Skip to content

Commit

Permalink
Cleanup Exif Date sorting patch.
Browse files Browse the repository at this point in the history
Fix a memleak, and move a part of the code from set_exif_time_data() to read_exif_time_data()
  • Loading branch information
Laurent Monin authored and zas committed Aug 16, 2012
1 parent 92c6523 commit 44b81fb
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions src/filedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolea
return ret;
}

void init_exif_time_data(GList *files) {
void init_exif_time_data(GList *files)
{
FileData *file;
DEBUG_1("%s init_exif_time_data: ...", get_exec_time());
while (files)
Expand All @@ -424,47 +425,52 @@ void init_exif_time_data(GList *files) {
}
}

void set_exif_time_data(GList *files) {
gchar *tmp;
uint year, month, day, hour, min, sec;
struct tm time_str;
FileData *file;
DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
while (files)
void read_exif_time_data(FileData *file)
{
if (file->exifdate > 0)
{
file = files->data;

if (file->exifdate > 0)
{
files = files->next;
DEBUG_1("%s set_exif_time_data: Already exists for %s", get_exec_time(), file->path);
continue;
}

DEBUG_1("%s set_exif_time_data: Getting exiftime for %s", get_exec_time(), file->path);
DEBUG_1("%s set_exif_time_data: Already exists for %s", get_exec_time(), file->path);
return;
}

file->exif = exif_read_fd(file);

file->exif = exif_read_fd(file);
if (file->exif)
{
gchar *tmp = exif_get_data_as_text(file->exif, "Exif.Photo.DateTimeOriginal");
DEBUG_2("%s set_exif_time_data: reading %p %s", get_exec_time(), file, file->path);

if (file->exif)
if (tmp)
{
tmp = exif_get_data_as_text(file->exif, "Exif.Photo.DateTimeOriginal");
if (tmp)
{
sscanf(tmp, "%4d:%2d:%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
time_str.tm_year = year - 1900;
time_str.tm_mon = month - 1;
time_str.tm_mday = day;
time_str.tm_hour = hour;
time_str.tm_min = min;
time_str.tm_sec = sec;
time_str.tm_isdst = 0;

file->exifdate = mktime(&time_str);
}
struct tm time_str;
uint year, month, day, hour, min, sec;

sscanf(tmp, "%4d:%2d:%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
time_str.tm_year = year - 1900;
time_str.tm_mon = month - 1;
time_str.tm_mday = day;
time_str.tm_hour = hour;
time_str.tm_min = min;
time_str.tm_sec = sec;
time_str.tm_isdst = 0;
file->exifdate = mktime(&time_str);
g_free(tmp);
}
files = files->next;
}
}

void set_exif_time_data(GList *files)
{
DEBUG_1("%s set_exif_time_data: ...", get_exec_time());

while (files)
{
FileData *file = files->data;

read_exif_time_data(file);
files = files->next;
}
}

FileData *file_data_new_no_grouping(const gchar *path_utf8)
Expand Down Expand Up @@ -1123,6 +1129,7 @@ static gboolean filelist_read_real(const gchar *dir_path, GList **files, GList *
g_free(pathl);

if (dirs) *dirs = dlist;

if (files)
{
g_hash_table_foreach(basename_hash, file_data_basename_hash_to_sidecars, NULL);
Expand Down

0 comments on commit 44b81fb

Please sign in to comment.