diff --git a/server/archiver.go b/server/archiver.go index d321c421..35e6f052 100644 --- a/server/archiver.go +++ b/server/archiver.go @@ -81,33 +81,25 @@ func (a *Archiver) Archive() error { files = append(files, f) } - stat, err := a.Stat() - if err != nil && !os.IsNotExist(err) { + if err := a.DeleteIfExists(); err != nil { return err } - // Check if the file exists. - if stat != nil { - if err := os.Remove(a.Path()); err != nil { - return err - } - } - return archiver.NewTarGz().Archive(files, a.Path()) } // DeleteIfExists deletes the archive if it exists. func (a *Archiver) DeleteIfExists() error { - stat, err := a.Stat() - if err != nil && !errors.Is(err, os.ErrNotExist) { + if _, err := a.Stat(); err != nil { + if errors.Is(err, os.ErrNotExist) { + return nil + } + return err } - // Check if the file exists. - if stat != nil { - if err := os.Remove(a.Path()); err != nil { - return err - } + if err := os.Remove(a.Path()); err != nil { + return errors.WithStack(err) } return nil