summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2016-03-27 18:32:33 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2016-04-03 17:29:44 +0200
commit2d4a2fc03859065291fcb05d8df29ba8f50ab6e3 (patch)
treef296db6c380d8f9c0ea89ea03ad2cc5828585e88 /src
parent415fa18ad93493b7073a69cda3af27863537185b (diff)
downloadcataract-2d4a2fc03859065291fcb05d8df29ba8f50ab6e3.tar.xz
gallery-utils: Copy extra files recursively
This brings support for copying whole directories when specified in album extra files or template supplemental files.
Diffstat (limited to 'src')
-rw-r--r--src/gallery-utils.c35
-rw-r--r--src/gallery-utils.h8
-rw-r--r--src/job-manager.c3
3 files changed, 44 insertions, 2 deletions
diff --git a/src/gallery-utils.c b/src/gallery-utils.c
index 3caff02..d97cef3 100644
--- a/src/gallery-utils.c
+++ b/src/gallery-utils.c
@@ -154,6 +154,41 @@ copy_file (const gchar *src, const gchar *dst)
return TRUE;
}
+/*
+ * copy_file_dir: recursively copy file or directory from src to dst
+ */
+gboolean
+copy_file_dir (const gchar *src, const gchar *dst)
+{
+ int n;
+ struct dirent **namelist;
+ char *new_src, *new_dst;
+
+ if (g_file_test (src, G_FILE_TEST_IS_DIR)) {
+ if (g_mkdir_with_parents (dst, DEFAULT_DATA_DIR_MODE)) {
+ log_error ("error making target directory '%s': %s\n", dst, strerror (errno));
+ return FALSE;
+ }
+ n = scandir (src, &namelist, NULL, NULL);
+ if (n < 0) {
+ log_error ("error listing source directory '%s': %s\n", src, strerror (errno));
+ return FALSE;
+ }
+ while (n--) {
+ if (g_strcmp0 (".", namelist[n]->d_name) != 0 && g_strcmp0 ("..", namelist[n]->d_name) != 0) {
+ new_src = g_build_filename (src, namelist[n]->d_name, NULL);
+ new_dst = g_build_filename (dst, namelist[n]->d_name, NULL);
+ copy_file_dir (new_src, new_dst);
+ g_free (new_src);
+ g_free (new_dst);
+ }
+ free (namelist[n]);
+ }
+ free (namelist);
+ return TRUE;
+ } else return copy_file (src, dst);
+}
+
/*
* make_string: make string of 'substr' substrings
diff --git a/src/gallery-utils.h b/src/gallery-utils.h
index 4559fa4..1af8b84 100644
--- a/src/gallery-utils.h
+++ b/src/gallery-utils.h
@@ -27,6 +27,9 @@ G_BEGIN_DECLS
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '~')
#define IS_EQUAL_SIGN(ch) ((ch) == '=')
+#define DEFAULT_DATA_DIR_MODE S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
+
+
/*
* str_replace: replace substring 'search' with a 'replace' string
* - multiple occurences of the string are replaced
@@ -40,6 +43,11 @@ void str_replace (gchar **dst, const gchar *search, const gchar *replace);
gboolean copy_file (const gchar *src, const gchar *dst);
/*
+ * copy_file_dir: recursively copy file or directory from src to dst
+ */
+gboolean copy_file_dir (const gchar *src, const gchar *dst);
+
+/*
* make_string: make string of 'substr' substrings
* - returns newly allocated string
*/
diff --git a/src/job-manager.c b/src/job-manager.c
index 28e81ff..9dcb3cd 100644
--- a/src/job-manager.c
+++ b/src/job-manager.c
@@ -34,7 +34,6 @@
-#define DEFAULT_DATA_DIR_MODE S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
#define AUTH_PASSWD_FILE ".htpasswd"
@@ -87,7 +86,7 @@ mirror_files (TGallerySetup *setup, gchar **files, const gchar *src_tree, const
printf ("%s", label);
printf (" %s", s1);
}
- copy_file (s2, s3);
+ copy_file_dir (s2, s3);
processed++;
}
g_free (s2);