mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 18:41:59 -07:00
Exit and error if the target is not a directory
This commit is contained in:
parent
6057138466
commit
19884ade99
@ -69,7 +69,14 @@ func Copy(from, to string) (err error) {
|
|||||||
// containing `path` is writable for the duration of the call.
|
// containing `path` is writable for the duration of the call.
|
||||||
func InWritableDir(fn func(string) error, path string) error {
|
func InWritableDir(fn func(string) error, path string) error {
|
||||||
dir := filepath.Dir(path)
|
dir := filepath.Dir(path)
|
||||||
if info, err := os.Stat(dir); err == nil && info.IsDir() && info.Mode()&0200 == 0 {
|
info, err := os.Stat(dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
return errors.New("Not a directory: " + path)
|
||||||
|
}
|
||||||
|
if info.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.
|
||||||
|
Loading…
Reference in New Issue
Block a user