mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
Correctly handle file updates in read only directories (fixes #470)
This commit is contained in:
parent
5651847877
commit
fdb11d7c06
@ -91,6 +91,7 @@ alterFiles() {
|
|||||||
for i in 1 12-2 23-3 ; do
|
for i in 1 12-2 23-3 ; do
|
||||||
# Delete some files
|
# Delete some files
|
||||||
pushd "s$i" >/dev/null
|
pushd "s$i" >/dev/null
|
||||||
|
chmod 755 ro-test
|
||||||
nfiles=$(find . -type f | wc -l)
|
nfiles=$(find . -type f | wc -l)
|
||||||
if [[ $nfiles -ge 300 ]] ; then
|
if [[ $nfiles -ge 300 ]] ; then
|
||||||
todelete=$(( $nfiles - 300 ))
|
todelete=$(( $nfiles - 300 ))
|
||||||
@ -107,6 +108,10 @@ alterFiles() {
|
|||||||
../genfiles -maxexp 22 -files 200
|
../genfiles -maxexp 22 -files 200
|
||||||
echo " $i: append to large file"
|
echo " $i: append to large file"
|
||||||
dd if=large-$i bs=1024k count=4 >> large-$i 2>/dev/null
|
dd if=large-$i bs=1024k count=4 >> large-$i 2>/dev/null
|
||||||
|
echo " $i: new files in ro directory"
|
||||||
|
uuidgen > ro-test/$(uuidgen)
|
||||||
|
chmod 500 ro-test
|
||||||
|
|
||||||
../md5r -l | sort | grep -v .stversions > ../md5-$i
|
../md5r -l | sort | grep -v .stversions > ../md5-$i
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
done
|
done
|
||||||
@ -118,6 +123,7 @@ alterFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rm -rf h?/*.idx.gz h?/index
|
rm -rf h?/*.idx.gz h?/index
|
||||||
|
chmod -R u+w s? s??-?
|
||||||
rm -rf s? s??-?
|
rm -rf s? s??-?
|
||||||
mkdir s1 s2 s3 s12-1 s12-2 s23-2 s23-3
|
mkdir s1 s2 s3 s12-1 s12-2 s23-2 s23-3
|
||||||
|
|
||||||
@ -126,6 +132,10 @@ for i in 1 12-2 23-3; do
|
|||||||
pushd "s$i" >/dev/null
|
pushd "s$i" >/dev/null
|
||||||
echo " $i: random nonoverlapping"
|
echo " $i: random nonoverlapping"
|
||||||
../genfiles -maxexp 22 -files 400
|
../genfiles -maxexp 22 -files 400
|
||||||
|
echo " $i: ro directory"
|
||||||
|
mkdir ro-test
|
||||||
|
uuidgen > ro-test/$(uuidgen)
|
||||||
|
chmod 500 ro-test
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -436,9 +436,12 @@ func (p *puller) handleBlock(b bqBlock) bool {
|
|||||||
of.temp = filepath.Join(p.repoCfg.Directory, defTempNamer.TempName(f.Name))
|
of.temp = filepath.Join(p.repoCfg.Directory, defTempNamer.TempName(f.Name))
|
||||||
|
|
||||||
dirName := filepath.Dir(of.filepath)
|
dirName := filepath.Dir(of.filepath)
|
||||||
_, err := os.Stat(dirName)
|
fi, err := os.Stat(dirName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = os.MkdirAll(dirName, 0777)
|
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 {
|
if err != nil {
|
||||||
l.Infof("mkdir: error: %q / %q: %v", p.repoCfg.ID, f.Name, err)
|
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)
|
l.Debugf("pull: delete %q", f.Name)
|
||||||
}
|
}
|
||||||
os.Remove(of.temp)
|
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(of.filepath, 0666)
|
||||||
|
os.Chmod(filepath.Dir(of.filepath), 0777)
|
||||||
if p.versioner != nil {
|
if p.versioner != nil {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln("pull: deleting with versioner")
|
l.Debugln("pull: deleting with versioner")
|
||||||
|
Loading…
Reference in New Issue
Block a user