Skip to content

Commit 65fb61b

Browse files
Classeplamentotev
authored andcommitted
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. Closes #16, Closes #17
1 parent b473eb0 commit 65fb61b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCac
6464
Path path = file.toPath();
6565
if ( AttributeUtils.isUnix( path ) )
6666
{
67-
Map<String, Object> attrs = Files.readAttributes( path, "unix:*", LinkOption.NOFOLLOW_LINKS );
67+
Map<String, Object> attrs = Files.readAttributes( path, "unix:permissions,gid,uid,isSymbolicLink,mode", LinkOption.NOFOLLOW_LINKS );
6868
this.permissions = (Set<PosixFilePermission>) attrs.get( "permissions" );
6969

7070
groupId = (Integer) attrs.get( "gid" );
@@ -76,7 +76,8 @@ public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCac
7676
}
7777
else
7878
{
79-
this.groupName = ( (Principal) attrs.get( "group" ) ).getName();
79+
Object group = Files.getAttribute( path, "unix:group", LinkOption.NOFOLLOW_LINKS );
80+
this.groupName = ( (Principal) group ).getName();
8081
groupCache.put( groupId, this.groupName );
8182
}
8283
userId = (Integer) attrs.get( "uid" );
@@ -87,7 +88,8 @@ public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCac
8788
}
8889
else
8990
{
90-
this.userName = ( (Principal) attrs.get( "owner" ) ).getName();
91+
Object owner = Files.getAttribute( path, "unix:owner", LinkOption.NOFOLLOW_LINKS );
92+
this.userName = ( (Principal) owner ).getName();
9193
userCache.put( userId, this.userName );
9294
}
9395
octalMode = (Integer) attrs.get( "mode" ) & 0xfff; // Mask off top bits for compatibilty. Maybe check if we

0 commit comments

Comments
 (0)