On Wed, Mar 19, 2014 at 03:16:28PM -0700, Brian Shore wrote:
> On Wed, Mar 19, 2014 at 11:35 AM, Jason A. Donenfeld <[email protected]> wrote:
> > On Wed, Mar 19, 2014 at 12:31 PM, Brian Shore <[email protected]>
> > wrote:
> >> Also, I don't see any realpath(1) on RHEL6, so this could introduce
> >> some compatibility issues.
> >
> > Thanks for pointing this out! I'd like to use "readlink -f", but this isn't
> > available on the BSDs. Any suggestion for something broadly supported?
> 
> RHEL is probably the only "large" Linux distribution that doesn't have
> it yet (realpath(1) was added in v8.15).
> 
> FreeBSD has a realpath(1) but OS X doesn't.  OSX can install gnu
> coreutils to provide greadlink.
> 
> I think there are enough variations to justify adding this as a shell
> function in the platform-specific code.  Each platform can define
> "real_path" and implement it as desired (possibly even in pure sh).
> 
> I would aim for the syntax of realpath(1) without parameters (because
> they differ between platforms).
> 
> realpath FILE...
> 
> If using shell functions as a fall-back, this page seems a good place to 
> start:
> https://sites.google.com/site/jdisnard/realpath

I don't think any of this realpath nonsense is necessary at all.  Instead of
tacking '/..' to the end of current, just use a parameter expansion to strip
off '/*'.  Since you know that 'current' will always have "$PREFIX" as a
prefix, you're guaranteed to terminate.

        current="$PREFIX/$1"
        while true; do
                [[ "$(realpath -q "$current")" == "$(realpath -q "$PREFIX")" ]] 
&& break
                [[ -f "$current/.gpg-id" ]] && break
                current="$current/.."
        done

becomes:

        current="$PREFIX/$1"
        while [[ $current != "$PREFIX" ]]; do
                if [[ -f $current/.gpg-id ]]; then
                        break
                fi
                current=${current%/*}
        done

  Josh
_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to