Skip to content

Remove unnecessary casts within FileManager #1594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ open class FileManager : NSObject {

try _contentsOfDir(atPath: path, { (entryName, entryType) throws in
contents.append(entryName)
if entryType == Int32(DT_DIR) {
if entryType == DT_DIR {
let subPath: String = path + "/" + entryName
let entries = try subpathsOfDirectory(atPath: subPath)
contents.append(contentsOf: entries.map({file in "\(entryName)/\(file)"}))
Expand Down Expand Up @@ -434,7 +434,7 @@ open class FileManager : NSObject {
let bufSize = Int(PATH_MAX + 1)
var buf = [Int8](repeating: 0, count: bufSize)
let len = _fileSystemRepresentation(withPath: path) {
readlink($0, &buf, bufSize)
readlink($0, &buf, bufSize)
}
if len < 0 {
throw _NSErrorWithErrno(errno, reading: true, path: path)
Expand Down Expand Up @@ -503,6 +503,7 @@ open class FileManager : NSObject {
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(fileInfo.st_blksize))
defer { buffer.deallocate() }

// Casted to Int64 because fileInfo.st_size is 64 bits long even on 32 bit platforms
var bytesRemaining = Int64(fileInfo.st_size)
while bytesRemaining > 0 {
let bytesToRead = min(bytesRemaining, Int64(fileInfo.st_blksize))
Expand Down Expand Up @@ -696,8 +697,7 @@ open class FileManager : NSObject {
let length = Int(PATH_MAX) + 1
var buf = [Int8](repeating: 0, count: length)
getcwd(&buf, length)
let result = self.string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
return result
return string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
}

@discardableResult
Expand Down Expand Up @@ -798,8 +798,8 @@ open class FileManager : NSObject {

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

let size1 = readlink(file1Rep, buffer1, bufSize)
let size2 = readlink(file2Rep, buffer2, bufSize)
Expand Down