Repository: gokcehan/lf (language: go)

Issue:
dircounts is not refreshed with load command
Directory's `dircounts` is not changing, when the number of sub files/directories has been changed. Using the `load` command doesn't work, so setting `period` option to non-zero is also not working. However, I was able to use `reload` command to update the sub files/directories count.

I have disabled the `dircache` option (#627 #673). But disabling the dircache (along with `set period 1`) only updates the changes in the sub files/directories list, not the sub files/directories count. Because of which, the `dircounts` becomes inconsistent.

So, is this a bug? or maybe I am missing something?


Discussion / hints:
@srimadhan11 What do you mean when you say the count becomes inconsistent? Can you provide a steps to reproduce here?
@gokcehan Sorry for not including the steps to reproduce the bug in my previous comment. I have explained them below.

Initial directory structure,
```
DirA/
    DirB
    DirC
    FileD
```

Steps:
 1. navigate to `DirA` in lf
 2. execute the shell command, `touch DirA/FileE` to create new file inside `DirA`
 3. dircounts for DirA will still remains to be `3`, whereas its children's list gets updated and shows the new file `FileE`

---

I am using lf with version `r26`, and few relevant configs in my `lfrc`,
```
set dircounts
set dircache off
set period 1
```
@srimadhan11 I think you are right, this should update with `load` commands. I don't see any reason it shouldn't. Marking the issue as a bug.

Not quite related to this issue but `set dircache off` in your example should be `set nodircache` instead. More about this in #758 . But it still does not update dircounts and it seems that `period` and `dircache` does not work well together resulting in loading screens periodically.
@srimadhan11 I have taken a look at this today and unfortunately it does not seem as easy as I first imagined. The issue is that dircount is stored in the file itself in the parent's list. Since parent directory is not changed in this command, the directory is not refreshed and the dircount stays the same. So this behavior is somewhere in between a bug and working as intended. I would love to see an easy solution for this but I wouldn't get my expectations high if I were you. If you are using a custom command for creating a new file, maybe you can consider adding a manual remote `reload` at the end as a workaround.
Ohh okay, I thought it might be a small bug. Thank you for looking into this issue :)

Fix patch:
diff --git a/app.go b/app.go
index 5b7e344c..5611db9c 100644
--- a/app.go
+++ b/app.go
@@ -487,6 +487,10 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
 	}
 
 	app.ui.loadFile(app, true)
+
+	//mark the current directory as updated for refresh
+	app.nav.currDir().updated = true
+
 	app.nav.renew()
 }
 
@@ -522,6 +526,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
 		cmd.Stderr = os.Stderr
 
 		app.runCmdSync(cmd, prefix == "!")
+
 		return
 	}
 
diff --git a/nav.go b/nav.go
index 31788001..f11e2ff5 100644
--- a/nav.go
+++ b/nav.go
@@ -179,6 +179,7 @@ type dir struct {
 	ignoredia   bool       // ignoredia value from last sort
 	noPerm      bool       // whether lf has no permission to open the directory
 	lines       []string   // lines of text to display if directory previews are enabled
+	updated     bool       // directory has been updated after last dirCheck
 }
 
 func newDir(path string) *dir {
@@ -521,7 +522,7 @@ func (nav *nav) checkDir(dir *dir) {
 	}
 
 	switch {
-	case s.ModTime().After(dir.loadTime):
+	case s.ModTime().After(dir.loadTime) || dir.updated:
 		now := time.Now()
 
 		// XXX: Linux builtin exFAT drivers are able to predict modifications in the future
@@ -1372,6 +1373,8 @@ loop:
 	if errCount == 0 {
 		app.ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mCopied successfully\033[0m"}, 1}
 	}
+	//mark the current directory as updated for refresh
+	nav.currDir().updated = true
 }
 
 func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
@@ -1484,6 +1487,8 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
 	if errCount == 0 {
 		app.ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1}
 	}
+	//mark the current directory as updated for refresh
+	nav.currDir().updated = true
 }
 
 func (nav *nav) paste(app *app) error {


Test patch: