errno.h and Ubuntu 20.04
[geeqie.git] / src / misc.c
index 50a0a6b..c117b68 100644 (file)
@@ -22,8 +22,7 @@
 #include "misc.h"
 #include "ui_fileops.h"
 
-#include <archive.h>
-#include <archive_entry.h>
+#include <errno.h>
 #include <langinfo.h>
 #include <locale.h>
 
@@ -412,6 +411,17 @@ void tree_path_free_wrapper(void *data, void *useradata)
 
 /* Copied from the libarchive .repo. examples */
 
+#ifndef HAVE_ARCHIVE
+gchar *open_archive(FileData *fd)
+{
+       return NULL;
+}
+
+#else
+
+#include <archive.h>
+#include <archive_entry.h>
+
 static void errmsg(const char *);
 static gboolean extract(const char *filename, int do_extract, int flags);
 static int copy_data(struct archive *, struct archive *);
@@ -424,18 +434,38 @@ gchar *open_archive(FileData *fd)
        gchar *current_dir;
        gchar *destination_dir;
        gboolean success;
+       gint error;
 
        destination_dir = g_build_filename(g_get_tmp_dir(), GQ_ARCHIVE_DIR, instance_identifier, fd->path, NULL);
 
-       recursive_mkdir_if_not_exists(destination_dir, 0755);
+       if (!recursive_mkdir_if_not_exists(destination_dir, 0755))
+               {
+               log_printf("%s%s%s", _("Open Archive - Cannot create directory: "), destination_dir, "\n");
+               g_free(destination_dir);
+               return NULL;
+               }
 
        current_dir = g_get_current_dir();
-       chdir(destination_dir);
+       error = chdir(destination_dir);
+       if (error)
+               {
+               log_printf("%s%s%s%s%s", _("Open Archive - Cannot change directory to: "), destination_dir, _("\n  Error code: "), strerror(errno), "\n");
+               g_free(destination_dir);
+               g_free(current_dir);
+               return NULL;
+               }
 
        flags = ARCHIVE_EXTRACT_TIME;
        success = extract(fd->path, 1, flags);
 
-       chdir(current_dir);
+       error = chdir(current_dir);
+       if (error)
+               {
+               log_printf("%s%s%s%s%s", _("Open Archive - Cannot change directory to: "), current_dir, _("\n  Error code: "), strerror(errno), "\n");
+               g_free(destination_dir);
+               g_free(current_dir);
+               return NULL;
+               }
        g_free(current_dir);
 
        if (!success)
@@ -526,8 +556,7 @@ static gboolean extract(const char *filename, int do_extract, int flags)
        return(TRUE);
 }
 
-static int
-copy_data(struct archive *ar, struct archive *aw)
+static int copy_data(struct archive *ar, struct archive *aw)
 {
        int r;
        const void *buff;
@@ -555,7 +584,7 @@ copy_data(struct archive *ar, struct archive *aw)
 
 static void msg(const char *m)
 {
-       log_printf("%s \n", m);
+       log_printf("Open Archive - libarchive error: %s \n", m);
 }
 
 static void errmsg(const char *m)
@@ -564,7 +593,7 @@ static void errmsg(const char *m)
                {
                m = "Error: No error description provided.\n";
                }
-       log_printf("%s \n", m);
+       log_printf("Open Archive - libarchive error: %s \n", m);
 }
-
+#endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */