Previous Entry Share Next Entry
Getting rid of annoyances... the hard way
hack
siddhesh

Lately I have been tinkering around with code in shotwell, which is the photo manager I use to sort pictures I click. As a result I built an svn snapshot and set about making my changes. On firing up the freshly built app, I saw an "Updating libraries..." progress bar pulsing away for quite some time. it just would not go away. I didn't wait long enough for it and ended the app to modify my code further. I started the app again. The progress bar comes up again and does not leave.

This had been happening for a few days and I kept ignoring it because I was working on a different part of the code (porting shotwell to cairo). I finally decided to find out what was going on today and I started shotwell in debug mode, which is simply:

SHOTWELL_LOG=1 SHOTWELL_LOG_FILE=:console: ./shotwell

... and it struck me that I had been lazy the very first time and did not bother to set the default directory for shotwell to scan. Shotwell simply assumed it to be my home directory and that was it. Scanning my home directory obviously was taking very long since it has a little over 30GB of data. Anyway, I moved my photos to a different location but it turns out that shotwell cannot read them anymore despite pointing it to the new location. I will have to modify its database to update the file paths.

So the unique thing about shotwell is that it does not modify the photo files. It stores all edits into a database correlated with the file path. So all I had to do was to edit this database (which is $HOME/.shotwell/data/photos.db, an sqlite3 database) and change the file paths to the new location.

Now here's the big warning: NEVER do such changes when you're having a conversation with someone else or are distracted by anything else.

I ended up writing an incorrect query... and then cancelling it midway, thus leaving the database in a pretty messy state. So in the end the only reliable information I had was the name of the image files. I then hacked up a little script to correct this:

#!/bin/sh

# Set your photo path here
photopath=$HOME/photos

sqlite3 photo.db "select filename from PhotoTable" |
	while read file; do
		basename=$(basename "$file")
		fullname=$(find $photopath -name "$basename")

		if [ -n "$fullname" ]; then
			echo "Updating $fullname"
			sqlite3 photo.db "update PhotoTable set filename='$fullname' where filename='$file'"
		fi
	done

So those who want to move their shotwell photo databases to another location, here's one (fairly roundabout) way to do this. Enjoy!


?

Log in

No account? Create an account