diff --git a/ChangeLog b/ChangeLog index 6638dc6e1..c23766325 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-02-26 Lutz Müller + + * frontends/command-line/foreach.c (for_each_file_in_range): If + deleting files not recursively, adjust the image ID for subsequent + images. + * frontends/commane-line/main.c (main): If deleting files, do + it in reverse order such that above case does never occur. Fixes + #522796. + 2002-02-26 Lutz Müller * frontends/command-line/shell.c: Patch from Rob Hillis diff --git a/frontends/command-line/foreach.c b/frontends/command-line/foreach.c index b4c99675b..7f7d34b83 100644 --- a/frontends/command-line/foreach.c +++ b/frontends/command-line/foreach.c @@ -273,14 +273,27 @@ for_each_file_in_range (const char *folder, FileAction action, (unsigned int) i, ffolder, ffile)); CR (action (ffolder, ffile)); } - } else - for (i = 0; i <= max; i++) + } else { + unsigned int count; + + /* + * File deletion modifies the CameraFilesystem. Therefore + * the IDs of subsequent images change. This only affects us + * if not deleting reversely. This is the case here and we need + * to adjust the image IDs after a successful deletion. + */ + for (count = i = 0; i <= max; i++) if (index[i]) { - GP_DEBUG ("Now processing ID %i...", i); + GP_DEBUG ("Now processing ID %i " + "(originally %i)...", i - count, i); CR (get_path_for_id (folder, flags, - (unsigned int) i, ffolder, ffile)); + (unsigned int) i - count, + ffolder, ffile)); CR (action (ffolder, ffile)); + if (action == delete_file_action) + count++; } + } return (GP_OK); } diff --git a/frontends/command-line/main.c b/frontends/command-line/main.c index 0bcd382ac..99599b51d 100644 --- a/frontends/command-line/main.c +++ b/frontends/command-line/main.c @@ -978,7 +978,7 @@ OPTION_CALLBACK (delete_file) return (delete_file_action (glob_folder, arg)); return for_each_file_in_range (glob_folder, delete_file_action, - glob_flags, arg); + glob_flags, arg); } OPTION_CALLBACK (delete_all_files) @@ -1666,6 +1666,17 @@ e.g. SET IOLIBS=C:\\GPHOTO2\\IOLIB\n")); glob_flags &= ~FOR_EACH_FLAGS_RECURSE; } + /* + * If we delete single files, do it in the reverse order. It should + * work the other way, too, but one never knows... + */ + if ((option_is_present ("delete-file", argc, argv) == GP_OK) || + (option_is_present ("d", argc, argv) == GP_OK)) + glob_flags |= FOR_EACH_FLAGS_REVERSE; + else + glob_flags &= ~FOR_EACH_FLAGS_REVERSE; + + /* Now actually do something. */ result = execute_options (argc, argv); if (result < 0) { switch (result) {