Weed out non-existing directories when loading DIRSTACKFILE
authorFrank Terbeck <ft@grml.org>
Fri, 26 Jun 2015 09:38:33 +0000 (11:38 +0200)
committerFrank Terbeck <ft@grml.org>
Fri, 26 Jun 2015 09:52:52 +0000 (11:52 +0200)
Between saving our persistent dirstack file and loading it in the next
session, directories of which the names we saved might have ceased to
exist. This can cause problems, when the first entry from the saved
dirstack points to a non-existing directory.

Ordinarily, that would not be catastrophic and only lead to an error
message while loading the setup. But if you throw auto-mounters into the
mix, this can cause the setup to hang until the auto-mounter runs into a
timeout.

The proposed fix is to filter out names of non-existing directories
while loading the saved dirstack file.

This leaves the window between loading the file and trying to change to
the first then-existing directory of the file open for the directory to
vanish. That would be tough luck, I guess.

Reported-by: Till Hofmann <hofmanntill@gmail.com>
Signed-off-by: Frank Terbeck <ft@grml.org>
etc/zsh/zshrc

index e88ba04..d4978e4 100644 (file)
@@ -1620,7 +1620,9 @@ DIRSTACKSIZE=${DIRSTACKSIZE:-20}
 DIRSTACKFILE=${DIRSTACKFILE:-${ZDOTDIR:-${HOME}}/.zdirs}
 
 if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
-    dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
+    # Enabling NULL_GLOB via (N) weeds out any non-existing
+    # directories from the saved dir-stack file.
+    dirstack=( ${(f)"$(< $DIRSTACKFILE)"}(N) )
     # "cd -" won't work after login by just setting $OLDPWD, so
     [[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
 fi