Symbolic Links and Workspace Roots

UNIX symlinks and the p4 command line

Info & Tags

Article #:
44
Created:
04/25/07
Modified:
10/27/08
Tags:
root, symbolic links, symlinks, workspaces

SUMMARY

UNIX symbolic links and the p4 command line


DETAILS

If you have symbolic links in your UNIX filesytem and your client view is in a symlinked directory, you might get "not in client view" responses from p4 commands when the command line contains files with relative pathnames. As a result of the symlink, p4 can sometimes pick the wrong path to use as a root when it determines whether the file is in the client view.

One reason for this is that the p4 command-line takes the $PWD environment variable as authoritative over the results from the getcwd() call.

You can check on the mapping of the current directory by running:

p4 where

You can see the current working directory which the Perforce client sees by running:

p4 info

If the directories displayed by these commands do not match, p4 is probably using the wrong path for the current directory. You can explicitly tell Perforce what the current directory is by using the -d flag with p4 commands.

For example:

p4 -d /tmp info 

causes Perforce to translate relative pathnames as if the current directory is /tmp, no matter what the current working directory actually is. This mechanism can be used to provide p4 with the canonical name for a directory. For example, in bash, try:

alias p4='p4 -d `pwd`'

Use single-quotes so bash does not accidentally interpret the backtics before storing the alias. This way Perforce sees the "real" path as opposed to the symlinked path stored in $PWD.

Even if $PWD is set correctly, it may need the export command. For example,

export PWD 

If you see "not under client root" or "not in client view" messages related to symlinks, check to see that $PWD is set, and also that the export command is run on $PWD. Most shells set the $PWD variable automatically, but some shells require that $PWD be exported before it can be used.

AltRoots

With Alternate Client Roots, introduced with the release of server version 2002.2, you are no longer forced to use command-line tricks to work around $PWD versus CWD differences and shell problems; now you can just enter the symlink into an alternate root and Perforce continues along without complaints.

However, this does not necessarily fix the issue of symlinks under the Perforce client root. For that, you still need to either set and export the $PWD environment variable, or use the -d argument as necessary.