]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
Improve zsh/zstat integration; also make it handle dirs
authorDaniel Hahler <git@thequod.de>
Sun, 25 Jan 2015 18:18:25 +0000 (19:18 +0100)
committerDaniel Hahler <git@thequod.de>
Sun, 25 Jan 2015 18:22:52 +0000 (19:22 +0100)
autoenv.zsh
tests/_autoenv_stack.t
tests/_autoenv_utils.t

index 24f4b04481ca7735a9ef1286fcecf36bacef3efb..3ec01e910407b4d8c3afaf5043409ea23606e6b8 100644 (file)
@@ -60,13 +60,23 @@ _autoenv_stack_entered_add() {
   _autoenv_stack_entered_mtime[$env_file]=$(_autoenv_get_file_mtime $env_file)
 }
 
-_autoenv_get_file_mtime() {
-  if [[ -f $1 ]]; then
-    zstat +mtime $1
-  else
-    echo 0
-  fi
-}
+
+# zstat_mime helper, conditionally defined.
+# Load zstat module, but only its builtin `zstat`.
+if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then
+  # If the module is not available, define a wrapper around `stat`, and use its
+  # terse output instead of format, which is not supported by busybox.
+  # Assume '+mtime' as $1.
+  _autoenv_get_file_mtime() {
+    setopt localoptions pipefail
+    stat -t $1 2>/dev/null | cut -f13 -d ' ' || echo 0
+  }
+else
+  _autoenv_get_file_mtime() {
+    zstat +mtime $1 2>/dev/null || echo 0
+  }
+fi
+
 
 # Remove an entry from the stack.
 _autoenv_stack_entered_remove() {
@@ -132,16 +142,6 @@ _autoenv_debug() {
 }
 # }}}
 
-# Load zstat module, but only its builtin `zstat`.
-if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then
-  # If the module is not available, define a wrapper around `stat`, and use its
-  # terse output instead of format, which is not supported by busybox.
-  # Assume '+mtime' as $1.
-  zstat() {
-    stat -t $2 | cut -f13 -d ' '
-  }
-fi
-
 
 # Generate hash pair for a given file ($1).
 # A fixed hash value can be given as 2nd arg, but is used with tests only.
index 6f659c693462cee4f052bd27722e84f5c1466f66..299d0642c08e73df7e01a28bab9895adb5636f8e 100644 (file)
@@ -12,6 +12,8 @@ Add existing entries.
 
   $ mkdir -p sub/sub2
   $ touch -t 201401010101 sub/file
+  $ touch -t 201401010102 sub
+  $ touch -t 201401010103 sub/sub2
   $ _autoenv_stack_entered_add sub
   $ _autoenv_stack_entered_add sub/file
   $ _autoenv_stack_entered_add sub/sub2
@@ -26,7 +28,7 @@ Add existing entries.
   sub sub/file sub/sub2 non-existing
 
   $ echo $_autoenv_stack_entered_mtime
-  0 1388538060 0 0 (glob)
+  1388538180 1388538060 1388538120 0
 
 Touch the file and re-add it.
 
index 3da1fde11ff22fa30ce4f3a9d74da42c674dc855..91fa1bef744f6c19ef4ea418a4ff9beda3ec68e3 100644 (file)
@@ -71,3 +71,17 @@ Re-add the first one, with a new hash.
   :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
   :/tmp/cramtests-*/_autoenv_utils.t/first:65eb010197b73ddc109b7210080f97a87f53451e:1 (glob)
 }}}
+
+
+Explicit calls to _autoenv_get_file_mtime to test alternative implementation
+of _autoenv_get_file_mtime (via ZDOTDIR.invalid-module_path/).
+
+  $ _autoenv_get_file_mtime non-existing
+  0
+  $ touch -t 201401010101 file
+  $ _autoenv_get_file_mtime file
+  1388538060
+  $ mkdir dir
+  $ touch -t 201401010102 dir
+  $ _autoenv_get_file_mtime dir
+  1388538120