Skip to content

Commit

Permalink
delete incomplete archive files, if any
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlermitage committed Sep 1, 2022
1 parent 7672874 commit 2ca856d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Compression is set to _Fast_ (`-mx3` 7zip parameter) and it should compress file

* run backup tasks in parallel (make it configurable?)
* don't stop on first error (make it configurable?)
* delete incomplete archive files, if any
* move Go files to a folder like `src/main` and update the build command (I'm very new to Go programming...😅)

## License
Expand Down
20 changes: 15 additions & 5 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Compress(folderToCompress string, excludes []string, targetFolder string, a
}
targetFolder += GetCurrentDate() + "/"

archiveName = targetFolder + archiveName + " " + GetCurrentDateTime() + ".7z"
var archivePath = targetFolder + archiveName + " " + GetCurrentDateTime() + ".7z"

if !dryRun {
if !FolderExists(targetFolder) {
Expand All @@ -68,12 +68,12 @@ func Compress(folderToCompress string, excludes []string, targetFolder string, a
log.Fatal(mkdirErr)
}
}
if FileExists(archiveName) {
_ = os.Remove(archiveName)
if FileExists(archivePath) {
_ = os.Remove(archivePath)
}
}

args = append(args, archiveName, folderToCompress,
args = append(args, archivePath, folderToCompress,
"-ssw", /* compress files open for writing */
"-mx3", /* set level of compression */
"-bd" /* disable progress indicator */)
Expand All @@ -93,7 +93,17 @@ func Compress(folderToCompress string, excludes []string, targetFolder string, a
if err != nil {
fmt.Println(err)
}
return string(out[:])

var compressionResult = string(out[:])

if !validate7zOutput(compressionResult) {
if FileExists(archivePath) {
_ = os.Remove(archivePath)
fmt.Println("Compression failed, deleted bad archive file " + archivePath)
}
}

return compressionResult
}

func RotateLogs(logsFolder string, dryRun bool) {
Expand Down

0 comments on commit 2ca856d

Please sign in to comment.