On Tue, Jul 7, 2020 at 5:44 PM 'Jacob Kopczynski' via golang-nuts
<
golan...@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
~ is a symbol the shell expands to home directory. Outside a shell, ~
means ~. If you mkdir ~, you'll get a directory named ~ in the current