mirror of
https://github.com/rclone/rclone.git
synced 2025-01-11 00:40:03 +01:00
ncdu/scan: remove option for memory representation
Remove files/directories from the in memory structs of the cloud directory. Size and Count will be recalculated and populated upwards to the parent directories.
This commit is contained in:
parent
948a5d25c2
commit
9486df0226
@ -70,6 +70,45 @@ func (d *Dir) Entries() fs.DirEntries {
|
|||||||
return append(fs.DirEntries(nil), d.entries...)
|
return append(fs.DirEntries(nil), d.entries...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove removes the i-th entry from the
|
||||||
|
// in-memory representation of the remote directory
|
||||||
|
func (d *Dir) Remove(i int) {
|
||||||
|
d.mu.Lock()
|
||||||
|
defer d.mu.Unlock()
|
||||||
|
d.remove(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// removes the i-th entry from the
|
||||||
|
// in-memory representation of the remote directory
|
||||||
|
//
|
||||||
|
// Call with d.mu held
|
||||||
|
func (d *Dir) remove(i int) {
|
||||||
|
size := d.entries[i].Size()
|
||||||
|
count := int64(1)
|
||||||
|
|
||||||
|
subDir, ok := d.getDir(i)
|
||||||
|
if ok {
|
||||||
|
size = subDir.size
|
||||||
|
count = subDir.count
|
||||||
|
delete(d.dirs, path.Base(subDir.path))
|
||||||
|
}
|
||||||
|
|
||||||
|
d.size -= size
|
||||||
|
d.count -= count
|
||||||
|
d.entries = append(d.entries[:i], d.entries[i+1:]...)
|
||||||
|
|
||||||
|
dir := d
|
||||||
|
// populate changed size and count to parent(s)
|
||||||
|
for parent := d.parent; parent != nil; parent = parent.parent {
|
||||||
|
parent.mu.Lock()
|
||||||
|
parent.dirs[path.Base(dir.path)] = dir
|
||||||
|
parent.size -= size
|
||||||
|
parent.count -= count
|
||||||
|
dir = parent
|
||||||
|
parent.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// gets the directory of the i-th entry
|
// gets the directory of the i-th entry
|
||||||
//
|
//
|
||||||
// returns nil if it is a file
|
// returns nil if it is a file
|
||||||
|
Loading…
Reference in New Issue
Block a user