From 52494822aa89bf13eef996814c31bab76d2e92b7 Mon Sep 17 00:00:00 2001 From: Simon Evans Date: Mon, 15 Jul 2019 08:26:48 +0100 Subject: [PATCH] FileManager: Add missing replaceItemAt(_:withItemAt:backupItemName:options:) - This just wraps replaceItem(at:withItemAt:backupItemName:options:) --- Foundation/FileManager.swift | 20 ++++++++++---------- TestFoundation/TestFileManager.swift | 7 ++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Foundation/FileManager.swift b/Foundation/FileManager.swift index 2f2c93c2c0..1f495487c5 100644 --- a/Foundation/FileManager.swift +++ b/Foundation/FileManager.swift @@ -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:)") @@ -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())! } diff --git a/TestFoundation/TestFileManager.swift b/TestFoundation/TestFileManager.swift index 67cf478924..e19cc508fb 100644 --- a/TestFoundation/TestFileManager.swift +++ b/TestFoundation/TestFileManager.swift @@ -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