zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Re: PATCH: sshfs user-side automount
Date: Tue, 18 Feb 2020 10:44:51 +0000	[thread overview]
Message-ID: <20200218104451.1813845b@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <1581954328.4418.19.camel@samsung.com>

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

  reply	other threads:[~2020-02-18 10:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200217154528eucas1p17c3730dd3979ce40eb383d7f6889c5e2@eucas1p1.samsung.com>
2020-02-17 15:45 ` Peter Stephenson
2020-02-18 10:44   ` Daniel Shahaf [this message]
2020-02-18 11:10     ` Peter Stephenson
2020-02-18 11:24       ` Daniel Shahaf
2020-03-16 10:11       ` Peter Stephenson
2020-03-16 18:36         ` Daniel Shahaf
2020-03-17 12:19           ` Peter Stephenson
2020-03-17 14:00             ` Daniel Shahaf
2020-03-17 14:08               ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200218104451.1813845b@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).