Skip to content

Commit 12f12c4

Browse files
committed
initial implementation
1 parent 77a8e7b commit 12f12c4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Foundation/FileManager.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ open class FileManager : NSObject {
434434
let bufSize = Int(PATH_MAX + 1)
435435
var buf = [Int8](repeating: 0, count: bufSize)
436436
let len = _fileSystemRepresentation(withPath: path) {
437-
readlink($0, &buf, bufSize)
437+
readlink($0, &buf, bufSize)
438438
}
439439
if len < 0 {
440440
throw _NSErrorWithErrno(errno, reading: true, path: path)
@@ -503,16 +503,16 @@ open class FileManager : NSObject {
503503
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(fileInfo.st_blksize))
504504
defer { buffer.deallocate() }
505505

506-
var bytesRemaining = Int64(fileInfo.st_size)
506+
var bytesRemaining = Int(fileInfo.st_size)
507507
while bytesRemaining > 0 {
508-
let bytesToRead = min(bytesRemaining, Int64(fileInfo.st_blksize))
509-
let bytesRead = try _readFrom(fd: srcfd, toBuffer: buffer, length: Int(bytesToRead), filename: srcPath)
508+
let bytesToRead = min(bytesRemaining, Int(fileInfo.st_blksize))
509+
let bytesRead = try _readFrom(fd: srcfd, toBuffer: buffer, length: bytesToRead, filename: srcPath)
510510
if bytesRead == 0 {
511511
// Early EOF
512512
return
513513
}
514514
try _writeTo(fd: dstfd, fromBuffer: buffer, length: bytesRead, filename: dstPath)
515-
bytesRemaining -= Int64(bytesRead)
515+
bytesRemaining -= bytesRead
516516
}
517517
}
518518

@@ -693,11 +693,10 @@ open class FileManager : NSObject {
693693
/* Process working directory management. Despite the fact that these are instance methods on FileManager, these methods report and change (respectively) the working directory for the entire process. Developers are cautioned that doing so is fraught with peril.
694694
*/
695695
open var currentDirectoryPath: String {
696-
let length = Int(PATH_MAX) + 1
697-
var buf = [Int8](repeating: 0, count: length)
698-
getcwd(&buf, length)
699-
let result = self.string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
700-
return result
696+
let len = Int(PATH_MAX) + 1
697+
var buf = [Int8](repeating: 0, count: len)
698+
getcwd(&buf, len)
699+
return string(withFileSystemRepresentation: buf, length: len)
701700
}
702701

703702
@discardableResult
@@ -779,9 +778,9 @@ open class FileManager : NSObject {
779778
buffer2.deallocate()
780779
}
781780

782-
var bytesLeft = size
781+
var bytesLeft = Int(size)
783782
while bytesLeft > 0 {
784-
let bytesToRead = Int(min(Int64(bufSize), bytesLeft))
783+
let bytesToRead = min(bufSize, bytesLeft)
785784
guard read(fd1, buffer1, bytesToRead) == bytesToRead else {
786785
return false
787786
}
@@ -791,15 +790,15 @@ open class FileManager : NSObject {
791790
guard memcmp(buffer1, buffer2, bytesToRead) == 0 else {
792791
return false
793792
}
794-
bytesLeft -= Int64(bytesToRead)
793+
bytesLeft -= bytesToRead
795794
}
796795
return true
797796
}
798797

799798
private func _compareSymlinks(withFileSystemRepresentation file1Rep: UnsafePointer<Int8>, andFileSystemRepresentation file2Rep: UnsafePointer<Int8>, size: Int64) -> Bool {
800799
let bufSize = Int(size)
801-
let buffer1 = UnsafeMutablePointer<CChar>.allocate(capacity: Int(bufSize))
802-
let buffer2 = UnsafeMutablePointer<CChar>.allocate(capacity: Int(bufSize))
800+
let buffer1 = UnsafeMutablePointer<CChar>.allocate(capacity: bufSize)
801+
let buffer2 = UnsafeMutablePointer<CChar>.allocate(capacity: bufSize)
803802

804803
let size1 = readlink(file1Rep, buffer1, bufSize)
805804
let size2 = readlink(file2Rep, buffer2, bufSize)

0 commit comments

Comments
 (0)