Ignore symlink errors

This commit is contained in:
Dane Everitt 2020-12-27 16:30:00 -08:00
parent 7549eb13a0
commit 68749616ad
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -3,6 +3,7 @@ package filesystem
import ( import (
"archive/tar" "archive/tar"
"emperror.dev/errors" "emperror.dev/errors"
"github.com/apex/log"
"github.com/juju/ratelimit" "github.com/juju/ratelimit"
"github.com/karrick/godirwalk" "github.com/karrick/godirwalk"
"github.com/klauspost/pgzip" "github.com/klauspost/pgzip"
@ -149,21 +150,23 @@ func (a *Archive) addToArchive(p string, rp string, w *tar.Writer) error {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil return nil
} }
return errors.WrapIff(err, "failed to Lstat '"+rp+"'") return errors.WrapIff(err, "failed executing os.Lstat on '%s'", rp)
} }
// Resolve the symlink target if the file is a symlink. // Resolve the symlink target if the file is a symlink.
var target string var target string
if s.Mode()&os.ModeSymlink != 0 { if s.Mode()&os.ModeSymlink != 0 {
// Read the target of the symlink. // Read the target of the symlink. If there are any errors we will dump them out to
// the logs, but we're not going to stop the backup. There are far too many cases of
// symlinks causing all sorts of unnecessary pain in this process. Sucks to suck if
// it doesn't work.
target, err = os.Readlink(s.Name()) target, err = os.Readlink(s.Name())
if err != nil { if err != nil {
// Skip symlinks if the target does not exist. // Ignore the not exist errors specifically, since theres nothing important about that.
if os.IsNotExist(err) { if !os.IsNotExist(err) {
return nil log.WithField("path", rp).WithField("readlink_err", err.Error()).Warn("failed reading symlink for target path; skipping...")
} }
return nil
return errors.WrapIff(err, "failed to read symlink target for '%s'", rp)
} }
} }