Merge pull request #969 from AudriusButkevicius/dirfix
Remove existing file while handling dir (fixes #952)
This commit is contained in:
commit
ead09395d9
|
@ -367,32 +367,38 @@ func (p *Puller) handleDir(file protocol.FileInfo) {
|
||||||
l.Debugf("need dir\n\t%v\n\t%v", file, curFile)
|
l.Debugf("need dir\n\t%v\n\t%v", file, curFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info, err := os.Stat(realName); err != nil {
|
info, err := os.Stat(realName)
|
||||||
if os.IsNotExist(err) {
|
switch {
|
||||||
// The directory doesn't exist, so we create it with the right
|
// There is already something under that name, but it's a file.
|
||||||
// mode bits from the start.
|
// Most likely a file is getting replaced with a directory.
|
||||||
|
// Remove the file and fall through to directory creation.
|
||||||
mkdir := func(path string) error {
|
case err == nil && !info.IsDir():
|
||||||
// We declare a function that acts on only the path name, so
|
err = osutil.InWritableDir(os.Remove, realName)
|
||||||
// we can pass it to InWritableDir. We use a regular Mkdir and
|
if err != nil {
|
||||||
// not MkdirAll because the parent should already exist.
|
l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err)
|
||||||
return os.Mkdir(path, mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = osutil.InWritableDir(mkdir, realName); err == nil {
|
|
||||||
p.model.updateLocal(p.folder, file)
|
|
||||||
} else {
|
|
||||||
l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fallthrough
|
||||||
|
// The directory doesn't exist, so we create it with the right
|
||||||
|
// mode bits from the start.
|
||||||
|
case err != nil && os.IsNotExist(err):
|
||||||
|
// We declare a function that acts on only the path name, so
|
||||||
|
// we can pass it to InWritableDir. We use a regular Mkdir and
|
||||||
|
// not MkdirAll because the parent should already exist.
|
||||||
|
mkdir := func(path string) error {
|
||||||
|
return os.Mkdir(path, mode)
|
||||||
|
}
|
||||||
|
|
||||||
// Weird error when stat()'ing the dir. Probably won't work to do
|
if err = osutil.InWritableDir(mkdir, realName); err == nil {
|
||||||
// anything else with it if we can't even stat() it.
|
p.model.updateLocal(p.folder, file)
|
||||||
l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err)
|
} else {
|
||||||
|
l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else if !info.IsDir() {
|
// Weird error when stat()'ing the dir. Probably won't work to do
|
||||||
l.Infof("Puller (folder %q, dir %q): should be dir, but is not", p.folder, file.Name)
|
// anything else with it if we can't even stat() it.
|
||||||
|
case err != nil:
|
||||||
|
l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue