Delete files and directories after pulling
This commit is contained in:
parent
e62b9c6009
commit
dedf835aa6
@ -281,6 +281,9 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int) int {
|
|||||||
// !!!
|
// !!!
|
||||||
|
|
||||||
changed := 0
|
changed := 0
|
||||||
|
|
||||||
|
var deletions []protocol.FileInfo
|
||||||
|
|
||||||
files.WithNeed(protocol.LocalDeviceID, func(intf protocol.FileIntf) bool {
|
files.WithNeed(protocol.LocalDeviceID, func(intf protocol.FileIntf) bool {
|
||||||
|
|
||||||
// Needed items are delivered sorted lexicographically. This isn't
|
// Needed items are delivered sorted lexicographically. This isn't
|
||||||
@ -302,15 +305,12 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case protocol.IsDirectory(file.Flags) && protocol.IsDeleted(file.Flags):
|
case protocol.IsDeleted(file.Flags):
|
||||||
// A deleted directory
|
// A deleted file or directory
|
||||||
p.deleteDir(file)
|
deletions = append(deletions, file)
|
||||||
case protocol.IsDirectory(file.Flags):
|
case protocol.IsDirectory(file.Flags):
|
||||||
// A new or changed directory
|
// A new or changed directory
|
||||||
p.handleDir(file)
|
p.handleDir(file)
|
||||||
case protocol.IsDeleted(file.Flags):
|
|
||||||
// A deleted file
|
|
||||||
p.deleteFile(file)
|
|
||||||
default:
|
default:
|
||||||
// A new or changed file. This is the only case where we do stuff
|
// A new or changed file. This is the only case where we do stuff
|
||||||
// in the background; the other three are done synchronously.
|
// in the background; the other three are done synchronously.
|
||||||
@ -334,6 +334,15 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int) int {
|
|||||||
// Wait for the finisherChan to finish.
|
// Wait for the finisherChan to finish.
|
||||||
doneWg.Wait()
|
doneWg.Wait()
|
||||||
|
|
||||||
|
for i := range deletions {
|
||||||
|
deletion := deletions[len(deletions)-i-1]
|
||||||
|
if deletion.IsDirectory() {
|
||||||
|
p.deleteDir(deletion)
|
||||||
|
} else {
|
||||||
|
p.deleteFile(deletion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user