Correctly handle file updates in read only directories (fixes #470)

This commit is contained in:
Jakob Borg
2014-08-07 08:31:22 +02:00
parent 5651847877
commit fdb11d7c06
2 changed files with 16 additions and 1 deletions

View File

@@ -436,9 +436,12 @@ func (p *puller) handleBlock(b bqBlock) bool {
of.temp = filepath.Join(p.repoCfg.Directory, defTempNamer.TempName(f.Name))
dirName := filepath.Dir(of.filepath)
_, err := os.Stat(dirName)
fi, err := os.Stat(dirName)
if err != nil {
err = os.MkdirAll(dirName, 0777)
} else {
// We need to make sure the directory is writeable so we can create files in it
err = os.Chmod(dirName, 0777)
}
if err != nil {
l.Infof("mkdir: error: %q / %q: %v", p.repoCfg.ID, f.Name, err)
@@ -597,7 +600,9 @@ func (p *puller) handleEmptyBlock(b bqBlock) {
l.Debugf("pull: delete %q", f.Name)
}
os.Remove(of.temp)
// Ensure the file and the directory it is in is writeable so we can remove the file
os.Chmod(of.filepath, 0666)
os.Chmod(filepath.Dir(of.filepath), 0777)
if p.versioner != nil {
if debug {
l.Debugln("pull: deleting with versioner")