From 48d608bd30fdd8a1108c6ebffa4dd3376d1c8f40 Mon Sep 17 00:00:00 2001 From: Claes Nordmark Date: Mon, 19 Nov 2018 11:14:40 +0100 Subject: [PATCH] Fetch group and owner name only when not present in cache. Improves performance on systems which has high time penalty when fetching owner and group name. --- .../plexus/components/io/attributes/FileAttributes.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index 8cf28f55..d052d200 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -64,7 +64,7 @@ public FileAttributes( @Nonnull File file, @Nonnull Map userCac Path path = file.toPath(); if ( AttributeUtils.isUnix( path ) ) { - Map attrs = Files.readAttributes( path, "unix:*", LinkOption.NOFOLLOW_LINKS ); + Map attrs = Files.readAttributes( path, "unix:permissions,gid,uid,isSymbolicLink,mode", LinkOption.NOFOLLOW_LINKS ); this.permissions = (Set) attrs.get( "permissions" ); groupId = (Integer) attrs.get( "gid" ); @@ -76,7 +76,8 @@ public FileAttributes( @Nonnull File file, @Nonnull Map userCac } else { - this.groupName = ( (Principal) attrs.get( "group" ) ).getName(); + Object group = Files.getAttribute( path, "unix:group", LinkOption.NOFOLLOW_LINKS ); + this.groupName = ( (Principal) group ).getName(); groupCache.put( groupId, this.groupName ); } userId = (Integer) attrs.get( "uid" ); @@ -87,7 +88,8 @@ public FileAttributes( @Nonnull File file, @Nonnull Map userCac } else { - this.userName = ( (Principal) attrs.get( "owner" ) ).getName(); + Object owner = Files.getAttribute( path, "unix:owner", LinkOption.NOFOLLOW_LINKS ); + this.userName = ( (Principal) owner ).getName(); userCache.put( userId, this.userName ); } octalMode = (Integer) attrs.get( "mode" ) & 0xfff; // Mask off top bits for compatibilty. Maybe check if we