On Tue, Jul 7, 2020 at 4:44 PM 'Jacob Kopczynski' via golang-nuts
<golang-nuts@googlegroups.com> wrote:
>
> I tried to state a path relative to the home directory, since in the context 
> I am writing for the path from ~ to the Git repository will be consistent, 
> though the meaning of ~ may change based on user. A snippet:
>
> const specPath = "~/trunk/infra/metadata/config.cfg"
> absPath, _ := filepath.Abs(specPath)
> if err := readJSONPb(absPath, &s); err != nil {
>     fmt.Printf("specPath is %s, or as absolute %s\n", specPath, absPath)
>     return nil, errors.Annotate(err, "extracting tests from spec").Err()
> }
> However, this produces this output:
> specPath is ~/trunk/infra/metadata/config.cfg, or as absolute 
> /home/jkop/trunk/infra/~/trunk/infra/metadata/config.cfg
> extracting tests from spec: read JSON pb: open 
> /home/jkop/trunk/infra/~/trunk/infra/metadata/config.cfg: no such file or 
> directory
>
> This is a) surprising, since I would expect a platform-sensitive absolute 
> path function to deal with platform-global shortcuts like ~, and b) 
> completely undocumented. The docs say that "Abs returns an absolute 
> representation of path. If the path is not absolute it will be joined with 
> the current working directory to turn it into an absolute path." It doesn't 
> say "If the path is not rooted", but "not absolute". This is not an absolute 
> representation but it does specify an absolute path unambiguously.
>
> What's the process for submitting a change to a core library like this one? 
> Ideally, to the code, but I'd settle for making the documentation clearer.

On Unix systems a leading ~ in a path is expanded by the shell.
Programs do not normally treat a leading ~ as being special in any
way.  For example, the C glob function ignores ~ unless you explicitly
pass the GLOB_TILDE flag (and GLOB_TILDE is not even defined by POSIX,
it's a common extension).  So I think the Go functions are acting in
the usual Unix way, and I don't yet see a reason to change them.
Whether the docs should be changed depends on what the suggested
change is.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVyY%2B0jjUsHKFwyXUNcyTo68v9k8%2BPziPbuQBRa5yd8xg%40mail.gmail.com.

Reply via email to