[p4ruby] fix for symlink-in-PWD problem

Tony Smith tony at smee.org
Fri Mar 7 05:46:11 PST 2008

The easier workaround is:

	ENV.delete( "PWD" )

If PWD isn't present in the environment, then the Perforce API will fall back 
on using the result of getcwd(), which expands your symlink as required.

Note that the PWD environment variable is intended to supress expansion of 
symlinks. Back in the early 90's it used to drive me nuts when I cd'd across 
a symlink and couldn't get back using 'cd ..'. PWD was the solution that the 
shells adopted for this and Perforce is simply following the convention.

Most of the time that's what's wanted. When it isn't, deleting PWD from the 
environment usually solves the problem.

Hope that helps!


On Thursday 06 March 2008 14:29:24 bob p4 wrote:
> [ In reference to
> http://maillist.perforce.com/pipermail/p4ruby/2008q1/000115.html ]
> I finally got P4Win cooperating with cygwin-p4ruby via listing my
> cygwin path in AltRoots, however I ran into a bit of confusion along
> the way.  My client root is /home/me/some/long/path, which I have
> symlinked to /home/me/work.  Apparently this causes a glitch since the
> shell sets PWD to /home/me/work instead of the full path:
> http://kb.perforce.com/UserTasks/ConfiguringP4/SymbolicLinks
> Note the Perforce authors decided not to solve the problem: "However,
> this doesn't necessarily fix the issue of symlinks under the Perforce
> client root. For that, you will still need to either set and export
> the $PWD environment variable, or use the -d argument as necessary."
> May I suggest the following patch to workaround it:
> require 'p4'
> require 'pathname'
> class P4
>    class << self
>       alias_method :previous_new, :new
>       def new(*args, &block)
>          previous_pwd = ENV["PWD"]
>          begin
>             ENV["PWD"] = Pathname.new(previous_pwd).realpath
>             previous_new(*args, &block)
>          ensure
>             ENV["PWD"] = previous_pwd
>          end
>       end
>    end
> end
> I am using p4ruby-2007.3 with cygwin p4api-2007.3.143793.
> IMO Perforce should expand away the symlink, but until then at least
> P4Ruby can do it.  Please spare others from this needless pain!
> _______________________________________________
> p4ruby mailing list
> p4ruby at perforce.com
> http://maillist.perforce.com/mailman/listinfo/p4ruby
> !DSPAM:47d0000351257730779061!

More information about the p4ruby mailing list