Saturday, January 02, 2010

Little Lessons

It seems like I always learn something new on any given project that I get involved in. I generally view that as a positive thing since, if I stop learning, it means I’ve started to stagnate.

A couple of weeks ago, I decided I should finally get around to writing the backup program that I’d been considering for a while. Nothing fancy, essentially just a series of system calls to xcopy and svnadmin with error checking and logging in order to backup my email, files, and subversion repositories.

I could have hard coded the commands, but that wouldn’t be any fun. Besides which, it would make it more difficult to fix if the drive lettering changed (say, if I changed computers).

Hey, I at least try to make things easy to maintain even if it takes a little longer than a totally quick and dirty solution. =]

No, I’m not going to post it on the site. There’s really no reason to because it’s a basically nothing program and I only wrote it to save me time. Now all I have to do to perform a backup is double click the shortcut to the ruby program, walk away for 30 minutes, and then burn the results to dvd after checking the log to make sure everything passed.

The interesting part of the project was the thing that I learned.

Most of the calls to xcopy went off without a hitch. Then I ran into one that I just *couldn’t* get to work. I beat my head against the problem for the better part of a day, but made absolutely no progress. The only difference between the calls that worked and the one call that didn’t was that the non-working call had a space in the path.

Xcopy “Drive1:\path_without_spaces\” “Drive2:\path_without_spaces\” /E
Worked perfectly fine, but
Xcopy “Drive1:\path with spaces\” “Drive2:\path with spaces\” /E
Would choke every time.

I tweaked my code, endlessly trying different things that might help. I checked to see if there was anything weird with system(). I even looked on google to see if I could find an answer.

I had no luck whatsoever. Even discussions on xcopy itself were no help.

After beating my head against the problem endlessly, I finally thought of something so incredibly stupid that it couldn’t possibly work – take the trailing "\" off of the paths with spaces.

It worked. It’s stupid, and it shouldn’t have caused a problem, but it did. Apparently xcopy doesn’t like paths with spaces that end in a “\” while it has no problem with a trailing “\” at the end of a path that doesn’t contain spaces.

Who knew?

It was a small lesson. Heck, it was even a *stupid* lesson, but I *did* learn something, and it was something that I hadn’t seen listed as an issue online.

I can’t have been the only one to have run into this problem, but apparently if anyone else had it, they didn’t see fit to post a note on the subject.

Current mood: tired
Current music: none