@@ -853,24 +853,27 @@ extension FileManager {
853
853
}
854
854
}
855
855
856
- private func _compareSymlinks( withFileSystemRepresentation file1Rep: UnsafePointer < Int8 > , andFileSystemRepresentation file2Rep: UnsafePointer < Int8 > , size: Int64 ) -> Bool {
857
- let bufSize = Int ( size )
856
+ private func _compareSymlinks( withFileSystemRepresentation file1Rep: UnsafePointer < Int8 > , andFileSystemRepresentation file2Rep: UnsafePointer < Int8 > , size fileSize : Int64 ) -> Bool {
857
+ let bufSize = Int ( fileSize )
858
858
let buffer1 = UnsafeMutablePointer< CChar> . allocate( capacity: bufSize)
859
+ defer { buffer1. deallocate ( ) }
859
860
let buffer2 = UnsafeMutablePointer< CChar> . allocate( capacity: bufSize)
861
+ defer { buffer2. deallocate ( ) }
860
862
861
863
let size1 = readlink ( file1Rep, buffer1, bufSize)
864
+ guard size1 >= 0 else { return false }
865
+
862
866
let size2 = readlink ( file2Rep, buffer2, bufSize)
867
+ guard size2 >= 0 else { return false }
863
868
864
- let compare : Bool
865
- if size1 < 0 || size2 < 0 || size1 != size || size1 != size2 {
866
- compare = false
867
- } else {
868
- compare = memcmp ( buffer1, buffer2, size1) == 0
869
- }
869
+ #if !os(Android)
870
+ // In Android the reported size doesn't match the contents.
871
+ // Other platforms seems to follow that rule.
872
+ guard fileSize == size1 else { return false }
873
+ #endif
870
874
871
- buffer1. deallocate ( )
872
- buffer2. deallocate ( )
873
- return compare
875
+ guard size1 == size2 else { return false }
876
+ return memcmp ( buffer1, buffer2, size1) == 0
874
877
}
875
878
876
879
internal func _lstatFile( atPath path: String , withFileSystemRepresentation fsRep: UnsafePointer < Int8 > ? = nil ) throws -> stat {
@@ -938,7 +941,7 @@ extension FileManager {
938
941
939
942
/* -contentsEqualAtPath:andPath: does not take into account data stored in the resource fork or filesystem extended attributes.
940
943
*/
941
- internal func _contentsEqual( atPath path1: String , andPath path2: String ) -> Bool {
944
+ internal func _contentsEqual( atPath path1: String , andPath path2: String ) -> Bool {
942
945
do {
943
946
let fsRep1 = try __fileSystemRepresentation ( withPath: path1)
944
947
defer { fsRep1. deallocate ( ) }
0 commit comments