More archiver code cleanup; ref pterodactyl/panel#2438
This commit is contained in:
parent
d9109cbf5a
commit
e02c197585
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user