summaryrefslogtreecommitdiff
path: root/libarchive
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2024-01-19 18:45:31 +0100
committerTomas Bzatek <tbzatek@redhat.com>2024-01-19 18:45:31 +0100
commit22f9564566e5a6577be9bbd3e4297fb761d2e2d1 (patch)
treeb19ebcd2846bb48fa4674486812c4d02d757a29d /libarchive
parenta55d09bb2d74944b7ea5a7e81b7d3e86bc04cd42 (diff)
downloadtuxcmd-modules-22f9564566e5a6577be9bbd3e4297fb761d2e2d1.tar.xz
libarchive: Use the new common logging macros
Diffstat (limited to 'libarchive')
-rw-r--r--libarchive/Makefile5
-rw-r--r--libarchive/libarchive.c121
l---------libarchive/logutils.c1
l---------libarchive/logutils.h1
4 files changed, 65 insertions, 63 deletions
diff --git a/libarchive/Makefile b/libarchive/Makefile
index 373f166..9c7a144 100644
--- a/libarchive/Makefile
+++ b/libarchive/Makefile
@@ -8,11 +8,11 @@ CC = gcc
CFLAGS = -I. -I/usr/include \
-Wall -Wtype-limits -fPIC -O2 -g -ggdb \
-DG_DISABLE_DEPRECATED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE \
- -D__VERBOSE_DEBUGx
+ -D__DEBUG_INTERNALx -D_LOG_DOMAIN="libarchive"
LIB_SUFFIX = `if test \`uname -m\` = x86_64 -o \`uname -m\` = ppc64; then echo 64; fi`
-VFS_COMMON_OBJECTS = filelist.o filelist-vfs-intf.o strutils.o vfsutils.o
+VFS_COMMON_OBJECTS = filelist.o filelist-vfs-intf.o strutils.o vfsutils.o logutils.o
VFS_OBJECTS = libarchive.o
@@ -36,6 +36,7 @@ filelist.o: filelist.h filelist.c
filelist-vfs-intf.o: filelist-vfs-intf.h filelist-vfs-intf.c
strutils.o: strutils.h strutils.c
vfsutils.o: vfsutils.h vfsutils.c
+logutils.o: logutils.h logutils.c
install::
$(INSTALL) ./libarchive_plugin.so $(DESTDIR)/lib$(LIB_SUFFIX)/tuxcmd/
diff --git a/libarchive/libarchive.c b/libarchive/libarchive.c
index 26efa85..1e4f984 100644
--- a/libarchive/libarchive.c
+++ b/libarchive/libarchive.c
@@ -1,6 +1,6 @@
/* libarchive plugin for Tux Commander
- * version 0.3, designed for libarchive v3.6.1
- * Copyright (C) 2008-2023 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ * version 0.3.1, designed for libarchive v3.6.1
+ * Copyright (C) 2008-2024 Tomas Bzatek <tbzatek@users.sourceforge.net>
* Check for updates on tuxcmd.sourceforge.net
*
* Uses libarchive library
@@ -35,6 +35,7 @@
#include "tuxcmd-vfs.h"
#include "vfsutils.h"
#include "strutils.h"
+#include "logutils.h"
#include "filelist.h"
#include "filelist-vfs-intf.h"
@@ -46,8 +47,8 @@
#endif
-#define MODULE_VERSION "0.3"
-#define MODULE_BUILD_DATE "2023-12-17"
+#define MODULE_VERSION "0.3.1"
+#define MODULE_BUILD_DATE "2024-01-19"
#define DEFAULT_BLOCK_SIZE 65536
@@ -92,20 +93,12 @@ VFSNew (TVFSLogFunc log_func)
{
struct TVFSGlobs * globs;
+ log_init ();
+
globs = g_malloc0 (sizeof (struct TVFSGlobs));
globs->block_size = DEFAULT_BLOCK_SIZE;
-
- globs->callback_data = NULL;
- globs->callback_ask_question = NULL;
- globs->callback_ask_password = NULL;
- globs->callback_progress = NULL;
-
- globs->op_archive = NULL;
-
globs->log_func = log_func;
- if (globs->log_func != NULL)
- globs->log_func ("libarchive plugin: VFSInit");
return globs;
}
@@ -114,8 +107,10 @@ VFSNew (TVFSLogFunc log_func)
void
VFSFree (struct TVFSGlobs *globs)
{
- if (globs->log_func != NULL)
- globs->log_func ("libarchive plugin: VFSDestroy");
+ vfs_filelist_free (globs->vfs_filelist);
+ filelist_tree_free (globs->files);
+ g_free (globs->curr_dir);
+ g_free (globs->archive_path);
g_free (globs);
}
@@ -154,7 +149,7 @@ VFSGetInfo()
module_info->Name = g_strdup ("libarchive plugin");
module_info->About = g_strdup_printf ("version %s, build date: %s\nusing %s%s\n",
MODULE_VERSION, MODULE_BUILD_DATE, archive_version_string (), shared_module);
- module_info->Copyright = g_strdup ("Plugin Copyright (C) 2008-2023 Tomáš Bžatek\nlibarchive sources Copyright (c) 2003-2010 Tim Kientzle");
+ module_info->Copyright = g_strdup ("Plugin Copyright (C) 2008-2024 Tomáš Bžatek\nlibarchive sources Copyright (c) 2003-2010 Tim Kientzle");
return module_info;
}
@@ -280,12 +275,12 @@ VFSGetArchiveExts ()
archive_read_free (archive);
#ifdef MODULE_SHARED
- g_print ("(II) dynamically linked\n");
+ log_debug ("dynamically linked");
#else
- g_print ("(II) statically linked\n");
+ log_debug ("statically linked");
#endif
- g_print ("(II) VFSGetArchiveExts: supported archives = '%s'\n", formats);
+ log_debug ("VFSGetArchiveExts: supported archives = '%s'", formats);
return formats;
}
@@ -306,7 +301,7 @@ libarchive_open (struct archive **a, const char *filename, guint32 block_size, G
r = archive_read_open_filename (*a, filename, block_size);
if (r) {
- fprintf (stderr, "(EE) libarchive_open: error occured when opening archive: %s\n", archive_error_string (*a));
+ log_error ("libarchive_open: error occured when opening archive: %s", archive_error_string (*a));
g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (archive_errno (*a)), archive_error_string (*a));
return FALSE;
}
@@ -329,7 +324,7 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
globs->curr_dir = NULL;
globs->archive_path = g_strdup (sName);
globs->total_size = 0;
- fprintf (stderr, "(--) VFSOpenArchive: trying to open archive '%s'...\n", globs->archive_path);
+ log_notice ("VFSOpenArchive: Opening archive '%s'...", globs->archive_path);
res = libarchive_open (&a, globs->archive_path, globs->block_size, error);
if (res) {
@@ -341,18 +336,18 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
break;
} else
if (r == ARCHIVE_WARN) {
- log ("(WW) VFSOpenArchive: file '%s' - libarchive warning: '%s'\n", archive_entry_pathname (entry), archive_error_string (a));
+ log_warn ("VFSOpenArchive: file '%s' - libarchive warning: '%s'", archive_entry_pathname (entry), archive_error_string (a));
} else
if (r != ARCHIVE_OK) {
- fprintf (stderr, "(EE) VFSOpenArchive: error occured while reading archive: '%s'\n", archive_error_string (a));
+ log_error ("VFSOpenArchive: error occured while reading archive: '%s'", archive_error_string (a));
g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (archive_errno (a)), archive_error_string (a));
res = FALSE;
break;
}
- log ("found file: %s, mode = %x\n", archive_entry_pathname (entry), archive_entry_mode (entry));
+ log_debug ("found file: %s, mode = %x", archive_entry_pathname (entry), archive_entry_mode (entry));
if (archive_entry_pathname (entry) == NULL) {
- fprintf (stderr, "(WW) VFSOpenArchive: found entry with empty pathname, inode_no = %lu\n", inode_no);
+ log_warn ("VFSOpenArchive: found entry with empty pathname, inode_no = %lu", inode_no);
continue;
}
inode_no++;
@@ -424,15 +419,18 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
archive_read_close (a);
}
archive_read_free (a);
- fprintf (stderr, "(II) VFSOpenArchive: done. \n");
+ log_debug ("VFSOpenArchive: done.");
/* Resolve symlinks */
+#ifdef __DEBUG_INTERNAL
GTimer *timer = g_timer_new ();
+#endif
filelist_tree_resolve_symlinks (globs->files);
- g_print (" filelist_tree_resolve_symlinks: elapsed %d ms\n", (int) (g_timer_elapsed (timer, NULL) * 1000));
+#ifdef __DEBUG_INTERNAL
+ log_debug ("filelist_tree_resolve_symlinks: elapsed %d ms", (int) (g_timer_elapsed (timer, NULL) * 1000));
g_timer_destroy (timer);
+#endif
- printf ("\n\nList of items:\n");
filelist_tree_print (globs->files);
return res;
@@ -443,13 +441,15 @@ gboolean
VFSClose (struct TVFSGlobs *globs, GError **error)
{
if (globs) {
- fprintf (stderr, "(II) VFSClose: Freeing objects...\n");
- if (globs->vfs_filelist)
- vfs_filelist_free (globs->vfs_filelist);
- if (globs->files)
- filelist_tree_free (globs->files);
+ log_debug ("VFSClose: Freeing objects...");
+ vfs_filelist_free (globs->vfs_filelist);
+ globs->vfs_filelist = NULL;
+ filelist_tree_free (globs->files);
+ globs->files = NULL;
g_free (globs->archive_path);
+ globs->archive_path = NULL;
g_free (globs->curr_dir);
+ globs->curr_dir = NULL;
}
return TRUE;
}
@@ -502,7 +502,7 @@ VFSGetPasswordRequired (struct TVFSGlobs *globs)
struct TVFSItem *
VFSListFirst (struct TVFSGlobs *globs, const char *sDir, gboolean FollowSymlinks, gboolean AddFullPath, GError **error)
{
- printf ("(--) VFSListFirst: Going to list all items in '%s'\n", sDir);
+ log_debug ("VFSListFirst: Going to list all items in '%s'", sDir);
return vfs_filelist_list_first (globs->vfs_filelist, sDir, FollowSymlinks, AddFullPath, error);
}
@@ -525,7 +525,7 @@ VFSListClose (struct TVFSGlobs *globs, GError **error)
struct TVFSItem *
VFSFileInfo (struct TVFSGlobs *globs, const char *AFileName, gboolean FollowSymlinks, gboolean AddFullPath, GError **error)
{
- printf ("(--) VFSFileInfo: requested info for object '%s'\n", AFileName);
+ log_debug ("VFSFileInfo: requested info for object '%s'", AFileName);
return vfs_filelist_file_info (globs->vfs_filelist, AFileName, FollowSymlinks, AddFullPath, error);
}
@@ -547,7 +547,7 @@ VFSGetDirSize (struct TVFSGlobs *globs, const char *APath)
void
VFSBreakGetDirSize (struct TVFSGlobs *globs)
{
- printf ("(WW) VFSBreakGetDirSize: calling break\n");
+ log_debug ("VFSBreakGetDirSize: calling break");
if (globs)
vfs_filelist_get_dir_size_break (globs->vfs_filelist);
@@ -647,14 +647,14 @@ VFSSetBlockSize (struct TVFSGlobs *globs, guint32 Value)
gboolean
VFSIsOnSameFS (struct TVFSGlobs *globs, const char *Path1, const char *Path2, gboolean FollowSymlinks)
{
- printf ("(WW) VFSIsOnSameFS: Not supported in libarchive plugin.\n");
+ log_debug ("VFSIsOnSameFS: Not supported in libarchive plugin.");
return TRUE;
}
gboolean
VFSTwoSameFiles (struct TVFSGlobs *globs, const char *Path1, const char *Path2, gboolean FollowSymlinks)
{
- printf ("(WW) VFSTwoSameFiles: Not supported in libarchive, comparing by paths.\n");
+ log_debug ("VFSTwoSameFiles: Not supported in libarchive, comparing by paths.");
return compare_two_same_files (Path1, Path2);
}
@@ -682,8 +682,7 @@ my_archive_read_data_into_fd (struct TVFSGlobs *globs, struct archive *a, struct
gboolean cancel = FALSE;
int saved_errno;
-
- printf ("(II) my_archive_read_data_into_fd: extracting to '%s', Append = %d\n", sDstName, Append);
+ log_debug ("my_archive_read_data_into_fd: extracting to '%s', Append = %d", sDstName, Append);
if (Append)
fd = open (sDstName, O_APPEND | O_WRONLY);
@@ -692,7 +691,7 @@ my_archive_read_data_into_fd (struct TVFSGlobs *globs, struct archive *a, struct
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
saved_errno = errno;
- fprintf (stderr, "(EE) my_archive_read_data_into_fd: error occured while extracting data: %s\n", strerror (saved_errno));
+ log_error ("my_archive_read_data_into_fd: error occured while extracting data: %s", strerror (saved_errno));
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (saved_errno), "Error extracting data: %s", g_strerror (saved_errno));
return FALSE;
}
@@ -716,7 +715,7 @@ my_archive_read_data_into_fd (struct TVFSGlobs *globs, struct archive *a, struct
bytes_written = write (fd, p, bytes_to_write);
if (bytes_written < 0) {
saved_errno = errno;
- fprintf (stderr, "(EE) my_archive_read_data_into_fd: error occured while extracting data: %s\n", strerror (saved_errno));
+ log_error ("my_archive_read_data_into_fd: error occured while extracting data: %s", strerror (saved_errno));
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (saved_errno), "Error writing data: %s", g_strerror (saved_errno));
close (fd);
return FALSE;
@@ -726,7 +725,7 @@ my_archive_read_data_into_fd (struct TVFSGlobs *globs, struct archive *a, struct
p += bytes_written;
size -= bytes_written;
- log (" (II) my_archive_read_data_into_fd: bytes_written = %zd, total_written = %zd\n", bytes_written, total_written);
+ log_debug (" my_archive_read_data_into_fd: bytes_written = %zd, total_written = %zd", bytes_written, total_written);
if (globs->callback_progress)
if (! globs->callback_progress (total_written, NULL, globs->callback_data)) {
cancel = TRUE;
@@ -737,24 +736,24 @@ my_archive_read_data_into_fd (struct TVFSGlobs *globs, struct archive *a, struct
/* FIXME: shall we treat ARCHIVE_EOF as an error? */
if (r != ARCHIVE_OK && r != ARCHIVE_EOF) {
- fprintf (stderr, "(EE) my_archive_read_data_into_fd: error reading archive: %s\n", archive_error_string (a));
+ log_error ("my_archive_read_data_into_fd: error reading archive: %s", archive_error_string (a));
g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (archive_errno (a)), archive_error_string (a));
close (fd);
return FALSE;
}
if (close (fd)) {
saved_errno = errno;
- fprintf (stderr, "(EE) my_archive_read_data_into_fd: error closing extracted file: %s\n", strerror (errno));
+ log_error ("my_archive_read_data_into_fd: error closing extracted file: %m");
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (saved_errno), "Error closing extracted file: %s", g_strerror (saved_errno));
return FALSE;
}
if (cancel) {
if (unlink (sDstName))
- fprintf (stderr, "(EE) my_archive_read_data_into_fd: error unlinking cancelled extraction: %s\n", strerror (errno));
+ log_error ("my_archive_read_data_into_fd: error unlinking cancelled extraction: %m");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Operation has been cancelled.");
return FALSE;
}
- printf ("(II) my_archive_read_data_into_fd: done.\n");
+ log_debug ("my_archive_read_data_into_fd: done.");
return TRUE;
}
@@ -767,7 +766,7 @@ VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error)
return FALSE;
}
- printf ("(II) VFSStartCopyOperation: opening archive '%s'\n", globs->archive_path);
+ log_notice ("VFSStartCopyOperation: opening archive '%s'", globs->archive_path);
return libarchive_open (&globs->op_archive, globs->archive_path, globs->block_size, error);
}
@@ -781,7 +780,7 @@ VFSStopCopyOperation (struct TVFSGlobs *globs, GError **error)
return FALSE;
}
- printf ("(II) VFSStopCopyOperation: closing archive.\n");
+ log_notice ("VFSStopCopyOperation: closing the archive.");
archive_read_close (globs->op_archive);
archive_read_free (globs->op_archive);
@@ -807,26 +806,26 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
return FALSE;
}
if (sSrcName == NULL || sDstName == NULL || strlen (sSrcName) < 1 || strlen (sDstName) < 1) {
- printf ("(EE) VFSCopyToLocal: The value of 'sSrcName' or 'sDstName' is NULL or empty\n");
+ log_error ("VFSCopyToLocal: The value of 'sSrcName' or 'sDstName' is NULL or empty");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "The value of 'sSrcName' or 'sDstName' is NULL or empty.");
return FALSE;
}
- printf ("(II) VFSCopyToLocal: copying file '%s' out to '%s'\n", sSrcName, sDstName);
+ log_notice ("VFSCopyToLocal: copying file '%s' out to '%s'", sSrcName, sDstName);
node = filelist_tree_find_node_by_path (globs->files, sSrcName);
if (! node) {
- fprintf (stderr, "(EE) VFSCopyToLocal: cannot find file '%s'\n", sSrcName);
+ log_error ("VFSCopyToLocal: cannot find file '%s'", sSrcName);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "cannot find file '%s'", sSrcName);
return FALSE;
}
src = node->original_pathstr;
if (! src) {
- fprintf (stderr, "(WW) VFSCopyToLocal: cannot determine original filename\n");
+ log_warn ("VFSCopyToLocal: cannot determine original filename");
src = sSrcName;
}
- printf ("(II) VFSCopyToLocal: new src path: '%s'\n", src);
+ log_debug ("VFSCopyToLocal: new src path: '%s'", src);
found = FALSE;
@@ -839,10 +838,10 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
break;
} else
if (r == ARCHIVE_WARN) {
- log ("(WW) VFSCopyToLocal: file '%s' - libarchive warning: '%s'\n", archive_entry_pathname (entry), archive_error_string (globs->op_archive));
+ log_warn ("VFSCopyToLocal: file '%s' - libarchive warning: '%s'", archive_entry_pathname (entry), archive_error_string (globs->op_archive));
} else
if (r != ARCHIVE_OK) {
- fprintf (stderr, "(EE) VFSCopyToLocal: error occured while reading archive: '%s'\n", archive_error_string (globs->op_archive));
+ log_error ("VFSCopyToLocal: error occured while reading archive: '%s'", archive_error_string (globs->op_archive));
g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (archive_errno (globs->op_archive)), archive_error_string (globs->op_archive));
break;
}
@@ -855,13 +854,13 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
}
if (! found && res) {
- fprintf (stderr, "(EE) VFSCopyToLocal: file not found in archive.\n");
+ log_error ("VFSCopyToLocal: file not found in the archive.");
if (error && *error == NULL)
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "File not found in archive.");
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "File not found in the archive.");
res = FALSE;
}
- fprintf (stderr, "(II) VFSCopyToLocal: finished. \n");
+ log_debug ("VFSCopyToLocal: finished.");
return res;
}
@@ -869,7 +868,7 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
gboolean
VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append, GError **error)
{
- printf ("(WW) VFSCopyFromLocal: Not supported in libarchive plugin.\n");
+ log_debug ("VFSCopyFromLocal: Not supported in libarchive plugin.");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Not supported in libarchive plugin.");
return FALSE;
}
diff --git a/libarchive/logutils.c b/libarchive/logutils.c
new file mode 120000
index 0000000..c1e4fc5
--- /dev/null
+++ b/libarchive/logutils.c
@@ -0,0 +1 @@
+../common/logutils.c \ No newline at end of file
diff --git a/libarchive/logutils.h b/libarchive/logutils.h
new file mode 120000
index 0000000..ed79bd9
--- /dev/null
+++ b/libarchive/logutils.h
@@ -0,0 +1 @@
+../common/logutils.h \ No newline at end of file