Skip to content

Commit c8c2a7b

Browse files
committed
FileManager contentsEqual(atPath:andPath:) updates.
- For block devices, compare the major/minor to match character devices. - When comparing directory contents, compare the contents of each item in the directories.
1 parent 06add84 commit c8c2a7b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,11 @@ static inline int _direntNameLength(struct dirent *entry) {
409409
}
410410

411411
// major() and minor() might be implemented as macros or functions.
412-
static inline unsigned int _char_dev_major(dev_t rdev) {
412+
static inline unsigned int _dev_major(dev_t rdev) {
413413
return major(rdev);
414414
}
415415

416-
static inline unsigned int _char_dev_minor(dev_t rdev) {
416+
static inline unsigned int _dev_minor(dev_t rdev) {
417417
return minor(rdev);
418418
}
419419

Foundation/FileManager.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ open class FileManager : NSObject {
677677
}
678678

679679
private func _compareSymlinks(withFileSystemRepresentation file1Rep: UnsafePointer<Int8>, andFileSystemRepresentation file2Rep: UnsafePointer<Int8>, size: Int64) -> Bool {
680-
let bufSize = Int(size) + 1
680+
let bufSize = Int(size)
681681
let buffer1 = UnsafeMutablePointer<CChar>.allocate(capacity: Int(bufSize))
682682
let buffer2 = UnsafeMutablePointer<CChar>.allocate(capacity: Int(bufSize))
683683

@@ -714,6 +714,9 @@ open class FileManager : NSObject {
714714
if path1entries.remove(item) == nil {
715715
return false
716716
}
717+
if contentsEqual(atPath: NSString(string: path1).appendingPathComponent(item), andPath: NSString(string: path2).appendingPathComponent(item)) == false {
718+
return false
719+
}
717720
}
718721
return path1entries.isEmpty
719722
}
@@ -763,10 +766,10 @@ open class FileManager : NSObject {
763766
return false
764767
}
765768

766-
if file1Type == S_IFCHR {
769+
if file1Type == S_IFCHR || file1Type == S_IFBLK {
767770
// For character devices, just check the major/minor pair is the same.
768-
return _char_dev_major(file1.st_rdev) == _char_dev_major(file2.st_rdev)
769-
&& _char_dev_minor(file1.st_rdev) == _char_dev_minor(file2.st_rdev)
771+
return _dev_major(file1.st_rdev) == _dev_major(file2.st_rdev)
772+
&& _dev_minor(file1.st_rdev) == _dev_minor(file2.st_rdev)
770773
}
771774

772775
// If both paths point to the same device/inode or they are both zero length

0 commit comments

Comments
 (0)