mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 07:12:27 +00:00
This commit is contained in:
parent
5495d0f8ab
commit
e3078cc531
@ -116,28 +116,35 @@ func inWritableDir(fn func(string) error, targetFs fs.Filesystem, path string, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
const permBits = fs.ModePerm | fs.ModeSetuid | fs.ModeSetgid | fs.ModeSticky
|
const permBits = fs.ModePerm | fs.ModeSetuid | fs.ModeSetgid | fs.ModeSticky
|
||||||
|
var parentErr error
|
||||||
if mode := info.Mode() & permBits; mode&0200 == 0 {
|
if mode := info.Mode() & permBits; mode&0200 == 0 {
|
||||||
// A non-writeable directory (for this user; we assume that's the
|
// A non-writeable directory (for this user; we assume that's the
|
||||||
// relevant part). Temporarily change the mode so we can delete the
|
// relevant part). Temporarily change the mode so we can delete the
|
||||||
// file or directory inside it.
|
// file or directory inside it.
|
||||||
if err := targetFs.Chmod(dir, mode|0700); err != nil {
|
parentErr = targetFs.Chmod(dir, mode|0700)
|
||||||
return err
|
if parentErr != nil {
|
||||||
}
|
l.Debugf("Failed to make parent directory writable: %v", parentErr)
|
||||||
// Chmod succeeded, we should change the permissions back on the way
|
} else {
|
||||||
// out. If we fail we log the error as we have irrevocably messed up
|
// Chmod succeeded, we should change the permissions back on the way
|
||||||
// at this point. :( (The operation we were called to wrap has
|
// out. If we fail we log the error as we have irrevocably messed up
|
||||||
// succeeded or failed on its own so returning an error to the
|
// at this point. :( (The operation we were called to wrap has
|
||||||
// caller is inappropriate.)
|
// succeeded or failed on its own so returning an error to the
|
||||||
defer func() {
|
// caller is inappropriate.)
|
||||||
if err := targetFs.Chmod(dir, mode); err != nil && !fs.IsNotExist(err) {
|
defer func() {
|
||||||
logFn := l.Warnln
|
if err := targetFs.Chmod(dir, mode); err != nil && !fs.IsNotExist(err) {
|
||||||
if ignorePerms {
|
logFn := l.Warnln
|
||||||
logFn = l.Debugln
|
if ignorePerms {
|
||||||
|
logFn = l.Debugln
|
||||||
|
}
|
||||||
|
logFn("Failed to restore directory permissions after gaining write access:", err)
|
||||||
}
|
}
|
||||||
logFn("Failed to restore directory permissions after gaining write access:", err)
|
}()
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fn(path)
|
err = fn(path)
|
||||||
|
if fs.IsPermission(err) && parentErr != nil {
|
||||||
|
err = fmt.Errorf("error after failing to make parent directory writable: %w", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user