This Time Self-Hosted
dark mode light mode Search

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]}'")
end

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!

Comments 2
  1. I recently did something similar for my Banshee collection which also uses sqlite 3. However, I did it by just using sqlite and running one update query. See the website link on this comment for my blog post.

  2. Ah thanks Michael! I tried figuring out the sqlite syntax, but it was quicker to use sqlite3-ruby than finding which one it really wanted to use, for me 😉

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.