Don't blow up if a file gets removed during the backup

This commit is contained in:
Dane Everitt 2020-08-27 19:57:35 -07:00
parent 0e474c8b24
commit 0dde54fc8f
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -90,13 +90,23 @@ func (a *Archive) Create(dst string, ctx context.Context) (os.FileInfo, error) {
func (a *Archive) addToArchive(p string, w *tar.Writer) error { func (a *Archive) addToArchive(p string, w *tar.Writer) error {
f, err := os.Open(p) f, err := os.Open(p)
if err != nil { if err != nil {
return err // If you try to backup something that no longer exists (got deleted somewhere during the process
// but not by this process), just skip over it and don't kill the entire backup.
if os.IsNotExist(err) {
return nil
}
return errors.WithStack(err) return errors.WithStack(err)
} }
defer f.Close() defer f.Close()
s, err := f.Stat() s, err := f.Stat()
if err != nil { if err != nil {
// Same as above, don't kill the process just because the file no longer exists.
if os.IsNotExist(err) {
return nil
}
return errors.WithStack(err) return errors.WithStack(err)
} }