Skip to content

Commit

Permalink
More archiver code cleanup; ref pterodactyl/panel#2438
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Oct 4, 2020
1 parent d9109cb commit e02c197
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions server/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e02c197

Please sign in to comment.