@@ -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,32 +884,43 @@ 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
-
893
+
894
+ #if os(Windows)
895
+ result [ . posixPermissions] = NSNumber ( value: UInt64 ( s. st_mode & ~ UInt16( ucrt. S_IFMT) ) )
896
+ #else
900
897
result [ . posixPermissions] = NSNumber ( value: UInt64 ( s. st_mode & ~ S_IFMT) )
898
+ #endif
901
899
result [ . referenceCount] = NSNumber ( value: UInt64 ( s. st_nlink) )
902
900
result [ . systemNumber] = NSNumber ( value: UInt64 ( s. st_dev) )
903
901
result [ . systemFileNumber] = NSNumber ( value: UInt64 ( s. st_ino) )
904
-
902
+
903
+ #if os(Windows)
904
+ result [ . type] = s. st_mode
905
+ result [ . deviceIdentifier] = NSNumber ( value: UInt64 ( s. st_rdev) )
906
+ #else
905
907
if let pwd = getpwuid ( s. st_uid) , pwd. pointee. pw_name != nil {
906
908
let name = String ( cString: pwd. pointee. pw_name)
907
909
result [ . ownerAccountName] = name
908
910
}
909
-
911
+
910
912
if let grd = getgrgid ( s. st_gid) , grd. pointee. gr_name != nil {
911
913
let name = String ( cString: grd. pointee. gr_name)
912
914
result [ . groupOwnerAccountName] = name
913
915
}
914
916
915
917
let type = FileAttributeType ( statMode: s. st_mode)
916
918
result [ . type] = type
917
-
919
+
918
920
if type == . typeBlockSpecial || type == . typeCharacterSpecial {
919
921
result [ . deviceIdentifier] = NSNumber ( value: UInt64 ( s. st_rdev) )
920
922
}
923
+ #endif
921
924
922
925
#if os(macOS) || os(iOS)
923
926
if ( s. st_flags & UInt32 ( UF_IMMUTABLE | SF_IMMUTABLE) ) != 0 {
@@ -929,11 +932,10 @@ open class FileManager : NSObject {
929
932
#endif
930
933
result [ . ownerAccountID] = NSNumber ( value: UInt64 ( s. st_uid) )
931
934
result [ . groupOwnerAccountID] = NSNumber ( value: UInt64 ( s. st_gid) )
932
- #endif
933
935
934
936
return result
935
937
}
936
-
938
+
937
939
/* 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
940
939
941
This method replaces fileSystemAttributesAtPath:.
0 commit comments