]> granicus.if.org Git - neomutt/commitdiff
Let the browser handle non-existent directories more gracefully.
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 13 Sep 2000 09:47:54 +0000 (09:47 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 13 Sep 2000 09:47:54 +0000 (09:47 +0000)
From Byrial Jensen.

browser.c

index c30bea45d2c3200dbaab046941d7943233ee8031..1bdb7cee20c2d6f805588034adb6c1f73ac80276 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <errno.h>
 
 static struct mapping_t FolderHelp[] = {
   { N_("Exit"),  OP_EXIT },
@@ -343,7 +344,7 @@ static void init_state (struct browser_state *state, MUTTMENU *menu)
 }
 
 static int examine_directory (MUTTMENU *menu, struct browser_state *state,
-                             const char *d, const char *prefix)
+                             char *d, const char *prefix)
 {
   struct stat s;
   DIR *dp;
@@ -351,8 +352,19 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
   char buffer[_POSIX_PATH_MAX + SHORT_STRING];
   BUFFY *tmp;
 
-  if (stat (d, &s) == -1)
+  while (stat (d, &s) == -1)
   {
+    if (errno == ENOENT)
+    {
+      /* The last used directory is deleted, try to use the parent dir. */
+      char *c = strrchr (d, '/');
+
+      if (c && (c > d))
+      {
+       *c = 0;
+       continue;
+      }
+    }
     mutt_perror (d);
     return (-1);
   }