Tuesday, August 11, 2009

(To Unix guy) Yes, it does...Windows Has Symlinks.

This is one really started to irk me lately, so here we go.

Qualifier: I am not a Windows fanboi at all. My primary machines are Macs, with a Windows box for Windows-only games and testing, and a remote one for development (I have two, one Centos, the other Windows Server). However, I am not a Mac fanboi either. The primary reason I own Macs is that in my field, most people work on Macs. Mac is also ruling the roost of UI-think these days, and I'm a UI developer. If and when the wheel turns, depending on the wants and needs of my clients, I will too. The ability to reinvent yourself is what keeps you viable and current; just ask David Bowie or Will I Am.

That said, to all the Unix guys who wave symlinks in the face of the Windows developer:

WINDOWS HAS SYMLINKS. YES IT DOES. THEY ARE CALLED NTFS JUNCTIONS.

I post this because recently, a friend who runs a business got shafted by some PHP developer, who got in over his head, screwed up his site, and suddenly "wasn't available". He got the entire site zipped up and sent it to me. It didn't work when I just dumped it into XAMPP on a Windows dev box I have running; the pages were requesting directories that didn't exist in the file structure I was sent.

I contacted him, and he responded, "what are you running it on", I said, "oh, a Windows box". He said, "you can't do that, the site uses symlinks".

While I understand the "why" of why he did this (easily point at other directories to try other versions), I don't really think it's in the interests of the client (and therefore, isn't a good idea). You can just rename directories to try alternate versions of a codebase. It also defeats the purpose of the whole "can run on anything" mantra; as far as this developer knew, he had tied a basic PHP site to Unix-based OSs, with the thought that, "you shouldn't run Windows". My friend (the business owner) had no knowledge of this decision whatsoever, as far as he knew, PHP ran anywhere, mySQL ran anywhere, the site was portable.

So here's a pro note: don't tie your websites to a particular platform unless you have to, and inform your client if you do, that "you will not be able to move this to Windows", or ".Net is, in practical terms, Windows technology. Your site will not be directly portable, if at all, to Unix/Linux".

Anyway, I responded, "that doesn't matter, Windows has symlinks".

He responded, and I have heard this from people at a particular startup I did some work for not long ago, who considered themselves superior to anybody that touched a Windows machine, "Windows doesn't have symlinks".

And like I said then:

YES IT DOES. THEY ARE CALLED NTFS JUNCTIONS.

So, either get the Windows Server Resource Kit to get the "linkd" tool, or just get the small, free Junction tool that's been around for a few years. If you have either of them though, it's a breeze.

With Junction (which is what I use), it's as easy as:

- Create an empty directory (your "symlink").
- junction c:\path\simlinkname c:\path\actualdirectory.

That's it. There's also commands to inspect directories for symlinks, delete them, and so on.

Note that, as far as I know, symlinks to directories on remote shares are not supported by Windows. This may not be true on the newer server versions, I dunno.

Here's a list to Junction (which I use now instead of moving around the whole Windows Server Resource Kit, which you can look up if you're so inclined):

http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

Happy Windows symlinking!