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

Re: PATCH: sshfs user-side automount



Peter Stephenson wrote on Mon, 17 Feb 2020 15:45 +0000:
> This certainly won't go in until the dust has settled, both on the
> release and the proposed change,

Why don't you push it to the 5.9 branch, then?  That's what it's for.

> +++ b/Doc/Zsh/contrib.yo
> @@ -386,6 +386,7 @@ findex(_cdr)
>  findex(chpwd_recent_add)

(The character on the first column is a non-breaking space, so
the diff couldn't easily be applied.)

> --- /dev/null
> +++ b/Functions/Chpwd/chpwd_check_mount
> @@ -0,0 +1,107 @@
> +# Return 0 if the path is available, possibly after mounting, 1 if
> +# it is still not available at the end of the function.
⋮
> +# The return status is 0 if the path exists; 1 if it does not exist
> +# (even if a mount was made in an attempt to provide it); 2 if some
> +# condition other than a missing directory was found, in particular
> +# bad zstyle configuration or an sshfs failure.

The return status is documented in two different places.

> +# If the argument to the function is a path that doesn't exist, the
> +# system checks to see if the path is under /local/dir.  If, so the
> +# other element of the pair is examined.  If "method" is a known method
> +# for moutning the remote path path-to-dir the path, it is mounted and

Typo "moutning"

> +
> +# We'll allow the path to be something other than a directory as we
> +# are in any case going to check prefixes.
> +if [[ -e $1 ]]; then
> +  if [[ -d $1 ]]; then

This does two stat()s in a row on what might be a subdirectory of an
sshfs mount.  If optimization is a concern, there might be a speed gain
from rearranging the code to «if [[ -d $1 ]]; … elif [[ -e $1 ]]; … fi»,
or possibly even to use zstat here.

> +    # As this may be the mount point itself, we'll assume it
> +    # should be non-empty, though we don't know for sure.
> +    local -a files
> +    files=($1/*(DN))
> +    (( ${#files} )) && return 0

Suggest to add the «Y1» glob qualifier, or to use the «F» glob qualifier.

Suggest to directly check whether $1 is a mountpoint.  On my system
there's a mountpoint(1) utility that can be used as «if mountpoint -q
/home; then», but it might be unportable.  For portability I guess we
could use «zstat +device».

> +  else
> +    # Not a directory, so assume everything is OK.
> +    return 0
> +  fi
> +fi

> +for locdir remote in $mpath; do
> +  # To be clever here we would look for the shortest matching path
> +  # and work our way down.
> +  if [[ $dir = ${locdir%%:*}(|/*) ]]; then
> +    mpoint=${locdir#*:}
> +    case $remote in
> +      ((#b)sshfs:(*))
> +      if ! sshfs -o workaround=rename $match[1] $mpoint; then

Quote $match[1] to prevent null elision.

Cheers,

Daniel



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