diff options
Diffstat (limited to 'src/job-manager.c')
| -rw-r--r-- | src/job-manager.c | 96 |
1 files changed, 60 insertions, 36 deletions
diff --git a/src/job-manager.c b/src/job-manager.c index 8344e60..1f37595 100644 --- a/src/job-manager.c +++ b/src/job-manager.c @@ -41,6 +41,7 @@ typedef struct { TGallerySetup *setup; TAlbum *items; const char *dst_dir; + gboolean force_update; } TJob; @@ -51,10 +52,10 @@ mirror_files (TGallerySetup *setup, char **files, const char *src_tree, const ch { char **extra; char *s1, *s2, *s3; + int processed = 0; if (files && g_strv_length (files) > 0) { extra = files; - if (setup->verbose) printf ("%s", label); while (*extra) { s1 = g_strstrip (*extra); if (strlen (s1) > 0) { @@ -70,16 +71,24 @@ mirror_files (TGallerySetup *setup, char **files, const char *src_tree, const ch g_free (s3); /* Copy the file */ - if (setup->verbose) printf (" %s", s1); s2 = g_strconcat (src_tree, "/", s1, NULL); s3 = g_strconcat (dst_dir, "/", s1, NULL); - copy_file (s2, s3); + if (! setup->update_mode || needs_update (s2, s3)) { + if (setup->verbose) { + if (processed == 0) + printf ("%s", label); + printf (" %s", s1); + } + copy_file (s2, s3); + processed++; + } g_free (s2); g_free (s3); } extra++; } - if (setup->verbose) printf ("\n"); + if (setup->verbose && processed > 0) + printf ("\n"); } } @@ -99,6 +108,7 @@ thread_func (gpointer data) char *s1, *s2, *s3; int total, index, real_index; TJob *job = data; + gboolean updated; do { item = NULL; @@ -129,13 +139,16 @@ thread_func (gpointer data) /* actually do some work */ if (item != NULL) { imgname = g_path_get_basename ((item->path == NULL && item->preview) ? item->preview : item->path); - G_LOCK (items_print); - if (job->setup->verbose) - g_print (" [%d/%d] Processing item \"%s\"\n", index, total, imgname); - G_UNLOCK (items_print); + updated = generate_image (job->setup, job->items, item, real_index, job->dst_dir, ! job->force_update); + + if (updated) { + G_LOCK (items_print); + if (job->setup->verbose) + g_print (" [%d/%d] Processing item \"%s\"\n", index, total, imgname); + G_UNLOCK (items_print); + } - generate_image (job->setup, job->items, item, real_index, job->dst_dir); - if (job->items->type == GALLERY_TYPE_ALBUM) { + if (updated && job->items->type == GALLERY_TYPE_ALBUM) { s1 = g_strconcat (job->setup->real_templates_dir, "/", job->setup->template_photo, NULL); s2 = g_strconcat (job->items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL); s3 = g_strconcat (job->dst_dir, "/", imgname, GET_EXT (job->setup->index_file_name), NULL); @@ -181,12 +194,14 @@ build_tree (TGallerySetup *setup, char *img_big_dir; char *img_orig_dir; char *template; + char *dst_album_file; gboolean res; int i; TJob *job; GError *error; GThread *thread; GList *thread_list; + gboolean force_update; printf ("Processing directory \"%s\"\n", src_tree); stats_dirs_inc (); @@ -223,10 +238,14 @@ build_tree (TGallerySetup *setup, free_album_data (items); return FALSE; } - g_free (idx_file); items->parent_index = parent_index; items->parent_item_index = parent_item_index; + /* Check if update is necessary */ + dst_album_file = g_strconcat (dst_dir, "/", setup->index_file_name, NULL); + force_update = (! setup->update_mode || needs_update (idx_file, dst_album_file)); + g_free (idx_file); + /* Copy support files */ if (! setup->support_files_use_common_root || parent_index == NULL) { /* copy only if we're in root level or old-style is active */ @@ -234,11 +253,13 @@ build_tree (TGallerySetup *setup, /* favicon */ if (setup->favicon_file && strlen (setup->favicon_file) > 0) { - if (setup->verbose) printf (" Copying favicon: %s\n", setup->favicon_file); s3 = g_path_get_dirname (setup->setup_xml_path); s1 = g_strconcat (s3, "/", setup->favicon_file, NULL); s2 = g_strconcat (dst_dir, "/", setup->favicon_file, NULL); - copy_file (s1, s2); + if (! setup->update_mode || needs_update (s1, s2)) { + if (setup->verbose) printf (" Copying favicon: %s\n", setup->favicon_file); + copy_file (s1, s2); + } g_free (s1); g_free (s2); g_free (s3); @@ -251,6 +272,7 @@ build_tree (TGallerySetup *setup, if (g_mkdir_with_parents (thumb_dir, DEFAULT_DATA_DIR_MODE)) { log_error ("error making target thumbnail directory: %s\n", strerror (errno)); g_free (thumb_dir); + g_free (dst_album_file); free_album_data (items); return FALSE; } @@ -275,6 +297,7 @@ build_tree (TGallerySetup *setup, g_free (img_big_dir); g_free (img_orig_dir); if (! res) { + g_free (dst_album_file); free_album_data (items); return FALSE; } @@ -285,6 +308,7 @@ build_tree (TGallerySetup *setup, job->items = items; job->setup = setup; job->dst_dir = dst_dir; + job->force_update = force_update; #ifdef G_THREADS_ENABLED thread_list = NULL; @@ -315,33 +339,33 @@ build_tree (TGallerySetup *setup, g_free (job); - /* Start generating items */ - if (items->type == GALLERY_TYPE_INDEX) - template = g_strconcat ("/", setup->template_index, NULL); - else - if (items->type == GALLERY_TYPE_ALBUM) - template = g_strconcat ("/", setup->template_album, NULL); - else - /* default to album */ - template = g_strconcat ("/", setup->template_album, NULL); - - if (setup->verbose) printf (" Writing %s\n", setup->index_file_name); - s1 = g_strconcat (setup->real_templates_dir, template, NULL); - s2 = g_strconcat (dst_dir, "/", setup->index_file_name, NULL); - res = write_html_album (setup, s1, s2, items); - g_free (s1); - g_free (s2); - g_free (template); - if (! res) { - log_error ("error generating target index file\n"); - free_album_data (items); - return FALSE; + /* Generate album page */ + if (force_update) { + if (items->type == GALLERY_TYPE_INDEX) + template = g_strconcat ("/", setup->template_index, NULL); + else + if (items->type == GALLERY_TYPE_ALBUM) + template = g_strconcat ("/", setup->template_album, NULL); + else + /* default to album */ + template = g_strconcat ("/", setup->template_album, NULL); + + if (setup->verbose) printf (" Writing %s\n", setup->index_file_name); + s1 = g_strconcat (setup->real_templates_dir, template, NULL); + res = write_html_album (setup, s1, dst_album_file, items); + g_free (s1); + g_free (template); + if (! res) { + log_error ("error generating target index file\n"); + free_album_data (items); + return FALSE; + } } + g_free (dst_album_file); /* Recurse to sub-albums (in case of album index) */ - if (items->type == GALLERY_TYPE_INDEX) - { + if (items->type == GALLERY_TYPE_INDEX) { if (items->items->len > 0) { for (i = 0; i < items->items->len; i++) { item = g_ptr_array_index (items->items, i); |
