Skip to content
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

FileManager: Add missing replaceItemAt(_:withItemAt:backupItemName:options:) #2416

Merged
merged 1 commit into from
Jul 16, 2019
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
20 changes: 10 additions & 10 deletions Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1045,10 +1045,20 @@ open class FileManager : NSObject {
open func replaceItem(at originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String?, options: ItemReplacementOptions = []) throws -> URL? {
NSUnimplemented()
}

@available(Windows, deprecated, message: "Not yet implemented")
public func replaceItemAt(_ originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String? = nil, options: ItemReplacementOptions = []) throws -> URL? {
NSUnimplemented()
}

#else
open func replaceItem(at originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String?, options: ItemReplacementOptions = []) throws -> URL? {
return try _replaceItem(at: originalItemURL, withItemAt: newItemURL, backupItemName: backupItemName, options: options)
}

public func replaceItemAt(_ originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String? = nil, options: ItemReplacementOptions = []) throws -> URL? {
return try _replaceItem(at: originalItemURL, withItemAt: newItemURL, backupItemName: backupItemName, options: options)
}
#endif

@available(*, unavailable, message: "Returning an object through an autoreleased pointer is not supported in swift-corelibs-foundation. Use replaceItem(at:withItemAt:backupItemName:options:) instead.", renamed: "replaceItem(at:withItemAt:backupItemName:options:)")
Expand All @@ -1064,17 +1074,7 @@ open class FileManager : NSObject {

return _appendSymlinkDestination(destination, toPath: path)
}


}

extension FileManager {
public func replaceItemAt(_ originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String? = nil, options: ItemReplacementOptions = []) throws -> NSURL? {
NSUnimplemented()
}
}

extension FileManager {
open var homeDirectoryForCurrentUser: URL {
return homeDirectory(forUser: NSUserName())!
}
Expand Down
7 changes: 6 additions & 1 deletion TestFoundation/TestFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1701,13 +1701,18 @@ VIDEOS=StopgapVideos
try runSingleTest(aIsDirectory: true, bIsDirectory: false, options: [.withoutDeletingBackupItem, .usingNewMetadataOnly])
}

print("Testing Darwin Foundation compatible replace", to: &stderr)
try testReplaceMethod { (a, b, backupItemName, options) -> URL? in
try fm.replaceItemAt(a, withItemAt: b, backupItemName: backupItemName, options: options)
}

#if !DARWIN_COMPATIBILITY_TESTS
print("note: Testing platform-specific replace implementation.", to: &stderr)
try testReplaceMethod { (a, b, backupItemName, options) -> URL? in
try fm.replaceItem(at: a, withItemAt: b, backupItemName: backupItemName, options: options)
}
#endif

#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
print("note: Testing cross-platform replace implementation.", to: &stderr)
try testReplaceMethod { (a, b, backupItemName, options) -> URL? in
Expand Down