shithub: vdir

Download patch

ref: dd0e9a1515ca68355bd8117b0903aa88db283c83
parent: ede5b76c75425f4b6e78f95dd0af7fb32d9846bb
author: phil9 <telephil9@gmail.com>
date: Mon Oct 11 08:16:37 EDT 2021

ensure file exist before sending to plumber

	if a file is deleted outside of vdir and we try to plumb it
	there is nothing that tells there was an issue.
	We know check that the file exist before plumbing and display
	an error message if it does not exist anymore.

	In addition we refresh the view when we notice a file or directory
	has disappeared.

--- a/vdir.c
+++ b/vdir.c
@@ -9,6 +9,7 @@
 #include "icons.h"
 
 extern void alert(const char *title, const char *message, Mousectl *mctl, Keyboardctl *kctl);
+void redraw(void);
 
 enum
 {
@@ -150,11 +151,10 @@
 		snprint(newpath, sizeof newpath, dir);
 	else
 		snprint(newpath, sizeof newpath, "%s/%s", path, dir);
-	if(access(newpath, 0)<0){
+	if(access(newpath, 0)<0)
 		alert("Error", "Directory does not exist", mctl, kctl);
-		return;
-	}
-	snprint(path, sizeof path, abspath(path, newpath));
+	else
+		snprint(path, sizeof path, abspath(path, newpath));
 	loaddirs();
 }
 
@@ -202,14 +202,23 @@
 	free(p);
 }
 
-void
+int
 plumbfile(char *path, char *name)
 {
 	char *f;
+	int e;
 
 	f = smprint("%s/%s", path, name);
-	plumbsendtext(plumbfd, "vdir", nil, nil, f);
+	e = access(f, 0)==0;
+	if(e)
+		plumbsendtext(plumbfd, "vdir", nil, nil, f);
+	else{
+		alert("Error", "File does not exist anymore", mctl, kctl);
+		loaddirs();
+		redraw();
+	}
 	free(f);
+	return e;
 }
 
 void
@@ -542,8 +551,8 @@
 				cd(d.name);
 				redraw();
 			}else{
-				plumbfile(path, d.name);
-				flash(n);
+				if(plumbfile(path, d.name))
+					flash(n);
 			}
 		}
 	}else if(m.buttons&8)