From 01072f4baa7ae333e796800d8a17aa157fe08a4e Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 29 Nov 2009 16:35:02 +0100 Subject: Introduce copy operation start/stop calls --- libarchive/libarchive.c | 94 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 29 deletions(-) (limited to 'libarchive') diff --git a/libarchive/libarchive.c b/libarchive/libarchive.c index 535d565..4337bb1 100644 --- a/libarchive/libarchive.c +++ b/libarchive/libarchive.c @@ -1,5 +1,5 @@ /* libarchive plugin for Tux Commander - * version 0.2.0, designed for libarchive v2.5.5 - v2.7.1 (recommended) + * version 0.2.1, designed for libarchive v2.5.5 - v2.7.1 (recommended) * Copyright (C) 2008-2009 Tomas Bzatek * Check for updates on tuxcmd.sourceforge.net * @@ -52,8 +52,8 @@ #endif -#define MODULE_VERSION "0.2.0" -#define MODULE_BUILD_DATE "2009-11-26" +#define MODULE_VERSION "0.2.1" +#define MODULE_BUILD_DATE "2009-11-29" #define DEFAULT_BLOCK_SIZE 65536 @@ -81,6 +81,9 @@ struct TVFSGlobs { TVFSAskPasswordCallback callback_ask_password; TVFSProgressCallback callback_progress; void *callback_data; + + /* copy operation private */ + struct archive *op_archive; }; @@ -104,6 +107,8 @@ VFSNew (TVFSLogFunc log_func) 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"); @@ -639,8 +644,8 @@ my_archive_read_data_into_fd (struct TVFSGlobs *globs, struct archive *a, struct if (Append) fd = open (sDstName, O_APPEND | O_WRONLY); else - fd = open(sDstName, O_CREAT | O_WRONLY | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + fd = open (sDstName, O_CREAT | O_WRONLY | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { fprintf (stderr, "(EE) my_archive_read_data_into_fd: error occured while extracting data: %s\n", strerror (errno)); return cVFS_Failed; @@ -695,17 +700,51 @@ my_archive_read_data_into_fd (struct TVFSGlobs *globs, struct archive *a, struct } +TVFSResult +VFSStartCopyOperation (struct TVFSGlobs *globs) +{ + TVFSResult Result; + + g_return_val_if_fail (globs != NULL, cVFS_Failed); + g_return_val_if_fail (globs->op_archive == NULL, cVFS_Failed); + + printf ("(II) VFSStartCopyOperation: opening archive '%s'\n", globs->archive_path); + + Result = libarchive_open (&globs->op_archive, globs->archive_path, globs->block_size); + + return Result; +} + + +TVFSResult +VFSStopCopyOperation (struct TVFSGlobs *globs) +{ + g_return_val_if_fail (globs != NULL, cVFS_Failed); + g_return_val_if_fail (globs->op_archive != NULL, cVFS_Failed); + + printf ("(II) VFSStopCopyOperation: closing archive.\n"); + + archive_read_close (globs->op_archive); + archive_read_finish (globs->op_archive); + globs->op_archive = NULL; + + return cVFS_OK; +} + + TVFSResult VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append) { struct PathTree *node; const char *src; TVFSResult Result; - struct archive *a; struct archive_entry *entry; int r; gboolean found; + + g_return_val_if_fail (globs->op_archive != NULL, cVFS_ReadErr); + 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"); return cVFS_Failed; @@ -728,32 +767,29 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN found = FALSE; - Result = libarchive_open (&a, globs->archive_path, globs->block_size); - if (Result == cVFS_OK) { - for (;;) { - entry = NULL; - r = archive_read_next_header (a, &entry); - if (r == ARCHIVE_EOF) { - break; - } else - if (r == ARCHIVE_WARN) { - log("(WW) VFSOpen: file '%s' - libarchive warning: '%s'\n", archive_entry_pathname (entry), archive_error_string (a)); - } else - if (r != ARCHIVE_OK) { - fprintf (stderr, "(EE) VFSCopyToLocal: error occured while reading archive: '%s'\n", archive_error_string (a)); - Result = cVFS_Failed; - break; - } + Result = cVFS_ReadErr; + + for (;;) { + entry = NULL; + r = archive_read_next_header (globs->op_archive, &entry); + if (r == ARCHIVE_EOF) { + 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)); + } else + if (r != ARCHIVE_OK) { + fprintf (stderr, "(EE) VFSCopyToLocal: error occured while reading archive: '%s'\n", archive_error_string (globs->op_archive)); + Result = cVFS_Failed; + break; + } - if (g_strcmp0 (src, archive_entry_pathname (entry)) == 0) { - found = TRUE; - Result = my_archive_read_data_into_fd (globs, a, entry, sDstName, globs->block_size, Append); - break; - } + if (g_strcmp0 (src, archive_entry_pathname (entry)) == 0) { + found = TRUE; + Result = my_archive_read_data_into_fd (globs, globs->op_archive, entry, sDstName, globs->block_size, Append); + break; } - archive_read_close (a); } - archive_read_finish (a); if (! found && Result == cVFS_OK) { fprintf (stderr, "(EE) VFSCopyToLocal: file not found in archive.\n"); -- cgit v1.2.3