@@ -871,14 +871,6 @@ open class FileManager : NSObject {
871
871
open func attributesOfItem( atPath path: String ) throws -> [ FileAttributeKey : Any ] {
872
872
var result : [ FileAttributeKey : Any ] = [ : ]
873
873
874
- #if os(Windows)
875
- let faAttributes : WIN32_FILE_ATTRIBUTE_DATA = try windowsFileAttributes ( atPath: path)
876
-
877
- result [ . size] = NSNumber ( value: ( faAttributes. nFileSizeHigh << 32 ) | faAttributes. nFileSizeLow)
878
- result [ . modificationDate] = Date ( timeIntervalSinceReferenceDate: TimeInterval ( faAttributes. ftLastWriteTime) )
879
- // FIXME(compnerd) what about .posixPermissions, .referenceCount, .systemNumber, .systemFileNumber, .ownerAccountName, .groupOwnerAccountName, .type, .immuatable, .appendOnly, .ownerAccountID, .groupOwnerAccountID
880
- #else
881
-
882
874
#if os(Linux)
883
875
let ( s, creationDate) = try _statxFile ( atPath: path)
884
876
result [ . creationDate] = creationDate
@@ -892,29 +884,36 @@ open class FileManager : NSObject {
892
884
let ti = ( TimeInterval ( s. st_mtimespec. tv_sec) - kCFAbsoluteTimeIntervalSince1970) + ( 1.0e-9 * TimeInterval( s. st_mtimespec. tv_nsec) )
893
885
#elseif os(Android)
894
886
let ti = ( TimeInterval ( s. st_mtime) - kCFAbsoluteTimeIntervalSince1970) + ( 1.0e-9 * TimeInterval( s. st_mtime_nsec) )
887
+ #elseif os(Windows)
888
+ let ti = ( TimeInterval ( s. st_mtime) - kCFAbsoluteTimeIntervalSince1970)
895
889
#else
896
890
let ti = ( TimeInterval ( s. st_mtim. tv_sec) - kCFAbsoluteTimeIntervalSince1970) + ( 1.0e-9 * TimeInterval( s. st_mtim. tv_nsec) )
897
891
#endif
898
892
result [ . modificationDate] = Date ( timeIntervalSinceReferenceDate: ti)
899
-
900
- result [ . posixPermissions] = NSNumber ( value: UInt64 ( s. st_mode & ~ S_IFMT ) )
893
+
894
+ result [ . posixPermissions] = NSNumber ( value: _filePermissionsMask ( mode : UInt32 ( s. st_mode) ) )
901
895
result [ . referenceCount] = NSNumber ( value: UInt64 ( s. st_nlink) )
902
896
result [ . systemNumber] = NSNumber ( value: UInt64 ( s. st_dev) )
903
897
result [ . systemFileNumber] = NSNumber ( value: UInt64 ( s. st_ino) )
904
-
898
+
899
+ #if os(Windows)
900
+ result [ . deviceIdentifier] = NSNumber ( value: UInt64 ( s. st_rdev) )
901
+ let type = FileAttributeType ( attributes: try windowsFileAttributes ( atPath: path) )
902
+ #else
905
903
if let pwd = getpwuid ( s. st_uid) , pwd. pointee. pw_name != nil {
906
904
let name = String ( cString: pwd. pointee. pw_name)
907
905
result [ . ownerAccountName] = name
908
906
}
909
-
907
+
910
908
if let grd = getgrgid ( s. st_gid) , grd. pointee. gr_name != nil {
911
909
let name = String ( cString: grd. pointee. gr_name)
912
910
result [ . groupOwnerAccountName] = name
913
911
}
914
912
915
913
let type = FileAttributeType ( statMode: s. st_mode)
914
+ #endif
916
915
result [ . type] = type
917
-
916
+
918
917
if type == . typeBlockSpecial || type == . typeCharacterSpecial {
919
918
result [ . deviceIdentifier] = NSNumber ( value: UInt64 ( s. st_rdev) )
920
919
}
@@ -929,11 +928,10 @@ open class FileManager : NSObject {
929
928
#endif
930
929
result [ . ownerAccountID] = NSNumber ( value: UInt64 ( s. st_uid) )
931
930
result [ . groupOwnerAccountID] = NSNumber ( value: UInt64 ( s. st_gid) )
932
- #endif
933
931
934
932
return result
935
933
}
936
-
934
+
937
935
/* attributesOfFileSystemForPath:error: returns an NSDictionary of key/value pairs containing the attributes of the filesystem containing the provided path. If this method returns 'nil', an NSError will be returned by reference in the 'error' parameter. This method does not traverse a terminal symlink.
938
936
939
937
This method replaces fileSystemAttributesAtPath:.
@@ -1858,15 +1856,21 @@ open class FileManager : NSObject {
1858
1856
return statInfo
1859
1857
}
1860
1858
1861
- internal func _permissionsOfItem( atPath path: String ) throws -> Int {
1862
- let fileInfo = try _lstatFile ( atPath: path)
1859
+ internal func _filePermissionsMask( mode : UInt32 ) -> Int {
1863
1860
#if os(Windows)
1864
- return Int ( fileInfo. st_mode & ~ UInt16( ucrt. S_IFMT) )
1861
+ return Int ( mode & ~ UInt32( ucrt. S_IFMT) )
1862
+ #elseif canImport(Darwin)
1863
+ return Int ( mode & ~ UInt32( S_IFMT) )
1865
1864
#else
1866
- return Int ( fileInfo . st_mode & ~ S_IFMT)
1865
+ return Int ( mode & ~ S_IFMT)
1867
1866
#endif
1868
1867
}
1869
1868
1869
+ internal func _permissionsOfItem( atPath path: String ) throws -> Int {
1870
+ let fileInfo = try _lstatFile ( atPath: path)
1871
+ return _filePermissionsMask ( mode: UInt32 ( fileInfo. st_mode) )
1872
+ }
1873
+
1870
1874
1871
1875
#if os(Linux)
1872
1876
// statx() is only supported by Linux kernels >= 4.11.0
0 commit comments