forked from TrueCloudLab/rclone
ncdu: fix crash when re-entering changed directory after rescan
ncdu stores the position that it was in for each directory. However doing a rescan can cause those positions to be out of range if the number of files decreased in a directory. When re-entering the directory, this causes an index out of range error. This fixes the problem by detecting the index out of range and flushing the saved directory position. See: https://forum.rclone.org/t/slice-bounds-out-of-range-during-ncdu/42492/
This commit is contained in:
parent
e1ad467009
commit
53868ef4e1
1 changed files with 6 additions and 0 deletions
|
@ -386,6 +386,12 @@ func (u *UI) Draw() {
|
||||||
}
|
}
|
||||||
showEmptyDir := u.hasEmptyDir()
|
showEmptyDir := u.hasEmptyDir()
|
||||||
dirPos := u.dirPosMap[u.path]
|
dirPos := u.dirPosMap[u.path]
|
||||||
|
// Check to see if a rescan has invalidated the position
|
||||||
|
if dirPos.offset >= len(u.sortPerm) {
|
||||||
|
delete(u.dirPosMap, u.path)
|
||||||
|
dirPos.offset = 0
|
||||||
|
dirPos.entry = 0
|
||||||
|
}
|
||||||
for i, j := range u.sortPerm[dirPos.offset:] {
|
for i, j := range u.sortPerm[dirPos.offset:] {
|
||||||
entry := u.entries[j]
|
entry := u.entries[j]
|
||||||
n := i + dirPos.offset
|
n := i + dirPos.offset
|
||||||
|
|
Loading…
Reference in a new issue