16
16
* limitations under the License.
17
17
*/
18
18
19
- import javax .annotation .Nonnull ;
20
- import javax .annotation .Nullable ;
21
19
import java .io .File ;
22
20
import java .io .IOException ;
23
21
import java .nio .file .Files ;
24
- import java .nio .file .attribute . BasicFileAttributes ;
22
+ import java .nio .file .LinkOption ;
25
23
import java .nio .file .attribute .FileOwnerAttributeView ;
26
- import java .nio .file .attribute .PosixFileAttributes ;
27
24
import java .nio .file .attribute .PosixFilePermission ;
25
+ import java .security .Principal ;
28
26
import java .util .Collections ;
29
27
import java .util .HashMap ;
30
28
import java .util .Map ;
31
29
import java .util .Set ;
32
30
31
+ import javax .annotation .Nonnull ;
32
+ import javax .annotation .Nullable ;
33
+
33
34
/*
34
35
* File attributes for a java7 file that are backed on disk by a file.
35
36
* Immutable
@@ -59,12 +60,13 @@ public Java7FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> u
59
60
throws IOException
60
61
{
61
62
62
- BasicFileAttributes basicFileAttributes = Java7AttributeUtils .getFileAttributes ( file );
63
63
64
- if ( basicFileAttributes instanceof PosixFileAttributes )
64
+ if (Java7AttributeUtils . isUnix ( file . toPath ()) )
65
65
{
66
- this .permissions = ( (PosixFileAttributes ) basicFileAttributes ).permissions ();
67
- groupId = (Integer ) Files .readAttributes ( file .toPath (), "unix:gid" ).get ( "gid" );
66
+ Map <String , Object > attrs = Files .readAttributes (file .toPath (), "unix:*" , LinkOption .NOFOLLOW_LINKS );
67
+ this .permissions = (Set <PosixFilePermission >) attrs .get ("permissions" );
68
+
69
+ groupId = (Integer ) attrs .get ("gid" );
68
70
69
71
String groupName = groupCache .get ( groupId );
70
72
if ( groupName != null )
@@ -73,21 +75,22 @@ public Java7FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> u
73
75
}
74
76
else
75
77
{
76
- this .groupName = ( ( PosixFileAttributes ) basicFileAttributes ). group ( ).getName ();
78
+ this .groupName = (( Principal ) attrs . get ( "group" ) ).getName ();
77
79
groupCache .put ( groupId , this .groupName );
78
80
}
79
- userId = (Integer ) Files . readAttributes ( file . toPath (), "unix:uid" ). get ( "uid" );
81
+ userId = (Integer ) attrs . get ("uid" );
80
82
String userName = userCache .get ( userId );
81
83
if ( userName != null )
82
84
{
83
85
this .userName = userName ;
84
86
}
85
87
else
86
88
{
87
- this .userName = ( ( PosixFileAttributes ) basicFileAttributes ). owner ( ).getName ();
89
+ this .userName = (( Principal ) attrs . get ( "owner" ) ).getName ();
88
90
userCache .put ( userId , this .userName );
89
91
}
90
92
octalMode = calculatePosixOctalMode ();
93
+ symbolicLink = (Boolean ) attrs .get ("isSymbolicLink" );
91
94
} else {
92
95
FileOwnerAttributeView fa = Java7AttributeUtils .getFileOwnershipInfo ( file );
93
96
this .userName = fa .getOwner ().getName ();
@@ -96,9 +99,9 @@ public Java7FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> u
96
99
this .groupId = null ;
97
100
octalMode = -1 ;
98
101
permissions = Collections .emptySet ();
102
+ symbolicLink = Files .isSymbolicLink (file .toPath ());
99
103
}
100
104
101
- symbolicLink = Files .isSymbolicLink ( file .toPath () );
102
105
}
103
106
104
107
public static @ Nonnull PlexusIoResourceAttributes uncached ( @ Nonnull File file )
0 commit comments