Skip to content

Commit cf47315

Browse files
committed
Merge branch 'filemanager-default' of https://github.com/jpsim/swift-corelibs-foundation
2 parents 7c28dca + df452e8 commit cf47315

14 files changed

+60
-63
lines changed

Foundation/NSData.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ extension NSData {
408408
if fd == -1 {
409409
throw _NSErrorWithErrno(errno, reading: false, path: dirPath)
410410
}
411-
let pathResult = FileManager.default().string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
411+
let pathResult = FileManager.default.string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
412412
return (fd, pathResult)
413413
}
414414

@@ -472,7 +472,7 @@ extension NSData {
472472
} catch let err {
473473
if let auxFilePath = auxFilePath {
474474
do {
475-
try FileManager.default().removeItem(atPath: auxFilePath)
475+
try FileManager.default.removeItem(atPath: auxFilePath)
476476
} catch _ {}
477477
}
478478
throw err
@@ -482,7 +482,7 @@ extension NSData {
482482
if let auxFilePath = auxFilePath {
483483
if rename(auxFilePath, path) != 0 {
484484
do {
485-
try FileManager.default().removeItem(atPath: auxFilePath)
485+
try FileManager.default.removeItem(atPath: auxFilePath)
486486
} catch _ {}
487487
throw _NSErrorWithErrno(errno, reading: false, path: path)
488488
}

Foundation/NSFileManager.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ open class FileManager: NSObject {
7070

7171
/* Returns the default singleton instance.
7272
*/
73-
internal static let defaultInstance = FileManager()
74-
open class func `default`() -> FileManager {
75-
return defaultInstance
76-
}
73+
public static let `default` = FileManager()
7774

7875
/* Returns an NSArray of NSURLs locating the mounted volumes available on the computer. The property keys that can be requested are available in NSURL.
7976
*/
@@ -461,7 +458,7 @@ open class FileManager: NSObject {
461458
return
462459
} else if errno == ENOTEMPTY {
463460

464-
let fsRep = FileManager.default().fileSystemRepresentation(withPath: path)
461+
let fsRep = FileManager.default.fileSystemRepresentation(withPath: path)
465462
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 2)
466463
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
467464
ps.advanced(by: 1).initialize(to: nil)
@@ -733,7 +730,7 @@ open class FileManager: NSObject {
733730
return nil
734731
}
735732

736-
guard let destination = try? FileManager.default().destinationOfSymbolicLink(atPath: path) else {
733+
guard let destination = try? FileManager.default.destinationOfSymbolicLink(atPath: path) else {
737734
return nil
738735
}
739736

@@ -874,7 +871,7 @@ extension FileManager {
874871
init?(path: String) {
875872
let url = URL(fileURLWithPath: path)
876873
self.baseURL = url
877-
guard let ie = FileManager.default().enumerator(at: url, includingPropertiesForKeys: nil, options: [], errorHandler: nil) else {
874+
guard let ie = FileManager.default.enumerator(at: url, includingPropertiesForKeys: nil, options: [], errorHandler: nil) else {
878875
return nil
879876
}
880877
self.innerEnumerator = ie
@@ -906,8 +903,8 @@ extension FileManager {
906903
_errorHandler = errorHandler
907904

908905
if let path = _url.path {
909-
if FileManager.default().fileExists(atPath: path) {
910-
let fsRep = FileManager.default().fileSystemRepresentation(withPath: path)
906+
if FileManager.default.fileExists(atPath: path) {
907+
let fsRep = FileManager.default.fileSystemRepresentation(withPath: path)
911908
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 2)
912909
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
913910
ps.advanced(by: 1).initialize(to: nil)

Foundation/NSKeyedArchiver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ open class NSKeyedArchiver : NSCoder {
148148
if finishedEncoding {
149149
try _NSCleanupTemporaryFile(auxFilePath, path)
150150
} else {
151-
try FileManager.default().removeItem(atPath: auxFilePath)
151+
try FileManager.default.removeItem(atPath: auxFilePath)
152152
}
153153
} catch _ {
154154
}

Foundation/NSPathUtilities.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ internal extension String {
146146
}
147147

148148
let temp = _stringByRemovingPrefix(prefix)
149-
if FileManager.default().fileExists(atPath: temp) {
149+
if FileManager.default.fileExists(atPath: temp) {
150150
return temp
151151
}
152152

@@ -347,7 +347,7 @@ public extension NSString {
347347

348348
default:
349349
resolvedPath = resolvedPath.bridge().stringByAppendingPathComponent(component)
350-
if let destination = FileManager.default()._tryToResolveTrailingSymlinkInPath(resolvedPath) {
350+
if let destination = FileManager.default._tryToResolveTrailingSymlinkInPath(resolvedPath) {
351351
resolvedPath = destination
352352
}
353353
}
@@ -427,7 +427,7 @@ public extension NSString {
427427
}
428428

429429
var isDirectory = false
430-
let exists = FileManager.default().fileExists(atPath: path, isDirectory: &isDirectory)
430+
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
431431
return exists && isDirectory
432432
}
433433

@@ -436,7 +436,7 @@ public extension NSString {
436436
internal func _getNamesAtURL(_ filePathURL: URL, prependWith: String, namePredicate: _FileNamePredicate, typePredicate: _FileNamePredicate) -> [String] {
437437
var result: [String] = []
438438

439-
if let enumerator = FileManager.default().enumerator(at: filePathURL, includingPropertiesForKeys: nil, options: .skipsSubdirectoryDescendants, errorHandler: nil) {
439+
if let enumerator = FileManager.default.enumerator(at: filePathURL, includingPropertiesForKeys: nil, options: .skipsSubdirectoryDescendants, errorHandler: nil) {
440440
for item in enumerator.lazy.map({ $0 as! URL }) {
441441
let itemName = item.lastPathComponent
442442

@@ -618,14 +618,14 @@ internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, Strin
618618
if fd == -1 {
619619
throw _NSErrorWithErrno(errno, reading: false, path: filePath)
620620
}
621-
let pathResult = FileManager.default().string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
621+
let pathResult = FileManager.default.string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
622622
return (fd, pathResult)
623623
}
624624

625625
internal func _NSCleanupTemporaryFile(_ auxFilePath: String, _ filePath: String) throws {
626626
if rename(auxFilePath, filePath) != 0 {
627627
do {
628-
try FileManager.default().removeItem(atPath: auxFilePath)
628+
try FileManager.default.removeItem(atPath: auxFilePath)
629629
} catch _ {
630630
}
631631
throw _NSErrorWithErrno(errno, reading: false, path: filePath)

Foundation/NSTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ open class Task: NSObject {
152152
open var arguments: [String]?
153153
open var environment: [String : String]? // if not set, use current
154154

155-
open var currentDirectoryPath: String = FileManager.defaultInstance.currentDirectoryPath
155+
open var currentDirectoryPath: String = FileManager.default.currentDirectoryPath
156156

157157
// standard I/O channels; could be either an NSFileHandle or an NSPipe
158158
open var standardInput: AnyObject? {

Foundation/NSURL.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ open class NSURL: NSObject, NSSecureCoding, NSCopying {
267267
} else {
268268
absolutePath = path
269269
}
270-
let _ = FileManager.default().fileExists(atPath: absolutePath, isDirectory: &isDir)
270+
let _ = FileManager.default.fileExists(atPath: absolutePath, isDirectory: &isDir)
271271
} catch {
272272
// ignored
273273
}
@@ -287,7 +287,7 @@ open class NSURL: NSObject, NSSecureCoding, NSCopying {
287287
if thePath.hasSuffix("/") {
288288
isDir = true
289289
} else {
290-
let _ = FileManager.default().fileExists(atPath: path, isDirectory: &isDir)
290+
let _ = FileManager.default.fileExists(atPath: path, isDirectory: &isDir)
291291
}
292292

293293
self.init(fileURLWithPath: thePath, isDirectory: isDir, relativeTo: nil)
@@ -697,7 +697,7 @@ extension NSURL {
697697
if let urlWithoutDirectory = result,
698698
let path = urlWithoutDirectory.path {
699699
var isDir : Bool = false
700-
if FileManager.default().fileExists(atPath: path, isDirectory: &isDir) && isDir {
700+
if FileManager.default.fileExists(atPath: path, isDirectory: &isDir) && isDir {
701701
result = self.appendingPathComponent(pathComponent, isDirectory: true)
702702
}
703703
}
@@ -747,7 +747,7 @@ extension NSURL {
747747
if selfPath.hasPrefix("/") {
748748
absolutePath = selfPath
749749
} else {
750-
let workingDir = FileManager.default().currentDirectoryPath
750+
let workingDir = FileManager.default.currentDirectoryPath
751751
absolutePath = workingDir.bridge().stringByAppendingPathComponent(selfPath)
752752
}
753753

@@ -769,15 +769,15 @@ extension NSURL {
769769

770770
default:
771771
resolvedPath = resolvedPath.bridge().stringByAppendingPathComponent(component)
772-
if let destination = FileManager.default()._tryToResolveTrailingSymlinkInPath(resolvedPath) {
772+
if let destination = FileManager.default._tryToResolveTrailingSymlinkInPath(resolvedPath) {
773773
resolvedPath = destination
774774
}
775775
}
776776
}
777777

778778
// It might be a responsibility of NSURL(fileURLWithPath:). Check it.
779779
var isExistingDirectory = false
780-
let _ = FileManager.default().fileExists(atPath: resolvedPath, isDirectory: &isExistingDirectory)
780+
let _ = FileManager.default.fileExists(atPath: resolvedPath, isDirectory: &isExistingDirectory)
781781

782782
if excludeSystemDirs {
783783
resolvedPath = resolvedPath._tryToRemovePathPrefix("/private") ?? resolvedPath

TestFoundation/TestNSBundle.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TestNSBundle : XCTestCase {
6868
let testPlist = bundle.urlForResource("Test", withExtension: "plist")
6969
XCTAssertNotNil(testPlist)
7070
XCTAssertEqual("Test.plist", testPlist!.lastPathComponent)
71-
XCTAssert(FileManager.default().fileExists(atPath: testPlist!.path!))
71+
XCTAssert(FileManager.default.fileExists(atPath: testPlist!.path!))
7272

7373
// aliases, paths
7474
XCTAssertEqual(testPlist!.path, bundle.urlForResource("Test", withExtension: "plist", subdirectory: nil)!.path)
@@ -111,20 +111,20 @@ class TestNSBundle : XCTestCase {
111111
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().uuidString + "/"
112112

113113
do {
114-
try FileManager.default().createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
114+
try FileManager.default.createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
115115

116116
// Make a flat bundle in the playground
117117
let bundlePath = tempDir + _bundleName
118-
try FileManager.default().createDirectory(atPath: bundlePath, withIntermediateDirectories: false, attributes: nil)
118+
try FileManager.default.createDirectory(atPath: bundlePath, withIntermediateDirectories: false, attributes: nil)
119119

120120
// Put some resources in the bundle
121121
for n in _bundleResourceNames {
122-
let _ = FileManager.default().createFile(atPath: bundlePath + "/" + n, contents: nil, attributes: nil)
122+
let _ = FileManager.default.createFile(atPath: bundlePath + "/" + n, contents: nil, attributes: nil)
123123
}
124124
// Add a resource into a subdirectory
125125
let subDirPath = bundlePath + "/" + _subDirectory
126-
try FileManager.default().createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
127-
let _ = FileManager.default().createFile(atPath: subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
126+
try FileManager.default.createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
127+
let _ = FileManager.default.createFile(atPath: subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
128128
} catch _ {
129129
return nil
130130
}
@@ -135,7 +135,7 @@ class TestNSBundle : XCTestCase {
135135

136136
private func _cleanupPlayground(_ location: String) {
137137
do {
138-
try FileManager.default().removeItem(atPath: location)
138+
try FileManager.default.removeItem(atPath: location)
139139
} catch _ {
140140
// Oh well
141141
}

TestFoundation/TestNSData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TestNSData: XCTestCase {
4949
let savePath = URL(fileURLWithPath: "/var/tmp/Test.plist")
5050
do {
5151
try saveData.write(to: savePath, options: .dataWritingAtomic)
52-
let fileManager = FileManager.default()
52+
let fileManager = FileManager.default
5353
XCTAssertTrue(fileManager.fileExists(atPath: savePath.path!))
5454
try! fileManager.removeItem(atPath: savePath.path!)
5555
} catch _ {

0 commit comments

Comments
 (0)