Ask a Jedi: Moving to UNIX, but didn't plan for it. Now what?

This post is more than 2 years old.

Sandeep asks:

i have been doing my development on windows machine but now i decided to move to linux .. but when i was writing my code i did not think i would be moving to linux anytime so i was not very careful when i did my includes ... is there any tool that you know of can help me fix cf code... i know i can use dreamweaver replace in a particular folder but still it might be too time consuming.

I can't think of a tool out there that will just 'magic wand' this away, but here are some things to consider:

First, you probably want to lowercase all your file names except for your Application.cfc/cfm files. I assumed there was probably a way to do this at the command line, and there was, from Speaking Unix (http://www.ibm.com/developerworks/aix/library/au-speakingunix7.html):

rename 'y/A-Z/a-z/' *

I don't have a UNIX system handy right now so your mileage may very. (Mac OSX doesn't have rename as a command as is case insensitive for filenames.) You could easily do it in CFML with cfdirectory and cffile. The point is to get all your files (again, excepting the special Application.cfc/cfm file and onRequestEnd.cfm) into lowercase first.

Now for the code. You actually have two 'areas' of code to worry about. One is the simple html, so for example, covering cases like so:

<img src="Foo.jpg">

You could probably handle this with a URL Rewrite, but that's only hiding the problem.

Your next area of concern is CFML. You have more to worry about than cfinclude. Anything that touches the file system would need to be updated, including fileExists, cffile, cfdirectory, etc. You could use the manual method for this - as you suggest with Dreamweaver, but it will be sluggish.

Lastly, you have the database side to worry about as well. Consider code that loads a preferred image. If you stored that image filename, then a Dreamweaver code search won't help. For example, it isn't immediately obvious that this can be a problem:

<body background="#session.mybackground#">

As a rule of thumb, I've always tried to use lowercase files everywhere in my code. It just makes it easier to read I think.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Scott P posted on 7/29/2008 at 4:55 AM

I might have an example in CFML in an older post, http://www.scottpinkston.or...

Comment 2 by Raymond Camden posted on 7/29/2008 at 4:58 AM

Nice - but you need to remove that use of ListContains. ;)

Comment 3 by Jim Priest posted on 7/29/2008 at 5:00 AM

WHY is Application.cfm capitalized? Anyone know?

I'm doing some work on Linux at home for a Windows hosted site and running into this all over the place... I'd agree the 'everything lowercase' just makes things easier in the long run.

Comment 4 by Scott P posted on 7/29/2008 at 5:07 AM

what ListContains? whistles innocently

Comment 5 by Brian Rinaldi posted on 7/29/2008 at 5:11 AM

I wrote about this exact problem a while back. Includes the code for handling the file renaming and the URL rewrite using Apache - http://www.remotesynthesis....

Comment 6 by Raymond Camden posted on 7/29/2008 at 5:17 AM

Cool Brian. I'd still point out though the need to worry about files being loaded via DB.

Comment 7 by Michael Sharman posted on 7/29/2008 at 5:31 AM

And don't forget that on Linux the database tables names (at least for MySQL) are case sensitive, columns are not however.

So keep a standard and stick to it!

http://www.chapter31.com/20...

Comment 8 by Chad Fenske posted on 7/29/2008 at 5:35 AM

I'm currently the lead on a project that is not only moving from a windows environment to an AIX environment, but from CF5 to CF8. We created a PERL script that will open every file in a given directory and lower case all references to .cfm, .js, .html ect. The script looks for these files in cfinclude tags, javascript include tags, stylesheet include tags, you get the idea. We have also added the ability to lower case calls to custom tags as well (thank you 8.01 hotfix 1). We also had to make sure that all the developers started lower casing file names and calls to those files as well. It's a lot of work to do all of this before we move the code to the new servers, but that time pales in comparison to what we would need to go through to fix it after we moved the code.

Comment 9 by Raymond Camden posted on 7/29/2008 at 5:38 AM

@MS: I wonder who on the MySQL dev team thought it made sense to check case for tables but not columns? Personally I think case sensitive file systems don't make sense. Why would you want to allow for foo.txt and Foo.txt in one folder anyway.

Comment 10 by Jim Priest posted on 7/29/2008 at 5:41 AM

Right now I'm working on a small site and it's in SVN so renaming files has to be done via SVN (and so far I've been doing it manually). I'll have to dig around to see if there are any solutions to recursively go through a repo and rename everything to lowercase.

Comment 11 by Michael Sharman posted on 7/29/2008 at 6:44 AM

@Ray - I believe it's because MySQL's table stoage is on the file system as a directory, hence the case sensitivity issue.

So a database called "blogCFC" would have a directory called "blogCFC" with all the data files in it etc

Comment 12 by Raymond Camden posted on 7/29/2008 at 6:53 AM

@Michael - that makes sense actually.

Comment 13 by Tom Mollerus posted on 7/29/2008 at 8:34 AM

@Jim: my guess for the reason why Application.cfm/.cfc needs to be capitalized is so that there wasn't any confusion on case-sensitive systems such as Unix or Linux.

For instance, on a *nix system it would be possible to have both "Application.cfm" and "application.cfm". Even if CF were built to use one of the two by precendence, I can see all sorts of mistakes being made by developers who couldn't remember which of the two files was in use in a given folder.

Comment 14 by JC posted on 7/29/2008 at 4:33 PM

if you need to rename files like this on windows... this tool is just fantastic:

http://www.bulkrenameutilit...

Saves me hours and hours and hours when I'm screwing around with log files from clusters, and the few times I've had case issues.

Comment 15 by sandeep posted on 7/29/2008 at 5:28 PM

bulkrename is really cool i have used this tool long time back. should make part of the moving to Linux easier.