@@ -638,8 +638,7 @@ open class FileManager : NSObject {
638
638
NSUnimplemented ( )
639
639
}
640
640
641
- private func _compareFiles( withFileSystemRepresentation file1Rep: UnsafePointer < Int8 > , andFileSystemRepresentation file2Rep: UnsafePointer < Int8 > , size: Int64 ) -> Bool {
642
- let bufSize = min ( size, 1024 * 1024 )
641
+ private func _compareFiles( withFileSystemRepresentation file1Rep: UnsafePointer < Int8 > , andFileSystemRepresentation file2Rep: UnsafePointer < Int8 > , size: Int64 , bufSize: Int ) -> Bool {
643
642
let fd1 = open ( file1Rep, O_RDONLY)
644
643
guard fd1 >= 0 else {
645
644
return false
@@ -652,16 +651,16 @@ open class FileManager : NSObject {
652
651
}
653
652
defer { close ( fd2) }
654
653
655
- let buffer1 = UnsafeMutablePointer< UInt8> . allocate( capacity: Int ( bufSize) )
656
- let buffer2 = UnsafeMutablePointer< UInt8> . allocate( capacity: Int ( bufSize) )
654
+ let buffer1 = UnsafeMutablePointer< UInt8> . allocate( capacity: bufSize)
655
+ let buffer2 = UnsafeMutablePointer< UInt8> . allocate( capacity: bufSize)
657
656
defer {
658
657
buffer1. deallocate ( )
659
658
buffer2. deallocate ( )
660
659
}
661
660
662
661
var bytesLeft = size
663
662
while bytesLeft > 0 {
664
- let bytesToRead = Int ( min ( bufSize, bytesLeft) )
663
+ let bytesToRead = Int ( min ( Int64 ( bufSize) , bytesLeft) )
665
664
guard read ( fd1, buffer1, bytesToRead) == bytesToRead else {
666
665
return false
667
666
}
@@ -784,7 +783,7 @@ open class FileManager : NSObject {
784
783
guard file1. st_size == file2. st_size else {
785
784
return false
786
785
}
787
- return _compareFiles ( withFileSystemRepresentation: path1, andFileSystemRepresentation: path2, size: Int64 ( file1. st_size) )
786
+ return _compareFiles ( withFileSystemRepresentation: path1, andFileSystemRepresentation: path2, size: Int64 ( file1. st_size) , bufSize : Int ( file1 . st_blksize ) )
788
787
}
789
788
else if file1Type == S_IFLNK {
790
789
return _compareSymlinks ( withFileSystemRepresentation: fsRep1, andFileSystemRepresentation: fsRep2, size: Int64 ( file1. st_size) )
0 commit comments