[f-spot] Add fallback dupe detect to make transition less painful.



commit d7af3139e394d993df57f1fd2178969a011da617
Author: Ruben Vermeersch <ruben savanne be>
Date:   Fri Jun 11 15:41:48 2010 +0200

    Add fallback dupe detect to make transition less painful.
    
    Will do time + filename matching as a backup when there are photos with
    no original version hash. When a dupe is detected, a hash calculation is
    scheduled. This ensures that we will have hashes in there at some point.

 src/PhotoStore.cs |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
index 25ec594..7d248fc 100644
--- a/src/PhotoStore.cs
+++ b/src/PhotoStore.cs
@@ -22,6 +22,7 @@ using System.Text;
 using System;
 
 using FSpot;
+using FSpot.Jobs;
 using FSpot.Query;
 using FSpot.Utils;
 using FSpot.Platform;
@@ -106,6 +107,38 @@ public class PhotoStore : DbStore<Photo> {
 		if (dupes_by_hash > 0)
 			return true;
 
+		// This is a very lame check to overcome the lack of duplicate detect data right after transition.
+		//
+		// Does filename matching if there are files with no hash for the original version.
+		condition = new ConditionWrapper ("version_id = 1 AND (import_md5 = \"\" OR import_md5 IS NULL)");
+		var have_no_hashes = Count ("photo_versions", condition);
+		if (have_no_hashes > 0) {
+			var name = uri.GetFilename ();
+			DateTime? time = null;
+
+			// Look for a filename match.
+			var reader = Database.Query (new DbCommand ("SELECT photos.id, photos.time, pv.filename FROM photos LEFT JOIN photo_versions AS pv ON pv.photo_id = photos.id WHERE pv.filename = :filename", "filename", name));
+			while (reader.Read ()) {
+				Log.DebugFormat ("Found one possible duplicate for {0}", reader["filename"].ToString ());
+				if (!time.HasValue) {
+					// Only read time when needed
+					using (FSpot.ImageFile img = FSpot.ImageFile.Create (uri)) {
+						time = img.Date;
+					}
+				}
+
+				if (reader["time"].ToString () == DbUtils.UnixTimeFromDateTime (time.Value).ToString ()) {
+					Log.Debug ("Skipping duplicate", uri);
+					
+					// Schedule a hash calculation job on the existing file.
+					CalculateHashJob.Create (FSpot.App.Instance.Database.Jobs, Convert.ToUInt32 (reader["id"]));
+
+					return true;
+				}
+			}
+			reader.Close ();
+		}
+
 		return false;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]