about summary refs log tree commit diff stats
path: root/src/common.c
diff options
context:
space:
mode:
authorPhilip Flohr <philip.flohr@student.kit.edu>2018-05-07 19:41:47 +0200
committerDmitry Podgorny <pasis.ua@gmail.com>2018-09-06 19:28:02 +0300
commite4ddced4203235c8393369ba3f0a62de1f5e980e (patch)
treeb1f5f858206cbbcc0f8c408a621edb8cbf5fb78e /src/common.c
parent2795dc487cdcd9a4adf55799b36516bfd7725710 (diff)
downloadprofani-tty-e4ddced4203235c8393369ba3f0a62de1f5e980e.tar.gz
use gio functions for file copy
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/common.c b/src/common.c
index 164523a2..251eddc6 100644
--- a/src/common.c
+++ b/src/common.c
@@ -46,6 +46,7 @@
 #include <curl/curl.h>
 #include <curl/easy.h>
 #include <glib.h>
+#include <gio/gio.h>
 
 #ifdef HAVE_NCURSESW_NCURSES_H
 #include <ncursesw/ncurses.h>
@@ -105,28 +106,22 @@ mkdir_recursive(const char *dir)
 }
 
 gboolean
-copy_file(const char *const sourcepath, const char *const targetpath)
+copy_file(const char *const sourcepath, const char *const targetpath, const gboolean overwrite_existing)
 {
-    int ch;
-    FILE *source = fopen(sourcepath, "rb");
-    if (source == NULL) {
-        return FALSE;
-    }
-
-    FILE *target = fopen(targetpath, "wb");
-    if (target == NULL) {
-        fclose(source);
-        return FALSE;
-    }
-
-    while((ch = fgetc(source)) != EOF) {
-        fputc(ch, target);
+    GFile *source = g_file_new_for_path(sourcepath);
+    GFile *dest = g_file_new_for_path(targetpath);
+    GError *error = NULL;
+    gboolean success = false;
+    
+    if (overwrite_existing)
+    {
+        success = g_file_copy (source, dest, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error);
+    } 
+    else 
+    {
+        success = g_file_copy (source, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, &error);
     }
-
-    fclose(source);
-    fclose(target);
-
-    return TRUE;
+    return success;
 }
 
 char*