From eca2e3c82b65276fdca47905ec32516f0ddb57d5 Mon Sep 17 00:00:00 2001 From: Max Chuquimia Date: Sun, 1 Dec 2019 18:31:57 +1100 Subject: [PATCH] Ensure edited file's attributes remain intact --- Sources/BeakCLI/Commands/EditCommand.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/BeakCLI/Commands/EditCommand.swift b/Sources/BeakCLI/Commands/EditCommand.swift index 5b35d8a..f45ddbb 100644 --- a/Sources/BeakCLI/Commands/EditCommand.swift +++ b/Sources/BeakCLI/Commands/EditCommand.swift @@ -1,6 +1,7 @@ import PathKit import SwiftCLI import BeakCore +import Foundation class EditCommand: BeakCommand { @@ -39,8 +40,9 @@ class EditCommand: BeakCommand { let line = readLine() if line?.lowercased() == "c" { + let attributes = try FileManager.default.attributesOfItem(atPath: path.string) try path.delete() - try packageManager.mainFilePath.copy(path) + try FileManager.default.createFile(atPath: path.string, contents: packageManager.mainFilePath.read(), attributes: attributes) stdout <<< "Copied edited file back to \(path.string)" } else { stdout <<< "Changes not copied back to \(path.string)"