Delete the server's archive when the server is deleted

This commit is contained in:
Matthew Penner
2020-04-04 18:31:18 -06:00
parent 8da9d45c9d
commit 0ca9c8a114
2 changed files with 23 additions and 0 deletions

View File

@@ -70,6 +70,23 @@ func (a *Archiver) Archive() error {
return archiver.NewTarGz().Archive(files, a.ArchivePath())
}
// DeleteIfExists deletes the archive if it exists.
func (a *Archiver) DeleteIfExists() error {
stat, err := a.Stat()
if err != nil && !os.IsNotExist(err) {
return err
}
// Check if the file exists.
if stat != nil {
if err := os.Remove(a.ArchivePath()); err != nil {
return err
}
}
return nil
}
// Checksum computes a SHA256 checksum of the server's archive.
func (a *Archiver) Checksum() (string, error) {
file, err := os.Open(a.ArchivePath())