diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-03-07 15:12:50 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-03-07 15:12:50 +0100 |
| commit | 895513e06150927cf5db6600ca164bdae15d4d75 (patch) | |
| tree | ff678c88754cfb6b966a463b04480665fdbf7504 /src/generators.c | |
| parent | aaeb9af232372ea8001fe9e71faf100f4fd34886 (diff) | |
| download | cataract-895513e06150927cf5db6600ca164bdae15d4d75.tar.xz | |
Support for extra (enclosed) files in albums [code]
Diffstat (limited to 'src/generators.c')
| -rw-r--r-- | src/generators.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/generators.c b/src/generators.c index b4bdf9c..e07a880 100644 --- a/src/generators.c +++ b/src/generators.c @@ -33,6 +33,8 @@ #include "generators-replace-table.h" +#define DEFAULT_DATA_DIR_MODE S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH + /* * generate_image: auxiliary function for write_html_album * - img_src and thumb should be freed afterwards @@ -890,6 +892,7 @@ build_tree (TGallerySetup *setup, char *imgname; gboolean res; int i; + char **extra; printf ("*** Entering directory '%s'\n", src_tree); #ifdef __DEBUG_ALL__ @@ -902,7 +905,7 @@ build_tree (TGallerySetup *setup, return FALSE; } if (access (dst_dir, R_OK | W_OK | X_OK)) { - if (g_mkdir_with_parents (dst_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (dst_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error creating destination directory: %s\n", strerror (errno)); return FALSE; } @@ -951,7 +954,7 @@ build_tree (TGallerySetup *setup, /* Prepare target thumbnail directory */ thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); if (access (thumb_dir, R_OK | W_OK | X_OK)) - if (g_mkdir_with_parents (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (thumb_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error making target thumbnail directory: %s\n", strerror (errno)); g_free (thumb_dir); free_album_data (items); @@ -966,12 +969,12 @@ build_tree (TGallerySetup *setup, img_big_dir = g_strconcat (dst_dir, "/", IMG_BIG_DIR, NULL); img_orig_dir = g_strconcat (dst_dir, "/", IMG_ORIG_DIR, NULL); if (access (img_big_dir, R_OK | W_OK | X_OK)) - if (g_mkdir_with_parents (img_big_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (img_big_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error making target preview directory: %s\n", strerror (errno)); res = FALSE; } if (access (img_orig_dir, R_OK | W_OK | X_OK)) - if (g_mkdir_with_parents (img_orig_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (img_orig_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error making target full size directory: %s\n", strerror (errno)); res = FALSE; } @@ -1058,6 +1061,36 @@ build_tree (TGallerySetup *setup, } } + /* Copy extra files */ + if (items->extra_files && g_strv_length (items->extra_files) > 0) { + extra = items->extra_files; + while (*extra) { + s1 = g_strstrip (*extra); + if (strlen (s1) > 0) { + /* First create target directory if it doesn't exist */ + s2 = g_strconcat (dst_dir, "/", s1, NULL); + s3 = g_path_get_dirname (s2); + g_free (s2); + if (g_mkdir_with_parents (s3, DEFAULT_DATA_DIR_MODE)) { + fprintf (stderr, "error making target extra directory '%s': %s\n", s3, strerror (errno)); + g_free (s3); + continue; + } + g_free (s3); + + /* Copy the file */ + if (setup->verbose) printf ("Copying extra file '%s' ...", s1); + s2 = g_strconcat (src_tree, "/", s1, NULL); + s3 = g_strconcat (dst_dir, "/", s1, NULL); + copy_file (s2, s3); + g_free (s2); + g_free (s3); + if (setup->verbose) printf (" done.\n"); + } + extra++; + } + } + printf ("*** Leaving directory '%s'\n", src_tree); free_album_data (items); |
