mirror of
https://github.com/softinio/Fishee.git
synced 2025-09-05 11:56:41 -07:00
complete backup functionality
This commit is contained in:
parent
9dd3399d5c
commit
02f14b70bf
3 changed files with 17 additions and 10 deletions
|
@ -35,25 +35,25 @@ func backupHistory(_ path: String) -> Bool {
|
|||
let newFileURL = directory.appendingPathComponent(newFileName).appendingPathExtension(fileExtension)
|
||||
|
||||
do {
|
||||
try? fileManager.removeItem(at: newFileURL)
|
||||
try fileManager.copyItem(at: fileURL, to: newFileURL)
|
||||
print("File duplicated successfully to: \(newFileURL.path)")
|
||||
return true
|
||||
} catch {
|
||||
print("error making a backup of \(path), got error: \(error)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func writeFishHistory(to path: String, history: [FishHistoryEntry], historyFileLocation: String?, backup: Bool = true) -> Bool {
|
||||
func writeFishHistory(to path: String, history: [FishHistoryEntry], backup: Bool = true) -> Bool {
|
||||
var output = ""
|
||||
|
||||
if backup {
|
||||
if let backupFile = historyFileLocation {
|
||||
let result = backupHistory(backupFile)
|
||||
if !result {
|
||||
print("Failed to backup \(backupFile) so aborting!")
|
||||
return false
|
||||
}
|
||||
let result = backupHistory(path)
|
||||
if !result {
|
||||
print("Failed to backup \(path) so aborting!")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue