Skip to content

Changing NSFileManager API names to match Darwin version #317

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 2 commits into from
Apr 14, 2016
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ extension NSData {
if fd == -1 {
throw _NSErrorWithErrno(errno, reading: false, path: dirPath)
}
let pathResult = NSFileManager.defaultManager().stringWithFileSystemRepresentation(buf, length: Int(strlen(buf)))
let pathResult = NSFileManager.defaultManager().string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
return (fd, pathResult)
}

Expand Down Expand Up @@ -462,7 +462,7 @@ extension NSData {
} catch let err {
if let auxFilePath = auxFilePath {
do {
try NSFileManager.defaultManager().removeItemAtPath(auxFilePath)
try NSFileManager.defaultManager().removeItem(atPath: auxFilePath)
} catch _ {}
}
throw err
Expand All @@ -472,7 +472,7 @@ extension NSData {
if let auxFilePath = auxFilePath {
if rename(auxFilePath, path) != 0 {
do {
try NSFileManager.defaultManager().removeItemAtPath(auxFilePath)
try NSFileManager.defaultManager().removeItem(atPath: auxFilePath)
} catch _ {}
throw _NSErrorWithErrno(errno, reading: false, path: path)
}
Expand Down
140 changes: 70 additions & 70 deletions Foundation/NSFileManager.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Foundation/NSKeyedArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class NSKeyedArchiver : NSCoder {
if finishedEncoding {
try _NSCleanupTemporaryFile(auxFilePath, path)
} else {
try NSFileManager.defaultManager().removeItemAtPath(auxFilePath)
try NSFileManager.defaultManager().removeItem(atPath: auxFilePath)
}
} catch _ {
}
Expand Down
10 changes: 5 additions & 5 deletions Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ internal extension String {
}

let temp = _stringByRemovingPrefix(prefix)
if NSFileManager.defaultManager().fileExistsAtPath(temp) {
if NSFileManager.defaultManager().fileExists(atPath: temp) {
return temp
}

Expand Down Expand Up @@ -446,7 +446,7 @@ public extension NSString {
}

var isDirectory = false
let exists = NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: &isDirectory)
let exists = NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: &isDirectory)
return exists && isDirectory
}

Expand All @@ -455,7 +455,7 @@ public extension NSString {
internal func _getNamesAtURL(_ filePathURL: NSURL, prependWith: String, namePredicate: _FileNamePredicate, typePredicate: _FileNamePredicate) -> [String] {
var result: [String] = []

if let enumerator = NSFileManager.defaultManager().enumeratorAtURL(filePathURL, includingPropertiesForKeys: nil, options: .SkipsSubdirectoryDescendants, errorHandler: nil) {
if let enumerator = NSFileManager.defaultManager().enumerator(at: filePathURL, includingPropertiesForKeys: nil, options: .skipsSubdirectoryDescendants, errorHandler: nil) {
for item in enumerator.lazy.map({ $0 as! NSURL }) {
let itemName = item.lastPathComponent

Expand Down Expand Up @@ -635,14 +635,14 @@ internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, Strin
if fd == -1 {
throw _NSErrorWithErrno(errno, reading: false, path: filePath)
}
let pathResult = NSFileManager.defaultManager().stringWithFileSystemRepresentation(buf, length: Int(strlen(buf)))
let pathResult = NSFileManager.defaultManager().string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
return (fd, pathResult)
}

internal func _NSCleanupTemporaryFile(_ auxFilePath: String, _ filePath: String) throws {
if rename(auxFilePath, filePath) != 0 {
do {
try NSFileManager.defaultManager().removeItemAtPath(auxFilePath)
try NSFileManager.defaultManager().removeItem(atPath: auxFilePath)
} catch _ {
}
throw _NSErrorWithErrno(errno, reading: false, path: filePath)
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public class NSURL : NSObject, NSSecureCoding, NSCopying {
} else {
absolutePath = path
}
NSFileManager.defaultManager().fileExistsAtPath(absolutePath, isDirectory: &isDir)
NSFileManager.defaultManager().fileExists(atPath: absolutePath, isDirectory: &isDir)
}

self.init(fileURLWithPath: thePath, isDirectory: isDir, relativeToURL: baseURL)
Expand All @@ -153,7 +153,7 @@ public class NSURL : NSObject, NSSecureCoding, NSCopying {
if thePath.hasSuffix("/") {
isDir = true
} else {
NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: &isDir)
NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: &isDir)
}

self.init(fileURLWithPath: thePath, isDirectory: isDir, relativeToURL: nil)
Expand Down Expand Up @@ -482,7 +482,7 @@ extension NSURL {
if !pathComponent.hasSuffix("/") && fileURL {
if let urlWithoutDirectory = result, path = urlWithoutDirectory.path {
var isDir : Bool = false
if NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: &isDir) && isDir {
if NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: &isDir) && isDir {
result = self.URLByAppendingPathComponent(pathComponent, isDirectory: true)
}
}
Expand Down Expand Up @@ -561,7 +561,7 @@ extension NSURL {

// It might be a responsibility of NSURL(fileURLWithPath:). Check it.
var isExistingDirectory = false
NSFileManager.defaultManager().fileExistsAtPath(resolvedPath, isDirectory: &isExistingDirectory)
NSFileManager.defaultManager().fileExists(atPath: resolvedPath, isDirectory: &isExistingDirectory)

if excludeSystemDirs {
resolvedPath = resolvedPath._tryToRemovePathPrefix("/private") ?? resolvedPath
Expand Down
14 changes: 7 additions & 7 deletions TestFoundation/TestNSBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TestNSBundle : XCTestCase {
let testPlist = bundle.URLForResource("Test", withExtension: "plist")
XCTAssertNotNil(testPlist)
XCTAssertEqual("Test.plist", testPlist!.lastPathComponent)
XCTAssert(NSFileManager.defaultManager().fileExistsAtPath(testPlist!.path!))
XCTAssert(NSFileManager.defaultManager().fileExists(atPath: testPlist!.path!))

// aliases, paths
XCTAssertEqual(testPlist!.path, bundle.URLForResource("Test", withExtension: "plist", subdirectory: nil)!.path)
Expand Down Expand Up @@ -107,20 +107,20 @@ class TestNSBundle : XCTestCase {
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().UUIDString + "/"

do {
try NSFileManager.defaultManager().createDirectoryAtPath(tempDir, withIntermediateDirectories: false, attributes: nil)
try NSFileManager.defaultManager().createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)

// Make a flat bundle in the playground
let bundlePath = tempDir + _bundleName
try NSFileManager.defaultManager().createDirectoryAtPath(bundlePath, withIntermediateDirectories: false, attributes: nil)
try NSFileManager.defaultManager().createDirectory(atPath: bundlePath, withIntermediateDirectories: false, attributes: nil)

// Put some resources in the bundle
for n in _bundleResourceNames {
NSFileManager.defaultManager().createFileAtPath(bundlePath + "/" + n, contents: nil, attributes: nil)
NSFileManager.defaultManager().createFile(atPath: bundlePath + "/" + n, contents: nil, attributes: nil)
}
// Add a resource into a subdirectory
let subDirPath = bundlePath + "/" + _subDirectory
try NSFileManager.defaultManager().createDirectoryAtPath(subDirPath, withIntermediateDirectories: false, attributes: nil)
NSFileManager.defaultManager().createFileAtPath(subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
try NSFileManager.defaultManager().createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
NSFileManager.defaultManager().createFile(atPath: subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
} catch _ {
return nil
}
Expand All @@ -131,7 +131,7 @@ class TestNSBundle : XCTestCase {

private func _cleanupPlayground(_ location: String) {
do {
try NSFileManager.defaultManager().removeItemAtPath(location)
try NSFileManager.defaultManager().removeItem(atPath: location)
} catch _ {
// Oh well
}
Expand Down
4 changes: 2 additions & 2 deletions TestFoundation/TestNSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class TestNSData: XCTestCase {
do {
try saveData!.writeToFile(savePath, options: NSDataWritingOptions.DataWritingAtomic)
let fileManager = NSFileManager.defaultManager()
XCTAssertTrue(fileManager.fileExistsAtPath(savePath))
try! fileManager.removeItemAtPath(savePath)
XCTAssertTrue(fileManager.fileExists(atPath: savePath))
try! fileManager.removeItem(atPath: savePath)
} catch _ {
XCTFail()
}
Expand Down
Loading