Remove replaceContents, user can use String.write
This commit is contained in:
@@ -155,33 +155,4 @@ public extension Path {
|
|||||||
}
|
}
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Replaces the contents of the file at this path with the provided string.
|
|
||||||
- Note: If file doesn’t exist, creates file
|
|
||||||
- Note: If file is not writable, makes writable first, resetting permissions after the write
|
|
||||||
- Parameter contents: The string that will become the contents of this file.
|
|
||||||
- Parameter atomically: If `true` the operation will be performed atomically.
|
|
||||||
- Parameter encoding: The string encoding to use.
|
|
||||||
- Returns: `self` to allow chaining.
|
|
||||||
*/
|
|
||||||
@discardableResult
|
|
||||||
public func replaceContents(with contents: String, atomically: Bool = false, encoding: String.Encoding = .utf8) throws -> Path {
|
|
||||||
let resetPerms: Int?
|
|
||||||
if exists, !isWritable {
|
|
||||||
resetPerms = try FileManager.default.attributesOfItem(atPath: string)[.posixPermissions] as? Int
|
|
||||||
let perms = resetPerms ?? 0o777
|
|
||||||
try chmod(perms | 0o200)
|
|
||||||
} else {
|
|
||||||
resetPerms = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
defer {
|
|
||||||
_ = try? resetPerms.map(self.chmod)
|
|
||||||
}
|
|
||||||
|
|
||||||
try contents.write(to: self)
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user