0

Strange behavior with ColdFusion ExpandPath() when using Symbolic Links

ColdFusion, Technology, Linux

I was playing around with the Quicksilver framework last night, and for some reason it was unable to find and instantiate my CFCs properly.  After digging into the framework a bit and determining where it was breaking, I discovered something strange about the way that ColdFusion interprets ExpandPath() when it exists in a directory that is defined as a symbolic link.  I am not sure if the same behavior exists on Macs, but I would imagine it does.  If someone could confirm that to be the case, I would be interested.

For starters, I usually have a 'www' directory in my user home directory. This way when I pass my user profile around from distro to distro, my development work is included in my home directory.  For ease of configuration I typically have a symbolic link in my OS that points /www/ ---> /home/dshuck/www/.  Then when I am creating a new web project called 'davescode', I would put it in /home/dshuck/www/davescode, but my Apache config would usually point to /www/davescode.  For the past several years, this approach has worked will for me.  That is until last night when experimenting with Quicksilver. 

When Quicksilver loads, it creates a list of service CFCs in the the application in such a way that if I had Foo.cfc in a directory 'com' in the root of my davescode site, it would look like /home/dshuck/www/davescode/com/Foo.cfc.  When I initted the application, I was getting an error that  it couldn't find the CFC home/dshuckcom/Foo.cfc.  Essentially what was happening is that it was getting the full path of the CFC and replacing the path to the root of the site with "".  In a perfect world the value of the path after the string replace would have looked like com/Foo.cfc.  Unfortunately that was not so.  Here's why!

I put a test file called path.cfm in the root of my davescode site that considted of the following:

<cfoutput>#ExpandPath("./")#</cfoutput>
<br/>
<cfoutput>#ExpandPath("/")#</cfoutput>


The result was very surprising!
/home/dshuck/www/davescode/
/www/davescode/


For some reason when you do ExpandPath("/") it looks at the symbolic link path, but when you do ExpandPath("./"), it looks at the true file path.  For the life of me, I can't think of why that would be.  If anyone has an explanation, I would be all ears!

Ben Nadel said:
 
Very funky. I have seen issues as well with virtual directories in IIS. I have started to defer to the use of getCurrentTemplatePath() as I find that that has always been accurate. Then, I can just base paths relative to that.
 
posted 58 days ago
Add Comment Reply to: this comment OR this thread
 
Adam Cameron said:
 
Is it because you're using a symbolic link rather than a hard link? A symbolic link is just a redirection (of sorts) to the original location. A hard link is - I guess - a proper junction.

(I'm just interpreting what I read here: http://ss64.com/bash/ln.html).

Given the symbolic link is just "redirecting", then expanding the path "./" kinda makes sense to resolve to the actual directory. Kinda. Why it doesn't do the same for "/"? Dunno.

What happens if you use a hard link?

--
Adam
 
posted 58 days ago
Add Comment Reply to: this comment OR this thread
 
 
Interesting point... I hadn't thought about doing a hard link. Still, the difference of interpretation between "/" and "./" is odd.

This is what I get when I try to create the hard link:

$ sudo ln -d /home/dshuck/www /www
ln: creating hard link `/www' => `/home/dshuck/www': Invalid cross-device link

Because I have my /home mount point partitioned on a separate place than /, it is effectively 2 devices even though they exist on the same physical HD. Apparently hard links can only exists within a single device.
 
posted 58 days ago
Add Comment Reply to: this comment OR this thread
 
Adam Cameron said:
 
Yikes. I'm sure there's a way to do it: NTFS allows cross-device mountpoints, so *nix will allow it too. However what little I ever used to know about that sort of thing has long since departed my small brain, so I can't offer any sensible comment. I'm sure there'll be a *nix guru/geek out there who will know some arcane series of switches to add to your ln statement to make it all work ;-)

--
Adam
 
posted 58 days ago
Add Comment Reply to: this comment OR this thread
 
Elliott Sprehn said:
 
This is expected since ./ is expanding from the CGI script path. / is the default webroot.

For example if you request foo.site.com/app1/a/test.cfm

You have the webroot for this subdomain set as /home/foo_site_com/www/app1/public/

The main webroot configured for apache when you setup JRun is set to /home/jrun/www/

expandPath("./") => /home/foo_site_com/www/app1/public/a/
expandPath("/") => /home/jrun/www/

btw, it's super hard to read the grey on grey on the comment form :(
 
posted 53 days ago
Add Comment Reply to: this comment OR this thread
 

Search