Skip to content

Commit 636edbf

Browse files
authored
Merge pull request swiftlang#425 from swiftwasm/main
[pull] swiftwasm from main
2 parents cdd09d3 + 483f3ff commit 636edbf

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Sources/Foundation/FileManager+Win32.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ extension FileManager {
740740
}
741741

742742
internal func _lstatFile(atPath path: String, withFileSystemRepresentation fsRep: UnsafePointer<NativeFSRCharType>? = nil) throws -> stat {
743+
let (stbuf, _) = try _statxFile(atPath: path, withFileSystemRepresentation: fsRep)
744+
return stbuf
745+
}
746+
747+
// FIXME(compnerd) the UInt64 should be UInt128 to uniquely identify the file across volumes
748+
internal func _statxFile(atPath path: String, withFileSystemRepresentation fsRep: UnsafePointer<NativeFSRCharType>? = nil) throws -> (stat, UInt64) {
743749
let _fsRep: UnsafePointer<NativeFSRCharType>
744750
if fsRep == nil {
745751
_fsRep = try __fileSystemRepresentation(withPath: path)
@@ -771,7 +777,8 @@ extension FileManager {
771777
statInfo.st_atime = info.ftLastAccessTime.time_t
772778
statInfo.st_ctime = info.ftCreationTime.time_t
773779
statInfo.st_dev = info.dwVolumeSerialNumber
774-
// inodes have meaning on FAT/HPFS/NTFS
780+
// The inode, and therefore st_ino, has no meaning in the FAT, HPFS, or
781+
// NTFS file systems. -- docs.microsoft.com
775782
statInfo.st_ino = 0
776783
statInfo.st_rdev = info.dwVolumeSerialNumber
777784

@@ -795,7 +802,8 @@ extension FileManager {
795802
statInfo.st_size = Int32(info.nFileSizeLow)
796803
// Uid is always 0 on Windows systems
797804
statInfo.st_uid = 0
798-
return statInfo
805+
806+
return (statInfo, UInt64(info.nFileIndexHigh << 32) | UInt64(info.nFileIndexLow))
799807
}
800808

801809
internal func _contentsEqual(atPath path1: String, andPath path2: String) -> Bool {

Sources/Foundation/FileManager.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ open class FileManager : NSObject {
539539
#if os(Linux)
540540
let (s, creationDate) = try _statxFile(atPath: path)
541541
result[.creationDate] = creationDate
542+
#elseif os(Windows)
543+
let (s, ino) = try _statxFile(atPath: path)
544+
result[.creationDate] = s.creationDate
542545
#else
543546
let s = try _lstatFile(atPath: path)
544547
result[.creationDate] = s.creationDate
@@ -554,7 +557,11 @@ open class FileManager : NSObject {
554557
result[.posixPermissions] = NSNumber(value: _filePermissionsMask(mode: UInt32(s.st_mode)))
555558
result[.referenceCount] = NSNumber(value: UInt64(s.st_nlink))
556559
result[.systemNumber] = NSNumber(value: UInt64(s.st_dev))
560+
#if os(Windows)
561+
result[.systemFileNumber] = NSNumber(value: UInt64(ino))
562+
#else
557563
result[.systemFileNumber] = NSNumber(value: UInt64(s.st_ino))
564+
#endif
558565

559566
#if os(Windows)
560567
result[.deviceIdentifier] = NSNumber(value: UInt64(s.st_rdev))

0 commit comments

Comments
 (0)