After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 329841 - Month/Day directory without leading 0 (1-31 instead of 01-31)
Month/Day directory without leading 0 (1-31 instead of 01-31)
Status: RESOLVED FIXED
Product: f-spot
Classification: Other
Component: General
CVS
Other All
: Normal trivial
: ---
Assigned To: F-spot maintainers
F-spot maintainers
: 369201 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-02-03 23:04 UTC by Bengt Thuree
Modified: 2007-01-09 13:26 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch against CVS 060204 (823 bytes, patch)
2006-02-04 00:10 UTC, Bengt Thuree
needs-work Details | Review
Patch agains CVS (16.57 KB, patch)
2006-02-15 23:36 UTC, Bengt Thuree
none Details | Review
Patch that handles deleted pictures (16.67 KB, patch)
2006-03-06 10:41 UTC, Bengt Thuree
none Details | Review
2 liner patch for new imports (2.11 KB, patch)
2006-09-22 11:33 UTC, Bengt Thuree
reviewed Details | Review
One-line patch to zero-pad month and day. (732 bytes, patch)
2006-11-02 14:52 UTC, Bradford Powell
committed Details | Review

Description Bengt Thuree 2006-02-03 23:04:51 UTC
Please describe the problem:

F-Spot stores all photos in ~/Photos/YYYY/MM/day/Photo
Where 
YYYY = 2006
MM = 01 - 12
Day = 1 - 31

This causes the day directory to not be in a sorted order when you do a ls in
the directory.

bengt@jolly:~/Photos/2005/3$ ls
1  11  12  13  14  15  19  2  20  4  5

Steps to reproduce:
1. Import Photos
2. 
3. 


Actual results:
Day directory is created as 1 - 31
1
2
..
31

Expected results:
The day directory should be created like 01 - 31
01
02
..
31

Does this happen every time?
Yes

Other information:
Comment 1 Bengt Thuree 2006-02-04 00:10:46 UTC
Created attachment 58678 [details] [review]
Patch against CVS 060204

+// time.Month,
+// time.Day);
+   time.ToString("MM"),   // To get months with leading 0 as in 01 - 12
+   time.ToString("dd"));  // To get days with leading 0 as in 01 - 31

bengt@jolly:~/Photos$ ls */*/
2005/02/:
27

2005/03/:
01  02  03  04  05  07  08  11  12  13  14  15  19  20

2006/01/:
15  17
Comment 2 Bengt Thuree 2006-02-04 00:12:44 UTC
I also found that by default the month is created as 1 - 12, which is the same problem as for the days. My above patch fixes both day and month.
Comment 3 Gabriel Burt 2006-02-09 02:33:56 UTC
The only problem with this patch is that if the user imports new photos from the same month/day as they already have, then there will be both a 1 and a 01 for instance.  So really the fix is more complicated - we need to move the old directories and update that in the database.
Comment 4 Bengt Thuree 2006-02-15 23:36:46 UTC
Created attachment 59440 [details] [review]
Patch agains CVS

2 lines changed for the actual import fix, and 311 lines or so to update existing data.


try
        1) Create Directory
        2) hard link photo
        3) update database
        4) move thumbnails
catch
        revert thumbnails
        remove new hard link
        remove new directory

remove old hard link
remove old directories

Would appreciate some comments if anyone have any.
Especially would appreciate if someone using a BSD system could verify this one.

Do bear in mind that please test this on a test system, not on your live
data. Also, just after 4 (in the above pseudo code) you can uncomment a
raise exception so no changes will be made... Also uncomment the Readln comment, so you can check the file structure.
Comment 5 Bengt Thuree 2006-02-16 02:18:44 UTC
Forgot one small line in my pseudo code ;)
after remove new directory... we raise the Exception again, so the database will be rolled back.

But do not handle a power off though. 
Comment 6 Bengt Thuree 2006-03-04 23:57:31 UTC
Comment from Ruben

Patch probably do not cope with deleted pictures (a photo id, with missing photo!) Anyway, I missed testing this test case.

Awkward with to many if statements, might be better using continue instead.

Also, 
- throw new Exception (String.Format("Photo with name {0} do not
exists", old_photo));
+ throw new Exception (String.Format("Photo with name {0} does not
exist", old_photo));
Comment 7 Bengt Thuree 2006-03-06 10:41:13 UTC
Created attachment 60749 [details] [review]
Patch that handles deleted pictures

I modified the patch to handle deleted pictures.
In short
- if (orig_directory.StartsWith (FSpot.Global.PhotoDirectory)) {
+ if ((orig_directory != null) && (orig_directory.StartsWith (FSpot.Global.PhotoDirectory))) {

I have not changed from If/Then to use "continue" though. If that is a request I will look into it, or perhaps someone else could do that. I thought the code is nicely commented and easy to follow, but then again, I am biased :)
Comment 8 Bengt Thuree 2006-04-20 06:14:31 UTC
Related comment in bug #339078
---- Anders Bo Rasmussen
I don't think we should change existing filenames. Users might have other
applications that remember the filenames and this will break if names of
existing files change.
----
Comment 9 Bengt Thuree 2006-05-15 15:37:59 UTC
Been long time with no comments on this one.
Is there a problem with getting this one into CVS or?

If problem with the update function, just skip the update and let all new photos get the new filename.
Comment 10 Bengt Thuree 2006-08-14 09:50:14 UTC
Do we really need to update the existing directory structure?

If so, should it really be done by using update?
I mean, 300+ lines of code for this... Ok, not the best code perhaps but still.
Comment 11 Bengt Thuree 2006-09-22 11:33:33 UTC
Created attachment 73205 [details] [review]
2 liner patch for new imports

This patch is an updated patch that applies cleanly against CVS.
It only handles new imports, which means any old directory names are left as they are.
So, you might have a 2006/9/1 and a 2006/09/01 directory after this patch.

The update patch to ensure all old directory names were renamed is much more complicated, and perhaps not worth the effort.
Comment 12 Stephane Delcroix 2006-09-22 11:50:36 UTC
I'm voting in favor of the 2-lines patch.

Supporting and maintaining a 300+ LOC updater for only one use is probably too much efforts.
Comment 13 Bengt Thuree 2006-11-02 03:51:35 UTC
*** Bug 369201 has been marked as a duplicate of this bug. ***
Comment 14 Bengt Thuree 2006-11-02 03:52:21 UTC
Another version of a patch in bug #369201
Comment 15 Bradford Powell 2006-11-02 14:52:20 UTC
Created attachment 75846 [details] [review]
One-line patch to zero-pad month and day.

This has the same function as Bengt's two-line patch, but does so by only adding 6 characters (using String.Format). It does not change the location of existing files-- it only affects where newly imported files will go. Brought here from bug #369201
Comment 16 Stephane Delcroix 2007-01-09 13:26:00 UTC
fixed in r2680 (at last)