From 904c0acdf6dc61ba2e82681eb0aea6d3022069f0 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 --- CHANGELOG.md | 1 + Sources/BeakCLI/Commands/EditCommand.swift | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5fac34..de70fc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## Next Version +- Fixed edit command removing file attributes #46 @maxchuquimia ## 0.5.1 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)"