git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git p4: chdir resolves symlinks only for relative paths

From
PWPete Wyckoff <pw@padd.com>
Date
Feb 3, 2013, 23:08 UTC
Message-ID
<20130203230803.GA25555@padd.com>
In-Reply-To
<CAAMmcSSEzs3+vZDO=FDMV9c2rp-8HTdMuPeeQCkok6y7sRDYJw@mail.gmail.com>
mfazekas@szemafor.com wrote on Tue, 29 Jan 2013 09:37 +0100:
Show 32 quoted lines
> If a p4 client is configured to /p/foo which is a symlink
> to /vol/bar/projects/foo, then resolving symlink, which
> is done by git-p4's chdir will confuse p4: "Path
> /vol/bar/projects/foo/... is not under client root /p/foo"
> While AltRoots in p4 client specification can be used as a
> workaround on p4 side, git-p4 should not resolve symlinks
> in client paths.
> chdir(dir) uses os.getcwd() after os.chdir(dir) to resolve
> relative paths, but as a side effect it resolves symlinks
> too. Now it checks if the dir is relative before resolving.
> 
> Signed-off-by: Miklós Fazekas <mfazekas@szemafor.com>
> ---
>  git-p4.py |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/git-p4.py b/git-p4.py
> index 2da5649..5d74649 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -64,7 +64,10 @@ def chdir(dir):
>      # not using the shell, we have to set it ourselves.  This path could
>      # be relative, so go there first, then figure out where we ended up.
>      os.chdir(dir)
> -    os.environ['PWD'] = os.getcwd()
> +    if os.path.isabs(dir):
> +        os.environ['PWD'] = dir
> +    else:
> +        os.environ['PWD'] = os.getcwd()
> 
>  def die(msg):
>      if verbose:

Thanks, this is indeed a bug and I have reproduced it with a test case. Your patch works, but I think it would be better to separate the callers of chdir(): those that know they are cd-ing to a path from a p4 client, and everybody else. The former should not use os.getcwd(), as you show.

I'll whip something up soon, unless you beat me to it.
		-- Pete
Previous: Miklós FazekasNext: Miklós Fazekas
Message 2 of 13 in “git p4: chdir resolves symlinks only for relative paths”
  1. git p4: chdir resolves symlinks only for relative pathsMiklós Fazekas, Jan 29, 2013
  2. Pete WyckoffFeb 3, 2013
  3. Miklós FazekasMar 7, 2013
  4. John KeepingMar 7, 2013
  5. 0/3 fix git-p4 client root symlink problemsPete Wyckoff, Mar 7, 2013
  6. 1/3 git p4 test: make sure P4CONFIG relative path worksPete Wyckoff, Mar 7, 2013
  7. 2/3 git p4 test: should honor symlink in p4 client rootPete Wyckoff, Mar 7, 2013
  8. Johannes SixtMar 8, 2013
  9. 0/3 fix git-p4 client root symlink problemsPete Wyckoff, Mar 11, 2013
  10. 1/3 git p4 test: make sure P4CONFIG relative path worksPete Wyckoff, Mar 11, 2013
  11. 2/3 git p4 test: should honor symlink in p4 client rootPete Wyckoff, Mar 11, 2013
  12. 3/3 git p4: avoid expanding client paths in chdirPete Wyckoff, Mar 11, 2013
  13. 3/3 git p4: avoid expanding client paths in chdirPete Wyckoff, Mar 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.