Tip of the day: move your f-spot Photo collection

Since today I’m pretty busy, I have no time for a complete post, but rather will give you a tip, if you’re using F-Spot and plan on moving your photos collection. Changing the location of the collection from the preferences not only won’t move your existing photos, but it won’t update the references in the DB either. This gets pretty bad if, like me, you’re forced to move the photo around between different filesystems (or in my case, disk entirely).

To solve that problem, I wrote this little Ruby script using sqlite3-ruby, that takes care of all that’s needed to move the photos:

#!/usr/bin/env ruby

require 'sqlite3'

db = SQLite3::Database.new(ARGV[0])

db.execute("SELECT DISTINCT base_uri FROM photos") do |row|
  newuri = row[0].gsub(ARGV[1], ARGV[2])
  db.execute("UPDATE photos SET base_uri = '#{newuri}' WHERE base_uri = '#{row[0]}'")
  db.execute("UPDATE photo_versions SET base_uri = '#{newuri}' WHERE base_uri = '#{row[0]}'")

It takes three parameters: the path to the SQLite database for F-Spot (generally ~/.config/f-spot/photos.db), the old path and the new path. Since the substitution is applied as-is, you need to use two slashes to make sure to start from the real root directory (like //media/photos).

Oh and for the Gentoo users reading this, what I wanted to write about was already written by Robin with better examples that I might have done. Kudos to Robin, and long live for the “old” networking scripts!