Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cmd/ncdu: add keybinding to rescan filesystem

eNV250bd0a992a444
diff --git a/cmd/ncdu/ncdu.go b/cmd/ncdu/ncdu.go
index 9cbc388a7..cd93e734d 100644
--- a/cmd/ncdu/ncdu.go
+++ b/cmd/ncdu/ncdu.go
@@ -112,6 +112,7 @@ func helpText() (tr []string) {
tr = append(tr, []string{
" Y display current path",
" ^L refresh screen (fix screen corruption)",
+ " r recalculate file sizes",
" ? to toggle help on and off",
" q/ESC/^c to quit",
}...)
@@ -122,6 +123,7 @@ func helpText() (tr []string) {
type UI struct {
s tcell.Screen
f fs.Fs // fs being displayed
+ cancel func() // cancel the current scanning process
fsName string // human name of Fs
root *scan.Dir // root directory
d *scan.Dir // current directory being displayed
@@ -900,6 +902,15 @@ func NewUI(f fs.Fs) *UI {
}
}
+func (u *UI) scan() (chan *scan.Dir, chan error, chan struct{}) {
+ if cancel := u.cancel; cancel != nil {
+ cancel()
+ }
+ ctx := context.Background()
+ ctx, u.cancel = context.WithCancel(ctx)
+ return scan.Scan(ctx, u.f)
+}
+
// Run shows the user interface
func (u *UI) Run() error {
var err error
@@ -936,8 +947,7 @@ func (u *UI) Run() error {
defer u.s.Fini()
// scan the disk in the background
- u.listing = true
- rootChan, errChan, updated := scan.Scan(context.Background(), u.f)
+ rootChan, errChan, updated := u.scan()
// Poll the events into a channel
events := make(chan tcell.Event)
@@ -1038,6 +1048,9 @@ outer:
u.deleteSelected()
case '?':
u.togglePopupBox(helpText())
+ case 'r':
+ // restart scan
+ rootChan, errChan, updated = u.scan()
// Refresh the screen. Not obvious what key to map
// this onto, but ^L is a common choice.