#856 Issue closed: clean up 'url_host()' mess

Labels: cleanup, fixed / solved / done

jsmeix opened issue at 2016-06-01 08:50:

Current rear master.

While I am trying to implement https://github.com/rear/rear/issues/845
I get totally confused by what 'url_host()' means.

The current url_host() function in global-functions.sh
does not result the hostname in an URL but
it results simply the part after the scheme.

E.g. for

scheme://foo@bar/something/else

url_host() results 'foo@bar' and not only 'foo'
as the name of that function indicates.

I tried to 'fix' that so that the url_host() function
results what its name tells but that lead into mess.

The really bad thing is that some places rely on
this obscure behaviour e.g. in global-functions.sh

        (sshfs)
            mount_cmd="sshfs $(url_host $url):$(url_path $url) $mountpoint -o $options"

because sshfs can be called as

sshfs [user@]host:[dir] mountpoint [options] 

Accordingly as a precondition before implementing https://github.com/rear/rear/issues/845
I have to first clean up the current 'url_host()' mess.

I think I will do the following to avoid regression:

First I rename the current 'url_host()' function into 'url_user_at_host()'
and replace all calls of that function as needed.

Then I add two new functions 'url_host()' and 'url_user()'
that result what their name tells.

Finally I can use the new functions 'url_host()' and 'url_user()'
to implement https://github.com/rear/rear/issues/845#issuecomment-220956048 properly.

jsmeix commented at 2016-06-01 09:29:

I will keep it simpler:

To avoid regressions I will not change any existing functionality.
I will keep the current 'url_host()' function as is.
But I will add explanatory comments that tell
what current 'url_host()' function actually results.

I will add two new functions 'url_hostname()'
and 'url_username()' that result what their name tells.

Then I can use the new functions 'url_hostname()'
and 'url_username()' to implement https://github.com/rear/rear/issues/845

jsmeix commented at 2016-06-01 10:46:

In https://github.com/rear/rear/pull/857 I implemented
what I wrote in https://github.com/rear/rear/issues/856#issuecomment-222940800

jsmeix commented at 2016-06-01 15:00:

With https://github.com/rear/rear/pull/857 I consider
this issue as sufficiently fixed (at least for now).

Perhaps in the future we may need additional functions
url_port() and url_password() to support all usual
components of a generic URI of the form

scheme:[//[user[:password]@]host[:port]][/]path

FYI:
I think in
https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
the syntax that a generic URI is of the form

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

is not fully correct because I think the ':password' part
is optional i.e. I think a URI could contain a plain 'user@'
without a ':password' like

BACKUP_URL=ftpfs://user@host/rear/

cf. https://github.com/rear/rear/issues/845


[Export of Github issue for rear/rear.]