Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: completion cache mkdir & startup stat/zstat



I noticed that the ~/.zcompcache is being created with normal umask,
which seems a bit odd for something that might be used for caching data
from private areas; a cache should typically be private IMO.  Best way
to test if MO differs from the norm is to throw the patch out there.

I initially switched to using zf_mkdir but then realised why that was
not the right thing to do.  There were a couple of things which I had to
think over; so I added explanatory comments.  A disturbing trend, this.

More arguably, I also changed StartupFiles/zshrc to only load zstat, not
stat.  Hopefully, this really is always used as an example (as warned in
BIG CAPS at the start) and never automatically deployed to new user
accounts by an environment which depends on stat being the zsh built-in
for aforesaid new user accounts.  It seems unlikely that we'd break
anything and we really do need to make the switch at some point.  So I'm
doing so.  I claim bonus points for demonstrating Peter's cool features
work in the demo file.

----------------------------8< cut here >8------------------------------
Index: Completion/Base/Utility/_store_cache
===================================================================
RCS file: /home/cvsroot/zsh/Completion/Base/Utility/_store_cache,v
retrieving revision 1.3
diff -p -u -r1.3 _store_cache
--- Completion/Base/Utility/_store_cache	9 Oct 2002 20:38:28 -0000	1.3
+++ Completion/Base/Utility/_store_cache	11 Jul 2008 06:38:24 -0000
@@ -13,7 +13,11 @@ if zstyle -t ":completion:${curcontext}:
     if [[ -e "$_cache_dir" ]]; then
       _message "cache-dir style points to a non-directory\!"
     else
-      (zmodload zsh/files 2>/dev/null; mkdir -p "$_cache_dir" )
+      # if module load fails, we *should* be okay using normal mkdir so
+      # we load feature b:mkdir instead of b:zf_mkdir; note that modules
+      # loaded in a sub-shell don't affect the parent.
+      ( zmodload -F zsh/files b:mkdir; mkdir -m 0700 -p "$_cache_dir"
+      ) 2>/dev/null
       if [[ ! -d "$_cache_dir" ]]; then
         _message "couldn't create cache-dir $_cache_dir"
         return 1
@@ -27,7 +31,9 @@ if zstyle -t ":completion:${curcontext}:
     if [[ -e "$_cache_ident_dir" ]]; then
       _message "cache ident dir points to a non-directory:$_cache_ident_dir"
     else
-      (zmodload zsh/files 2>/dev/null; mkdir -p "$_cache_ident_dir")
+      # See also rationale in zmodload above
+      ( zmodload -F zsh/files b:mkdir; mkdir -m 0700 -p "$_cache_ident_dir"
+      ) 2>/dev/null
       if [[ ! -d "$_cache_ident_dir" ]]; then
         _message "couldn't create cache-ident_dir $_cache_ident_dir"
         return 1
Index: StartupFiles/zshrc
===================================================================
RCS file: /home/cvsroot/zsh/StartupFiles/zshrc,v
retrieving revision 1.3
diff -p -u -r1.3 zshrc
--- StartupFiles/zshrc	9 May 2001 16:57:31 -0000	1.3
+++ StartupFiles/zshrc	11 Jul 2008 06:25:45 -0000
@@ -95,10 +95,11 @@ setopt   autopushd pushdminus extendedgl
 unsetopt bgnice autoparamslash
 
 # Autoload zsh modules when they are referenced
-zmodload -a zsh/stat stat
 zmodload -a zsh/zpty zpty
 zmodload -a zsh/zprof zprof
 zmodload -ap zsh/mapfile mapfile
+# stat(1) is now commonly an external command, so just load zstat
+zmodload -aF zsh/stat b:zstat
 
 # Some nice key bindings
 #bindkey '^X^Z' universal-argument ' ' magic-space



Messages sorted by: Reverse Date, Date, Thread, Author