Perhaps better error stacks for backups/archives; ref #2418

This commit is contained in:
Dane Everitt 2020-11-08 14:07:26 -08:00
parent be9d1a3986
commit ef999a039c
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 13 additions and 19 deletions

View File

@ -41,7 +41,7 @@ func (a *Archiver) Exists() bool {
func (a *Archiver) Stat() (*filesystem.Stat, error) { func (a *Archiver) Stat() (*filesystem.Stat, error) {
s, err := os.Stat(a.Path()) s, err := os.Stat(a.Path())
if err != nil { if err != nil {
return nil, errors.WithStackIf(err) return nil, errors.WithStack(err)
} }
return &filesystem.Stat{ return &filesystem.Stat{
@ -58,7 +58,7 @@ func (a *Archiver) Archive() error {
var files []string var files []string
fileInfo, err := ioutil.ReadDir(path) fileInfo, err := ioutil.ReadDir(path)
if err != nil { if err != nil {
return err return errors.WithStack(err)
} }
for _, file := range fileInfo { for _, file := range fileInfo {
@ -72,7 +72,6 @@ func (a *Archiver) Archive() error {
// and not the actual file in this listing. // and not the actual file in this listing.
if file.Mode()&os.ModeSymlink != 0 { if file.Mode()&os.ModeSymlink != 0 {
f, err = a.Server.Filesystem().SafePath(filepath.Join(path, file.Name())) f, err = a.Server.Filesystem().SafePath(filepath.Join(path, file.Name()))
if err != nil { if err != nil {
return err return err
} }
@ -95,21 +94,17 @@ func (a *Archiver) DeleteIfExists() error {
return nil return nil
} }
return err
}
if err := os.Remove(a.Path()); err != nil {
return errors.WithStackIf(err) return errors.WithStackIf(err)
} }
return nil return errors.WrapIf(os.Remove(a.Path()), "archiver: failed to delete archive from system")
} }
// Checksum computes a SHA256 checksum of the server's archive. // Checksum computes a SHA256 checksum of the server's archive.
func (a *Archiver) Checksum() (string, error) { func (a *Archiver) Checksum() (string, error) {
file, err := os.Open(a.Path()) file, err := os.Open(a.Path())
if err != nil { if err != nil {
return "", err return "", errors.WithStack(err)
} }
defer file.Close() defer file.Close()
@ -117,7 +112,7 @@ func (a *Archiver) Checksum() (string, error) {
buf := make([]byte, 1024*4) buf := make([]byte, 1024*4)
if _, err := io.CopyBuffer(hash, file, buf); err != nil { if _, err := io.CopyBuffer(hash, file, buf); err != nil {
return "", err return "", errors.WithStack(err)
} }
return hex.EncodeToString(hash.Sum(nil)), nil return hex.EncodeToString(hash.Sum(nil)), nil

View File

@ -13,8 +13,7 @@ import (
// Notifies the panel of a backup's state and returns an error if one is encountered // Notifies the panel of a backup's state and returns an error if one is encountered
// while performing this action. // while performing this action.
func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, successful bool) error { func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, successful bool) error {
r := api.New() err := api.New().SendBackupStatus(uuid, ad.ToRequest(successful))
err := r.SendBackupStatus(uuid, ad.ToRequest(successful))
if err != nil { if err != nil {
if !api.IsRequestError(err) { if !api.IsRequestError(err) {
s.Log().WithFields(log.Fields{ s.Log().WithFields(log.Fields{
@ -22,7 +21,7 @@ func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, suc
"error": err, "error": err,
}).Error("failed to notify panel of backup status due to wings error") }).Error("failed to notify panel of backup status due to wings error")
return err return errors.WithStackIf(err)
} }
return errors.New(err.Error()) return errors.New(err.Error())
@ -38,7 +37,7 @@ func (s *Server) getServerwideIgnoredFiles() ([]string, error) {
f, err := os.Open(path.Join(s.Filesystem().Path(), ".pteroignore")) f, err := os.Open(path.Join(s.Filesystem().Path(), ".pteroignore"))
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return nil, err return nil, errors.WithStack(err)
} }
} else { } else {
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
@ -50,7 +49,7 @@ func (s *Server) getServerwideIgnoredFiles() ([]string, error) {
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
return nil, err return nil, errors.WithStack(err)
} }
} }
@ -100,7 +99,7 @@ func (s *Server) Backup(b backup.BackupInterface) error {
"file_size": 0, "file_size": 0,
}) })
return errors.WrapIf(err, "error while generating server backup") return errors.WrapIf(err, "backup: error while generating server backup")
} }
// Try to notify the panel about the status of this backup. If for some reason this request // Try to notify the panel about the status of this backup. If for some reason this request
@ -108,7 +107,7 @@ func (s *Server) Backup(b backup.BackupInterface) error {
if notifyError := s.notifyPanelOfBackup(b.Identifier(), ad, true); notifyError != nil { if notifyError := s.notifyPanelOfBackup(b.Identifier(), ad, true); notifyError != nil {
b.Remove() b.Remove()
return notifyError return errors.WithStackIf(err)
} }
// Emit an event over the socket so we can update the backup in realtime on // Emit an event over the socket so we can update the backup in realtime on

View File

@ -27,7 +27,7 @@ func (fs *Filesystem) GetIncludedFiles(dir string, ignored []string) (*backup.In
i, err := ignore.CompileIgnoreLines(ignored...) i, err := ignore.CompileIgnoreLines(ignored...)
if err != nil { if err != nil {
return nil, err return nil, errors.WithStack(err)
} }
// Walk through all of the files and directories on a server. This callback only returns // Walk through all of the files and directories on a server. This callback only returns

View File

@ -138,5 +138,5 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) {
} }
// Block until all of the routines finish and have returned a value. // Block until all of the routines finish and have returned a value.
return cleaned, g.Wait() return cleaned, errors.WithStackIf(g.Wait())
} }