summaryrefslogtreecommitdiff
path: root/zip/zip.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zip/zip.cpp')
-rw-r--r--zip/zip.cpp819
1 files changed, 445 insertions, 374 deletions
diff --git a/zip/zip.cpp b/zip/zip.cpp
index 8998d8b..0432b6f 100644
--- a/zip/zip.cpp
+++ b/zip/zip.cpp
@@ -1,6 +1,6 @@
/* ZIP plugin for Tux Commander
- * version 0.5.6, designed for ZipArchive v3.2.0
- * Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ * version 0.6.0, designed for ZipArchive v3.2.0
+ * Copyright (C) 2004-2009 Tomas Bzatek <tbzatek@users.sourceforge.net>
* Check for updates on tuxcmd.sourceforge.net
*
* Uses ZipArchive library
@@ -35,11 +35,11 @@
#include <unistd.h>
#include <glib.h>
-#include "vfs_types.h"
+#include "tuxcmd-vfs.h"
#include "strutils.h"
#include "vfsutils.h"
-#include "treepathutils.h"
-#include "treepath_vfs.h"
+#include "filelist.h"
+#include "filelist-vfs-intf.h"
#include "ZipArchive.h"
#include "ZipPlatform.h"
@@ -47,8 +47,8 @@
-#define VERSION "0.5.6"
-#define BUILD_DATE "2009-10-25"
+#define VERSION "0.6.0"
+#define BUILD_DATE "2009-11-28"
#define DEFAULT_BLOCK_SIZE 65536
@@ -60,7 +60,8 @@ extern "C" {
/** Utilities */
/************** ****************/
-TVFSResult get_vfs_errorcode(int m_iCause)
+static TVFSResult
+get_vfs_errorcode (int m_iCause)
{
switch (m_iCause) {
case 13: return cVFS_WriteErr; // Permission denied
@@ -132,9 +133,9 @@ struct TVFSGlobs {
CZipArchive *zip;
CVFSZipActionCallback *extract_callback;
- bool archive_opened;
- unsigned long block_size;
- bool archive_modified;
+ gboolean archive_opened;
+ guint32 block_size;
+ gboolean archive_modified;
struct PathTree *files;
struct VfsFilelistData *vfs_filelist;
@@ -159,7 +160,7 @@ struct ZIP_API CVFSZipActionCallback : public CZipActionCallback
virtual bool Callback(ZIP_SIZE_TYPE uProgress)
{
- fprintf(stderr, "(II) Callback called, position = %lu; m_uTotalToProcess = %lu; m_uProcessed = %lu\n",
+ fprintf (stderr, "(II) Callback called, position = %lu; m_uTotalToProcess = %lu; m_uProcessed = %lu\n",
uProgress, m_uTotalToProcess, m_uProcessed);
bool ret = true;
try {
@@ -167,7 +168,7 @@ struct ZIP_API CVFSZipActionCallback : public CZipActionCallback
ret = globs->callback_progress (m_uProcessed, m_uTotalToProcess, globs->callback_data);
}
catch (...) {
- fprintf(stderr, "(EE) extract_callback: Fatal error occured when calling pCallBackProgress\n");
+ fprintf (stderr, "(EE) extract_callback: Fatal error occured when calling pCallBackProgress\n");
}
return ret;
}
@@ -180,60 +181,69 @@ struct ZIP_API CVFSZipActionCallback : public CZipActionCallback
* Internal tree functions
********/
-void build_global_filelist(struct TVFSGlobs *globs)
+static void
+build_global_filelist (struct TVFSGlobs *globs)
{
- int iCount = globs->zip->GetCount();
- // Ensure the filelist is freed
- if (globs->files) filelist_tree_free(globs->files);
+ int iCount;
+ int i;
+ CZipFileHeader *fh;
+ struct TVFSItem *item;
+ char *s;
+
+ /* Ensure the filelist is freed */
+ if (globs->vfs_filelist)
+ vfs_filelist_free (globs->vfs_filelist);
+ if (globs->files)
+ filelist_tree_free (globs->files);
globs->files = filelist_tree_new();
- vfs_filelist_set_files(globs->vfs_filelist, globs->files);
+ globs->vfs_filelist = vfs_filelist_new (globs->files);
- // list files in archive
- for (int i = 0; i < iCount; i++) {
- CZipFileHeader *fh = globs->zip->GetFileInfo(i);
+ iCount = globs->zip->GetCount();
+ /* list files in the archive */
+ for (i = 0; i < iCount; i++) {
+ fh = globs->zip->GetFileInfo (i);
if (fh != NULL)
printf(" No: %i, '%s', IsDir: %i, Size: %lu, SystemAttr = 0x%lX, OriginalAttr = 0x%lX, encrypted = %d\n",
i, (LPCTSTR)fh->GetFileName(), fh->IsDirectory(), fh->m_uUncomprSize, fh->GetSystemAttr(), fh->GetOriginalAttributes(), fh->IsEncrypted());
}
printf("\n\n");
- for (int i = 0; i < iCount; i++) {
- CZipFileHeader *fh = globs->zip->GetFileInfo(i);
+ for (i = 0; i < iCount; i++) {
+ fh = globs->zip->GetFileInfo (i);
if (fh != NULL) {
- // Create a TVFSItem entry and fill all info
- struct TVFSItem *item = (struct TVFSItem*)malloc(sizeof(struct TVFSItem));
- memset(item, 0, sizeof(struct TVFSItem));
-
- item->iSize = (int64_t)fh->m_uUncomprSize;
- item->iPackedSize = (int64_t)fh->m_uComprSize;
- if (fh->IsDirectory())
- item->ItemType = vDirectory;
- else item->ItemType = vRegular;
- item->iMode = fh->GetSystemAttr();
- item->iUID = geteuid();
- item->iGID = getegid();
- item->m_time = (__time_t)fh->GetTime();
- item->c_time = item->m_time;
- item->a_time = item->m_time;
-
- if (fh->IsEncrypted()) globs->need_password = TRUE;
-
- char *s;
-
- s = g_filename_display_name ((LPCTSTR)fh->GetFileName());
-
- // Add item to the global list and continue with next file
- filelist_tree_add_item(globs->files, s, s, item, i + 1);
- g_free (s);
- printf("\n");
+ /* Create a TVFSItem entry and fill all info */
+ item = (struct TVFSItem *) g_malloc0 (sizeof (struct TVFSItem));
+
+ item->iSize = (guint64) fh->m_uUncomprSize;
+ item->iPackedSize = (guint64) fh->m_uComprSize;
+ if (fh->IsDirectory ())
+ item->ItemType = vDirectory;
+ else
+ item->ItemType = vRegular;
+ item->iMode = fh->GetSystemAttr ();
+ item->iUID = geteuid ();
+ item->iGID = getegid ();
+ item->m_time = (__time_t) fh->GetTime ();
+ item->c_time = item->m_time;
+ item->a_time = item->m_time;
+
+ if (fh->IsEncrypted ())
+ globs->need_password = TRUE;
+
+ /* Add item to the global list and continue with next file */
+ s = g_filename_display_name ((LPCTSTR) fh->GetFileName ());
+ filelist_tree_add_item (globs->files, s, item, (LPCTSTR) fh->GetFileName (), i + 1);
+ g_free (s);
+ printf ("\n");
}
}
- if (globs->need_password) printf("Password present.\n");
+ if (globs->need_password)
+ printf ("Password present.\n");
- printf("\n\n\n\nPrinting the contents of the global filelist:\n\n");
- filelist_tree_print(globs->files);
+ printf ("\n\n\n\nPrinting the contents of the global filelist:\n\n");
+ filelist_tree_print (globs->files);
}
@@ -245,12 +255,11 @@ VFSNew (TVFSLogFunc log_func)
{
struct TVFSGlobs * globs;
- globs = (struct TVFSGlobs *) malloc (sizeof (struct TVFSGlobs));
- memset (globs, 0, sizeof (struct TVFSGlobs));
+ globs = (struct TVFSGlobs *) g_malloc0 (sizeof (struct TVFSGlobs));
- globs->archive_opened = false;
+ globs->archive_opened = FALSE;
globs->block_size = DEFAULT_BLOCK_SIZE;
- globs->archive_modified = false;
+ globs->archive_modified = FALSE;
globs->need_password = FALSE;
globs->callback_data = NULL;
@@ -259,7 +268,8 @@ VFSNew (TVFSLogFunc log_func)
globs->callback_progress = NULL;
globs->log_func = log_func;
- if (globs->log_func != NULL) globs->log_func("zip plugin: VFSInit");
+ if (globs->log_func != NULL)
+ globs->log_func ("zip plugin: VFSInit");
return globs;
}
@@ -280,19 +290,23 @@ VFSSetCallbacks (struct TVFSGlobs *globs,
void
VFSFree (struct TVFSGlobs *globs)
{
- if (globs->log_func != NULL) globs->log_func("zip plugin: VFSDestroy");
- free (globs);
+ if (globs->log_func != NULL)
+ globs->log_func ("zip plugin: VFSFree");
+ g_free (globs);
}
-int VFSVersion()
+int
+VFSVersion ()
{
return cVFSVersion;
}
struct TVFSInfo *
-VFSGetInfo()
+VFSGetInfo ()
{
- struct TVFSInfo *module_info = (TVFSInfo*) g_malloc0 (sizeof (struct TVFSInfo));
+ struct TVFSInfo *module_info;
+
+ module_info = (TVFSInfo*) g_malloc0 (sizeof (struct TVFSInfo));
module_info->ID = g_strdup ("zip_plugin");
module_info->Name = g_strdup ("ZIP plugin");
@@ -303,7 +317,7 @@ VFSGetInfo()
}
char *
-VFSGetArchiveExts()
+VFSGetArchiveExts ()
{
return g_strdup ("zip");
}
@@ -312,110 +326,118 @@ VFSGetArchiveExts()
/**************************************************************************************************************************************/
/**************************************************************************************************************************************/
-TVFSResult VFSOpenArchive(struct TVFSGlobs *globs, char *sName)
+TVFSResult
+VFSOpenArchive (struct TVFSGlobs *globs, const char *sName)
{
- // Initialize the objects
+ int iCount;
+
globs->files = NULL;
- globs->vfs_filelist = vfs_filelist_new(NULL);
+ globs->vfs_filelist = NULL;
globs->curr_dir = NULL;
globs->zip = new CZipArchive;
- try
- {
- fprintf(stderr, "(--) VFSOpenArchive: trying to open the file...\n");
+ try {
+ fprintf (stderr, "(--) VFSOpenArchive: trying to open the file...\n");
try {
- if (! globs->zip->Open(sName, CZipArchive::zipOpen, 0)) {
- printf("(EE) VFSOpenArchive: error opening zip archive\n");
- return cVFS_Failed;
+ if (! globs->zip->Open (sName, CZipArchive::zipOpen, 0)) {
+ printf ("(EE) VFSOpenArchive: error opening zip archive\n");
+ return cVFS_Failed;
}
}
catch (...) {
- printf("(!!) VFSOpenArchive: error opening readwrite zip, trying readonly...\n");
+ printf ("(!!) VFSOpenArchive: error opening readwrite zip, trying readonly...\n");
try {
- // try to open in read only mode (required if there's no write access on the media)
- if (! globs->zip->Open(sName, CZipArchive::zipOpenReadOnly, 0)) {
- printf("(EE) VFSOpenArchive: error opening readonly zip archive\n");
+ /* try to open in read only mode (required if there's no write access on the media) */
+ if (! globs->zip->Open (sName, CZipArchive::zipOpenReadOnly, 0)) {
+ printf ("(EE) VFSOpenArchive: error opening readonly zip archive\n");
return cVFS_Failed;
}
}
catch (...) {
- printf("(EE) VFSOpenArchive: error opening readonly zip\n");
+ printf ("(EE) VFSOpenArchive: error opening readonly zip\n");
return cVFS_Failed;
}
}
- int iCount = globs->zip->GetCount(false);
- printf("(II) VFSOpenArchive: %i records found, %i files.\n", iCount, globs->zip->GetCount(true));
- if (iCount < 1) return cVFS_Failed;
+ iCount = globs->zip->GetCount (false);
+ printf ("(II) VFSOpenArchive: %i records found, %i files.\n", iCount, globs->zip->GetCount (true));
+ if (iCount < 1)
+ return cVFS_Failed;
- // Build the global file list
- build_global_filelist(globs);
+ /* build global file list */
+ build_global_filelist (globs);
- // Set the progress callback
+ /* set progress callback */
globs->extract_callback = new CVFSZipActionCallback;
globs->extract_callback->globs = globs;
- globs->zip->SetCallback(globs->extract_callback, CZipActionCallback::cbExtract);
- globs->zip->SetCallback(globs->extract_callback, CZipActionCallback::cbAdd);
+ globs->zip->SetCallback (globs->extract_callback, CZipActionCallback::cbExtract);
+ globs->zip->SetCallback (globs->extract_callback, CZipActionCallback::cbAdd);
- // Set automatic flushing of changes to disk
- globs->zip->SetAutoFlush(true);
+ /* set automatic flushing of changes to disk */
+ globs->zip->SetAutoFlush (true);
}
catch (CZipException e) {
printf ("(EE) VFSOpenArchive: Error while processing archive %s\n%s\n", (LPCTSTR) sName, (LPCTSTR)e.GetErrorDescription());
- if (e.m_szFileName.IsEmpty()) printf("\n");
- else printf("(EE) VFSOpenArchive: Filename in error object: %s\n\n", (LPCTSTR)e.m_szFileName);
- globs->zip->Close(true);
+ if (e.m_szFileName.IsEmpty())
+ printf ("\n");
+ else
+ printf ("(EE) VFSOpenArchive: Filename in error object: %s\n\n", (LPCTSTR)e.m_szFileName);
+ globs->zip->Close (true);
return cVFS_Failed;
}
catch (...) {
printf ("(EE) VFSOpenArchive: Unknown error while processing archive %s\n\n", (LPCTSTR) sName);
- globs->zip->Close(true);
+ globs->zip->Close (true);
return cVFS_Failed;
}
- globs->archive_path = strdup(sName);
- globs->archive_modified = false;
+ globs->archive_path = g_strdup (sName);
+ globs->archive_modified = FALSE;
return cVFS_OK;
}
-TVFSResult VFSClose(struct TVFSGlobs *globs)
+TVFSResult
+VFSClose (struct TVFSGlobs *globs)
{
if (globs) {
- // Closing the archive...
- fprintf(stderr, "(II) VFSClose: Closing the archive...\n");
- try {
- if (globs->archive_modified) globs->zip->Flush();
- globs->zip->Close(CZipArchive::afNoException, false);
- //*** In case of inconsistency, try using afWriteDir value
- // (Use when an exception was thrown. The Close method writes the
- // central directory structure to the archive, so that the archive should be usable.)
- }
- catch (CZipException e) {
- fprintf(stderr, "(EE) VFSClose: Error while closing archive: %s\n", (LPCTSTR)e.GetErrorDescription());
- return cVFS_Failed;
- }
-
-
- // Freeing the ZIP objects...
- fprintf(stderr, "(II) VFSClose: Freeing ZipArchive objects...\n");
- try {
- delete globs->extract_callback;
- delete globs->zip;
- }
- catch (...) {
- fprintf(stderr, "(EE) VFSClose: Error freeing ZipArchive objects\n");
- return cVFS_Failed;
- }
-
- // Freeing the filelist
- fprintf(stderr, "(II) VFSClose: Freeing filelist...\n");
- if (globs->vfs_filelist) vfs_filelist_free(globs->vfs_filelist);
- if (globs->files) filelist_tree_free(globs->files);
-
- // Free the rest...
- free(globs->archive_path);
+ /* close the archive... */
+ fprintf (stderr, "(II) VFSClose: Closing the archive...\n");
+ try {
+ if (globs->archive_modified)
+ globs->zip->Flush ();
+ /* In case of inconsistency, try using afWriteDir value.
+ * (use when an exception was thrown, yhe Close method writes the
+ * central directory structure to the archive, so that the archive should be usable.)
+ */
+ globs->zip->Close (CZipArchive::afNoException, false);
+ }
+ catch (CZipException e) {
+ fprintf (stderr, "(EE) VFSClose: Error while closing archive: %s\n", (LPCTSTR)e.GetErrorDescription());
+ return cVFS_Failed;
+ }
+
+ /* free the ZIP objects... */
+ fprintf (stderr, "(II) VFSClose: Freeing ZipArchive objects...\n");
+ try {
+ delete globs->extract_callback;
+ delete globs->zip;
+ }
+ catch (...) {
+ fprintf (stderr, "(EE) VFSClose: Error freeing ZipArchive objects\n");
+ return cVFS_Failed;
+ }
+
+ /* free the filelist */
+ fprintf (stderr, "(II) VFSClose: Freeing filelist...\n");
+ if (globs->vfs_filelist)
+ vfs_filelist_free (globs->vfs_filelist);
+ if (globs->files)
+ filelist_tree_free (globs->files);
+
+ /* free the rest... */
+ g_free (globs->archive_path);
}
return cVFS_OK;
}
@@ -426,115 +448,108 @@ VFSGetPath (struct TVFSGlobs *globs)
return g_strdup (globs->curr_dir);
}
-u_int64_t VFSGetFileSystemFree(struct TVFSGlobs *globs, char *APath)
+TVFSResult
+VFSGetFileSystemInfo (struct TVFSGlobs *globs, const char *APath, gint64 *FSSize, gint64 *FSFree, char **FSLabel)
{
- return 0;
-}
-
-u_int64_t VFSGetFileSystemSize(struct TVFSGlobs *globs, char *APath)
-{
- return globs->zip->GetOccupiedSpace();
+ if (FSSize)
+ *FSSize = globs->zip->GetOccupiedSpace ();
+ if (FSFree)
+ *FSFree = 0;
+ if (FSLabel)
+ *FSLabel = NULL;
+ return cVFS_OK;
}
-
-
/******************************************************************************************************/
-TVFSResult VFSChangeDir(struct TVFSGlobs *globs, char *NewPath)
+TVFSResult
+VFSChangeDir (struct TVFSGlobs *globs, const char *NewPath)
{
if (NewPath == NULL) {
- printf("(EE) VFSChangeDir: NewPath is NULL!\n");
+ printf ("(EE) VFSChangeDir: NewPath is NULL!\n");
return cVFS_Failed;
}
- globs->curr_dir = vfs_filelist_change_dir(globs->vfs_filelist, NewPath);
- if (globs->curr_dir) return cVFS_OK;
- else return cVFS_Failed;
-}
-
-/*
-int VFSSetPassword(struct TVFSGlobs *globs, char *pass)
-{
- printf ("(II) VFSSetPassword: Going to set the password...\n");
- try {
- globs->zip->SetPassword(pass);
- }
- catch (...)
- {
- printf ("(EE) VFSSetPassword: Changing password failed. Maybe closed archive ?\n");
+ globs->curr_dir = vfs_filelist_change_dir (globs->vfs_filelist, NewPath);
+ if (globs->curr_dir)
+ return cVFS_OK;
+ else
return cVFS_Failed;
- }
- return cVFS_OK;
}
-*/
-int VFSGetPasswordRequired(struct TVFSGlobs *globs)
+gboolean
+VFSGetPasswordRequired (struct TVFSGlobs *globs)
{
- if (globs) return globs->need_password;
+ if (globs)
+ return globs->need_password;
return FALSE;
}
void
-VFSResetPassword(struct TVFSGlobs *globs)
+VFSResetPassword (struct TVFSGlobs *globs)
{
if (globs)
- globs->zip->SetPassword(NULL);
+ globs->zip->SetPassword (NULL);
}
/******************************************************************************************************/
-TVFSResult VFSListFirst(struct TVFSGlobs *globs, char *sDir, struct TVFSItem *Item)
+TVFSResult
+VFSListFirst (struct TVFSGlobs *globs, const char *sDir, struct TVFSItem *Item, gboolean FollowSymlinks, gboolean AddFullPath)
{
if (sDir == NULL) {
- printf("(EE) VFSListFirst: sDir is NULL!\n");
+ printf ("(EE) VFSListFirst: sDir is NULL!\n");
return cVFS_Failed;
}
printf ("(--) VFSListFirst: Going to list all items in '%s'\n", sDir);
-
- return vfs_filelist_list_first(globs->vfs_filelist, sDir, Item);
+
+ return vfs_filelist_list_first (globs->vfs_filelist, sDir, Item, FollowSymlinks, AddFullPath);
}
-TVFSResult VFSListNext(struct TVFSGlobs *globs, char *sDir, struct TVFSItem *Item)
+TVFSResult
+VFSListNext (struct TVFSGlobs *globs, struct TVFSItem *Item)
{
- return vfs_filelist_list_next(globs->vfs_filelist, sDir, Item);
+ return vfs_filelist_list_next (globs->vfs_filelist, Item);
}
-TVFSResult VFSListClose(struct TVFSGlobs *globs)
+TVFSResult
+VFSListClose (struct TVFSGlobs *globs)
{
- return vfs_filelist_list_close(globs->vfs_filelist);
+ return vfs_filelist_list_close (globs->vfs_filelist);
}
/******************************************************************************************************/
-long VFSFileExists(struct TVFSGlobs *globs, const char *FileName, const long Use_lstat)
-{
- if (! globs) return FALSE;
- return vfs_filelist_file_exists(globs->vfs_filelist, FileName, Use_lstat);
-}
-TVFSResult VFSFileInfo(struct TVFSGlobs *globs, char *AFileName, struct TVFSItem *Item)
+TVFSResult
+VFSFileInfo (struct TVFSGlobs *globs, const char *AFileName, struct TVFSItem *Item, gboolean FollowSymlinks, gboolean AddFullPath)
{
- printf("(--) VFSFileInfo: requested info for object '%s'\n", AFileName);
- if (!globs) return cVFS_Failed;
- return vfs_filelist_file_info(globs->vfs_filelist, AFileName, Item);
+ printf ("(--) VFSFileInfo: requested info for object '%s'\n", AFileName);
+ if (! globs)
+ return cVFS_Failed;
+ return vfs_filelist_file_info (globs->vfs_filelist, AFileName, Item, FollowSymlinks, AddFullPath);
}
/******************************************************************************************************/
/** Recursive tree size counting */
/************** ****************/
-u_int64_t VFSGetDirSize(struct TVFSGlobs *globs, char *APath)
+guint64
+VFSGetDirSize (struct TVFSGlobs *globs, const char *APath)
{
- if (! globs) return 0;
- return vfs_filelist_get_dir_size(globs->vfs_filelist, APath);
+ if (! globs)
+ return 0;
+ return vfs_filelist_get_dir_size (globs->vfs_filelist, APath);
}
-void VFSBreakGetDirSize(struct TVFSGlobs *globs)
+void
+VFSBreakGetDirSize (struct TVFSGlobs *globs)
{
- printf("(WW) VFSBreakGetDirSize: calling break\n");
- if (globs) vfs_filelist_get_dir_size_break(globs->vfs_filelist);
+ printf ("(WW) VFSBreakGetDirSize: calling break\n");
+ if (globs)
+ vfs_filelist_get_dir_size_break (globs->vfs_filelist);
}
@@ -542,133 +557,153 @@ void VFSBreakGetDirSize(struct TVFSGlobs *globs)
/** Methods modifying the archive */
/************** ****************/
-TVFSResult VFSMkDir(struct TVFSGlobs *globs, const char *sDirName)
+TVFSResult
+VFSMkDir (struct TVFSGlobs *globs, const char *sDirName)
{
- if ((sDirName == NULL) || (strlen(sDirName) < 1)) {
- printf("(EE) VFSMkDir: The value of 'sDirName' is NULL or empty\n");
- return cVFS_Failed;
+ CZipFileHeader header;
+ char *s;
+ bool bRet;
+
+ if (sDirName == NULL || strlen (sDirName) < 1) {
+ printf ("(EE) VFSMkDir: The value of 'sDirName' is NULL or empty\n");
+ return cVFS_Failed;
}
- if ((strlen(sDirName) < 1) || (strcmp(sDirName, "/") == 0)) {
- printf("(EE) VFSMkDir: Invalid value '%s' (duplicate root entry?)\n", sDirName);
+ if (strcmp (sDirName, "/") == 0) {
+ printf ("(EE) VFSMkDir: Invalid value '%s' (duplicate root entry?)\n", sDirName);
return cVFS_Failed;
}
printf ("(II) VFSMkDir: Going to create new directory '%s'...\n", sDirName);
try {
- try {
- CZipFileHeader header;
-// globs->zip->SetFileHeaderAttr(header, 0x41ED0010); // alternatively use ZipPlatform::GetDefaultAttributes();
- globs->zip->SetFileHeaderAttr(header, 0x41ED); // alternatively use ZipPlatform::GetDefaultAttributes();
- char *s = exclude_leading_path_sep(sDirName);
+ try {
+// globs->zip->SetFileHeaderAttr (header, 0x41ED0010);
+ globs->zip->SetFileHeaderAttr (header, 0x41ED); /* alternatively use ZipPlatform::GetDefaultAttributes(); */
+ s = exclude_leading_path_sep (sDirName);
header.SetFileName(s);
- free(s);
- header.SetTime(time(NULL));
- bool bRet = globs->zip->OpenNewFile(header, 0, NULL);
- globs->zip->CloseNewFile();
+ g_free (s);
+ header.SetTime (time (NULL));
+ bRet = globs->zip->OpenNewFile (header, 0, NULL);
+ globs->zip->CloseNewFile ();
if (! bRet) {
- printf("(EE) VFSMkDir: Error creating new directory '%s'\n", sDirName);
+ printf ("(EE) VFSMkDir: Error creating new directory '%s'\n", sDirName);
return cVFS_Failed;
}
- globs->archive_modified = true;
- build_global_filelist(globs);
+ globs->archive_modified = TRUE;
+ build_global_filelist (globs);
return cVFS_OK;
- }
+ }
catch (CZipException e) {
- globs->zip->CloseNewFile(true);
- fprintf(stderr, "(EE) VFSMkDir: Error creating new directory '%s': [%d] %s, archive closed = %d.\n",
- sDirName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
- return get_vfs_errorcode(e.m_iCause);
+ globs->zip->CloseNewFile (true);
+ fprintf (stderr, "(EE) VFSMkDir: Error creating new directory '%s': [%d] %s, archive closed = %d.\n",
+ sDirName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed ());
+ return get_vfs_errorcode (e.m_iCause);
}
}
catch (...)
{
- printf("(EE) VFSMkDir: Error creating new directory '%s'\n", sDirName);
+ printf ("(EE) VFSMkDir: Error creating new directory '%s'\n", sDirName);
return cVFS_Failed;
}
}
-TVFSResult VFSRemove(struct TVFSGlobs *globs, const char *APath)
+
+TVFSResult
+VFSRemove (struct TVFSGlobs *globs, const char *APath)
{
- printf("(II) VFSRemove: Going to remove the file '%s'...\n", APath);
+ char *AFile, *AFile1, *AFile2, *AFile3;
+ unsigned long int file_no;
+
+
+ printf ("(II) VFSRemove: Going to remove the file '%s'...\n", APath);
- char *AFile = exclude_trailing_path_sep(APath);
- unsigned long int file_no = filelist_find_index_by_path(globs->files, AFile) - 1;
- free(AFile);
+ AFile = exclude_trailing_path_sep (APath);
+ file_no = filelist_find_original_index_by_path (globs->files, AFile) - 1;
+ g_free (AFile);
if (file_no < 0) {
- printf("(EE) VFSRemove: can't find the file specified: '%s'\n", APath);
+ printf ("(EE) VFSRemove: can't find the file specified: '%s'\n", APath);
return cVFS_Failed;
}
try {
try {
- if (! globs->zip->RemoveFile(file_no)) {
- printf("(EE) VFSRemove: Delete file '%s' failed.\n", APath);
+ if (! globs->zip->RemoveFile (file_no)) {
+ printf ("(EE) VFSRemove: Delete file '%s' failed.\n", APath);
return cVFS_Failed;
}
- build_global_filelist(globs);
- globs->archive_modified = true;
- printf("(II) VFSRemove OK.\n");
+ build_global_filelist (globs);
+ globs->archive_modified = TRUE;
+ printf ("(II) VFSRemove OK.\n");
- // Test for the sparse ZIP central directory
- char *AFile1 = exclude_trailing_path_sep(APath);
- char *AFile2 = g_path_get_dirname(AFile1);
- char *AFile3 = exclude_trailing_path_sep(AFile2);
- if ((strlen(AFile3) > 0) && (strcmp(AFile3, "/") != 0)) {
- printf("(II) VFSRemove: AFile1: '%s', AFile2: '%s', AFile3: '%s'\n", AFile1, AFile2, AFile3);
- file_no = filelist_find_index_by_path(globs->files, AFile2) - 1;
- printf("(II) VFSRemove: deleted: '%s', parent: '%s', file_no = %ld\n", APath, AFile3, file_no);
+ /* If we delete last file from a directory, we should make an empty one.
+ * Some archives store pathnames only with filenames, no separate records for directories.
+ **/
+ AFile1 = exclude_trailing_path_sep (APath);
+ AFile2 = g_path_get_dirname (AFile1);
+ AFile3 = exclude_trailing_path_sep (AFile2);
+ if (strlen (AFile3) > 0 && g_strcmp0 (AFile3, "/") != 0) {
+ printf ("(II) VFSRemove: AFile1: '%s', AFile2: '%s', AFile3: '%s'\n", AFile1, AFile2, AFile3);
+ file_no = filelist_find_original_index_by_path (globs->files, AFile2) - 1;
+ printf ("(II) VFSRemove: deleted: '%s', parent: '%s', file_no = %ld\n", APath, AFile3, file_no);
if (file_no < 0) {
- printf("(WW) VFSRemove: sparse ZIP archive detected, adding empty directory: '%s'\n", AFile3);
- VFSMkDir(globs, AFile3);
+ printf ("(WW) VFSRemove: sparse ZIP archive detected, adding empty directory: '%s'\n", AFile3);
+ VFSMkDir (globs, AFile3);
}
}
- free(AFile1); free(AFile2); free(AFile3);
+ g_free (AFile1);
+ g_free (AFile2);
+ g_free (AFile3);
return cVFS_OK;
}
catch (CZipException e) {
- fprintf(stderr, "(EE) VFSRemove: Delete file '%s' failed: [%d] %s, archive closed = %d.\n",
- APath, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
- return get_vfs_errorcode(e.m_iCause);
+ fprintf (stderr, "(EE) VFSRemove: Delete file '%s' failed: [%d] %s, archive closed = %d.\n",
+ APath, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed ());
+ return get_vfs_errorcode (e.m_iCause);
}
}
catch (...)
{
- printf("(EE) VFSRemove: Delete file '%s' failed.\n", APath);
+ printf ("(EE) VFSRemove: Delete file '%s' failed.\n", APath);
return cVFS_Failed;
}
}
-TVFSResult VFSRename(struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName)
+
+TVFSResult
+VFSRename (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName)
{
+ char *AFile;
+ char *ADestFile;
+ unsigned long int file_no;
+
printf ("(II) VFSRename: Going to rename/move the file '%s' to '%s'...\n", sSrcName, sDstName);
- char *AFile = exclude_trailing_path_sep(sSrcName);
- char *ADestFile = exclude_trailing_path_sep(sDstName);
- unsigned long int file_no = filelist_find_index_by_path(globs->files, AFile) - 1;
- free(AFile);
+ AFile = exclude_trailing_path_sep (sSrcName);
+ ADestFile = exclude_trailing_path_sep (sDstName);
+ file_no = filelist_find_original_index_by_path (globs->files, AFile) - 1;
+ g_free (AFile);
if (file_no < 0) {
- printf("(EE) VFSRename: can't find the file specified: '%s'\n", sSrcName);
+ printf ("(EE) VFSRename: can't find the file specified: '%s'\n", sSrcName);
return cVFS_Failed;
}
try {
try {
- if (! globs->zip->RenameFile(file_no, ADestFile)) {
+ if (! globs->zip->RenameFile (file_no, ADestFile)) {
printf ("(EE) VFSRename: Rename/move file '%s' failed.\n", sSrcName);
return cVFS_Failed;
}
- free(ADestFile);
- build_global_filelist(globs);
- globs->archive_modified = true;
+ g_free (ADestFile);
+ build_global_filelist (globs);
+ globs->archive_modified = TRUE;
return cVFS_OK;
}
catch (CZipException e) {
- fprintf(stderr, "(EE) VFSRename: Rename/move file '%s' failed: [%d] %s, archive closed = %d.\n",
- sSrcName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
- return get_vfs_errorcode(e.m_iCause);
+ fprintf (stderr, "(EE) VFSRename: Rename/move file '%s' failed: [%d] %s, archive closed = %d.\n",
+ sSrcName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed ());
+ return get_vfs_errorcode (e.m_iCause);
}
}
catch (...)
@@ -678,37 +713,45 @@ TVFSResult VFSRename(struct TVFSGlobs *globs, const char *sSrcName, const char *
}
}
-TVFSResult VFSMakeSymLink(struct TVFSGlobs *globs, const char *NewFileName, const char *PointTo)
+
+TVFSResult
+VFSMakeSymLink (struct TVFSGlobs *globs, const char *NewFileName, const char *PointTo)
{
- fprintf(stderr, "(EE) VFSMakeSymLink: Symbolic links not supported in ZIP archives.\n");
+ fprintf (stderr, "(EE) VFSMakeSymLink: Symbolic links not supported in ZIP archives.\n");
return cVFS_Not_Supported;
}
-TVFSResult VFSChmod(struct TVFSGlobs *globs, const char *FileName, const uint Mode)
+
+TVFSResult
+VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode)
{
- printf("(II) VFSChmod: Going to change permissions of the file '%s'...\n", FileName);
+ char *AFile;
+ unsigned long int file_no;
+ CZipFileHeader *header;
+
+ printf ("(II) VFSChmod: Going to change permissions of the file '%s'...\n", FileName);
- char *AFile = exclude_trailing_path_sep(FileName);
- unsigned long int file_no = filelist_find_index_by_path(globs->files, AFile) - 1;
- free(AFile);
+ AFile = exclude_trailing_path_sep (FileName);
+ file_no = filelist_find_original_index_by_path (globs->files, AFile) - 1;
+ g_free (AFile);
if (file_no < 0) {
- printf("(EE) VFSChmod: can't find the file specified: '%s'\n", FileName);
+ printf ("(EE) VFSChmod: can't find the file specified: '%s'\n", FileName);
return cVFS_Failed;
}
try {
try {
- // Set system compatibility first
- if (! globs->zip->SetSystemCompatibility(ZipCompatibility::zcUnix)) {
- printf("(EE) VFSChmod: Unable to set system compatibility\n");
+ /* set system compatibility first */
+ if (! globs->zip->SetSystemCompatibility (ZipCompatibility::zcUnix)) {
+ printf ("(EE) VFSChmod: Unable to set system compatibility\n");
}
- // Change the header data
- globs->zip->ReadLocalHeader(file_no);
- CZipFileHeader *header = globs->zip->GetFileInfo(file_no);
+ /* change the header data */
+ globs->zip->ReadLocalHeader (file_no);
+ header = globs->zip->GetFileInfo (file_no);
if (! header) {
- printf("(EE) VFSChmod: Permissions modification of the file '%s' failed: NULL returned by GetFileInfo()\n", FileName);
+ printf ("(EE) VFSChmod: Permissions modification of the file '%s' failed: NULL returned by GetFileInfo()\n", FileName);
return cVFS_Failed;
}
// We need to change only 0xF000FFFF mask
@@ -718,75 +761,82 @@ TVFSResult VFSChmod(struct TVFSGlobs *globs, const char *FileName, const uint Mo
// header->GetSystemAttr(), header->GetSystemAttr() & 0xF000FFFF, Mode & 0xFFF, (header->GetSystemAttr() & 0xF000FFFF) + ((Mode & 0xFFF) << 16));
// globs->zip->SetFileHeaderAttr(*header, (header->GetSystemAttr() & 0xF000FFFF) + ((Mode & 0xFFF) << 16));
- printf("(II) VFSChmod: Current permissions: 0x%lX, stripped: 0x%lX, setting to: 0x%X, modified: 0x%lX\n",
+ printf ("(II) VFSChmod: Current permissions: 0x%lX, stripped: 0x%lX, setting to: 0x%X, modified: 0x%lX\n",
header->GetSystemAttr(), header->GetSystemAttr() & 0xFFFFF000,
Mode & 0xFFF, (header->GetSystemAttr() & 0xFFFFF000) + (Mode & 0xFFF));
- globs->zip->SetFileHeaderAttr(*header, (header->GetSystemAttr() & 0xFFFFF000) + (Mode & 0xFFF));
+ globs->zip->SetFileHeaderAttr (*header, (header->GetSystemAttr() & 0xFFFFF000) + (Mode & 0xFFF));
- // write the local header information
- globs->zip->OverwriteLocalHeader(file_no);
+ /* write local header information */
+ globs->zip->OverwriteLocalHeader (file_no);
-/*
+#if 0
// Re-encrypt the file
if (header->IsEncrypted()) {
printf("(II) VFSChmod: Re-encrypting the file...\n");
if (! globs->zip->EncryptFile(file_no))
printf("(EE) VFSChmod: Unable to encrypt the file\n");
}
-*/
- globs->zip->RemoveCentralDirectoryFromArchive();
- globs->zip->Flush();
+#endif
+ globs->zip->RemoveCentralDirectoryFromArchive ();
+ globs->zip->Flush ();
-
- printf("(II) VFSChmod OK.\n");
- build_global_filelist(globs);
- globs->archive_modified = true;
+ printf ("(II) VFSChmod OK.\n");
+ build_global_filelist (globs);
+ globs->archive_modified = TRUE;
return cVFS_OK;
}
catch (CZipException e) {
- globs->zip->CloseNewFile(true);
- fprintf(stderr, "(EE) VFSChmod: permissions modification of the file '%s' failed: [%d] %s, archive closed = %d.\n",
+ globs->zip->CloseNewFile (true);
+ fprintf (stderr, "(EE) VFSChmod: permissions modification of the file '%s' failed: [%d] %s, archive closed = %d.\n",
FileName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
- return get_vfs_errorcode(e.m_iCause);
+ return get_vfs_errorcode (e.m_iCause);
}
}
catch (...)
{
- printf("(EE) VFSChmod: permissions modification of the file '%s' failed.\n", FileName);
+ printf ("(EE) VFSChmod: permissions modification of the file '%s' failed.\n", FileName);
return cVFS_Failed;
}
}
-TVFSResult VFSChown(struct TVFSGlobs *globs, const char *FileName, const uint UID, const uint GID)
+
+TVFSResult
+VFSChown (struct TVFSGlobs *globs, const char *FileName, guint32 UID, guint32 GID)
{
- fprintf(stderr, "(EE) VFSChown: Owner changing is not supported in ZIP archives.\n");
+ fprintf (stderr, "(EE) VFSChown: Owner changing is not supported in ZIP archives.\n");
return cVFS_Not_Supported;
}
-TVFSResult VFSChangeTimes(struct TVFSGlobs *globs, char *APath, long mtime, long atime)
+
+TVFSResult
+VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint32 atime)
{
+ char *AFile;
+ unsigned long int file_no;
+ CZipFileHeader *header;
+
printf ("(II) VFSChangeTimes: Going to change date/times of the file '%s'...\n", APath);
- char *AFile = exclude_trailing_path_sep(APath);
- unsigned long int file_no = filelist_find_index_by_path(globs->files, AFile) - 1;
- free(AFile);
+ AFile = exclude_trailing_path_sep (APath);
+ file_no = filelist_find_original_index_by_path (globs->files, AFile) - 1;
+ g_free (AFile);
if (file_no < 0) {
- printf("(EE) VFSChangeTimes: can't find the file specified: '%s'\n", APath);
+ printf ("(EE) VFSChangeTimes: can't find the file specified: '%s'\n", APath);
return cVFS_Failed;
}
try {
try {
- // read the local header information
- globs->zip->ReadLocalHeader(file_no);
- CZipFileHeader *header = globs->zip->GetFileInfo(file_no);
+ /* read the local header information */
+ globs->zip->ReadLocalHeader (file_no);
+ header = globs->zip->GetFileInfo (file_no);
if (! header) {
- printf("(EE) VFSChangeTimes: DateTime modification of the file '%s' failed: NULL returned by GetFileInfo()\n", APath);
+ printf ("(EE) VFSChangeTimes: DateTime modification of the file '%s' failed: NULL returned by GetFileInfo()\n", APath);
return cVFS_Failed;
}
- // Change the header data
- header->SetTime(mtime);
+ /* change the header data */
+ header->SetTime (mtime);
/* // Re-encrypt the file
if (header->IsEncrypted()) {
@@ -795,25 +845,24 @@ TVFSResult VFSChangeTimes(struct TVFSGlobs *globs, char *APath, long mtime, long
printf("(EE) VFSChangeTimes: Unable to encrypt the file\n");
}
*/
- // write the local header information
- globs->zip->OverwriteLocalHeader(file_no);
- globs->zip->RemoveCentralDirectoryFromArchive();
+ /* write local header information */
+ globs->zip->OverwriteLocalHeader (file_no);
+ globs->zip->RemoveCentralDirectoryFromArchive ();
- printf("(II) VFSChangeTimes OK.\n");
- build_global_filelist(globs);
- globs->archive_modified = true;
+ printf ("(II) VFSChangeTimes OK.\n");
+ build_global_filelist (globs);
+ globs->archive_modified = TRUE;
return cVFS_OK;
}
catch (CZipException e) {
- globs->zip->CloseNewFile(true);
- fprintf(stderr, "(EE) VFSChangeTimes: DateTime modification of the file '%s' failed: [%d] %s, archive closed = %d.\n",
- APath, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
- return get_vfs_errorcode(e.m_iCause);
+ globs->zip->CloseNewFile (true);
+ fprintf (stderr, "(EE) VFSChangeTimes: DateTime modification of the file '%s' failed: [%d] %s, archive closed = %d.\n",
+ APath, e.m_iCause, (LPCTSTR)e.GetErrorDescription (), globs->zip->IsClosed ());
+ return get_vfs_errorcode (e.m_iCause);
}
}
- catch (...)
- {
- printf("(EE) VFSChangeTimes: DateTime modification of the file '%s' failed.\n", APath);
+ catch (...) {
+ printf ("(EE) VFSChangeTimes: DateTime modification of the file '%s' failed.\n", APath);
return cVFS_Failed;
}
}
@@ -852,21 +901,25 @@ int VFSWriteFile(struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, void *Buff
return 0;
}
-void VFSSetBlockSize(struct TVFSGlobs *globs, int Value)
+void
+VFSSetBlockSize (struct TVFSGlobs *globs, guint32 Value)
{
- globs->block_size = Value;
+ if (globs)
+ globs->block_size = Value;
}
-int VFSIsOnSameFS(struct TVFSGlobs *globs, const char *Path1, const char *Path2)
+gboolean
+VFSIsOnSameFS (struct TVFSGlobs *globs, const char *Path1, const char *Path2, gboolean FollowSymlinks)
{
- printf("(II) VFSIsOnSameFS: Not supported in ZIP archives.\n");
- return true;
+ printf ("(II) VFSIsOnSameFS: Not supported in ZIP archives.\n");
+ return TRUE;
}
-int VFSTwoSameFiles(struct TVFSGlobs *globs, const char *Path1, const char *Path2)
+gboolean
+VFSTwoSameFiles (struct TVFSGlobs *globs, const char *Path1, const char *Path2, gboolean FollowSymlinks)
{
- printf("(II) VFSTwoSameFiles: Not supported in ZIP archives, comparing by paths.\n");
- return compare_two_same_files(Path1, Path2);
+ printf ("(II) VFSTwoSameFiles: Not supported in ZIP archives, comparing by paths.\n");
+ return compare_two_same_files (Path1, Path2);
}
@@ -874,108 +927,127 @@ int VFSTwoSameFiles(struct TVFSGlobs *globs, const char *Path1, const char *Path
////////////////////////
-// Known issues: - crashes when no space left on NFS mounts, probably unhandled exception in further ZipArchive code (repro: Gentoo, Ubuntu)
-TVFSResult VFSCopyToLocal(struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, int Append)
+/* Known issues:
+ * - crashes when no space left on NFS mounts, probably unhandled exception in further ZipArchive code (repro: Gentoo, Ubuntu)
+ *
+ **/
+TVFSResult
+VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append)
{
gboolean try_again;
+ unsigned long int file_no;
+ char *s;
+ char *dest_path;
+ char *dest_filename;
+ char *passwd;
+ int res;
+
- 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");
+ 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;
}
- printf("(II) VFSCopyToLocal: copying file '%s' out to '%s'\n", sSrcName, sDstName);
+ printf ("(II) VFSCopyToLocal: copying file '%s' out to '%s'\n", sSrcName, sDstName);
- unsigned long int file_no = filelist_find_index_by_path(globs->files, sSrcName) - 1;
+ file_no = filelist_find_original_index_by_path (globs->files, sSrcName) - 1;
if (file_no < 0) {
- printf("(EE) VFSCopyToLocal: can't find source file '%s'\n", sSrcName);
+ printf ("(EE) VFSCopyToLocal: can't find source file '%s'\n", sSrcName);
return cVFS_ReadErr;
}
- char *s = exclude_trailing_path_sep(sDstName);
- char *dest_path = extract_file_path(s);
- char *dest_filename = extract_file_name(s);
- free(s);
+ s = exclude_trailing_path_sep (sDstName);
+ dest_path = g_path_get_dirname (s);
+ dest_filename = g_path_get_basename (s);
+ g_free (s);
- // Perform extract
+ /* Perform extract */
try {
do {
try {
try_again = FALSE;
- if (! globs->zip->ExtractFile(file_no, dest_path, false, dest_filename, globs->block_size)) {
- globs->zip->CloseFile(NULL, true);
- fprintf(stderr, "(EE) VFSCopyToLocal: Error while copying out, archive closed = %d.\n", globs->zip->IsClosed());
+ if (! globs->zip->ExtractFile (file_no, dest_path, false, dest_filename, globs->block_size)) {
+ globs->zip->CloseFile (NULL, true);
+ fprintf (stderr, "(EE) VFSCopyToLocal: Error while copying out, archive closed = %d.\n", globs->zip->IsClosed ());
return cVFS_WriteErr;
}
- fprintf(stderr, "(II) VFSCopyToLocal: copy OK, archive closed = %d.\n", globs->zip->IsClosed());
+ fprintf (stderr, "(II) VFSCopyToLocal: copy OK, archive closed = %d.\n", globs->zip->IsClosed ());
}
catch (CZipException e) {
- globs->zip->CloseFile(NULL, true);
- fprintf(stderr, "(EE) VFSCopyToLocal: Error while copying out: [%d] %s, archive closed = %d.\n",
- e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
+ globs->zip->CloseFile (NULL, true);
+ fprintf (stderr, "(EE) VFSCopyToLocal: Error while copying out: [%d] %s, archive closed = %d.\n",
+ e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
switch (e.m_iCause) {
case CZipException::badPassword:
if (globs->callback_ask_password) {
- char *passwd = NULL;
- int res = globs->callback_ask_password ("The archive is encrypted and requires password",
- NULL, NULL, NULL, (TVFSAskPasswordFlags)(VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE),
- NULL, &passwd, NULL, NULL, NULL,
- globs->callback_data);
+ passwd = NULL;
+ res = globs->callback_ask_password ("The archive is encrypted and requires password",
+ NULL, NULL, NULL, (TVFSAskPasswordFlags)(VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE),
+ NULL, &passwd, NULL, NULL, NULL,
+ globs->callback_data);
if (res && passwd) {
- fprintf(stderr, " (II) VFSCopyToLocal: setting password to '%s'\n", passwd);
- globs->zip->SetPassword(passwd);
+ fprintf (stderr, " (II) VFSCopyToLocal: setting password to '%s'\n", passwd);
+ globs->zip->SetPassword (passwd);
try_again = TRUE;
break;
} else
return cVFS_Cancelled;
}
default:
- return get_vfs_errorcode(e.m_iCause);
+ return get_vfs_errorcode (e.m_iCause);
}
}
} while (try_again);
}
catch (...)
{
- fprintf(stderr, "(EE) VFSCopyToLocal: Fatal error while copying out..., archive closed = %d.\n", globs->zip->IsClosed());
+ fprintf (stderr, "(EE) VFSCopyToLocal: Fatal error while copying out..., archive closed = %d.\n", globs->zip->IsClosed());
return cVFS_WriteErr;
}
+ g_free (dest_path);
+ g_free (dest_filename);
- free(dest_path);
- free(dest_filename);
return cVFS_OK;
}
-// Known issues: - archive corruption when no space left on device
-// - encrypted files are unreadable after copy in
-TVFSResult VFSCopyFromLocal(struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, int Append)
+
+/* Known issues:
+ * - archive corruption when no space left on device
+ * - encrypted files are unreadable after copy in
+ *
+ **/
+TVFSResult
+VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append)
{
gboolean try_again;
+ char *s;
+ char *passwd;
+ int res;
- if ((sSrcName == NULL) || (sDstName == NULL) || (strlen(sSrcName) < 1) || (strlen(sDstName) < 1)) {
- printf("(EE) VFSCopyFromLocal: The value of 'sSrcName' or 'sDstName' is NULL or empty\n");
+ if (sSrcName == NULL || sDstName == NULL || strlen (sSrcName) < 1 || strlen (sDstName) < 1) {
+ printf ("(EE) VFSCopyFromLocal: The value of 'sSrcName' or 'sDstName' is NULL or empty\n");
return cVFS_Failed;
}
- printf("(II) VFSCopyFromLocal: copying file '%s' in to '%s'\n", sSrcName, sDstName);
+ printf ("(II) VFSCopyFromLocal: copying file '%s' in to '%s'\n", sSrcName, sDstName);
try {
do {
try {
try_again = FALSE;
- char *s = exclude_leading_path_sep(sDstName);
- if (! globs->zip->AddNewFile(sSrcName, s, -1, CZipArchive::zipsmSafeSmart, globs->block_size)) {
- globs->zip->CloseNewFile(true);
- globs->zip->CloseFile(NULL, true);
- build_global_filelist(globs);
- fprintf(stderr, "(EE) VFSCopyFromLocal: Error while copying in, archive closed = %d.\n", globs->zip->IsClosed());
+ s = exclude_leading_path_sep (sDstName);
+ if (! globs->zip->AddNewFile (sSrcName, s, -1, CZipArchive::zipsmSafeSmart, globs->block_size)) {
+ globs->zip->CloseNewFile (true);
+ globs->zip->CloseFile (NULL, true);
+ build_global_filelist (globs);
+ fprintf (stderr, "(EE) VFSCopyFromLocal: Error while copying in, archive closed = %d.\n", globs->zip->IsClosed ());
return cVFS_WriteErr;
}
- globs->zip->Flush();
- printf("(II) VFSCopyFromLocal: copy OK, archive closed = %d.\n", globs->zip->IsClosed());
- build_global_filelist(globs);
- globs->archive_modified = true;
+ globs->zip->Flush ();
+ printf ("(II) VFSCopyFromLocal: copy OK, archive closed = %d.\n", globs->zip->IsClosed ());
+ build_global_filelist (globs);
+ globs->archive_modified = TRUE;
/*
// Encrypt the file if archive contains any encrypted files
@@ -991,39 +1063,38 @@ TVFSResult VFSCopyFromLocal(struct TVFSGlobs *globs, const char *sSrcName, const
}
*/
- free(s);
+ g_free (s);
}
catch (CZipException e) {
- globs->zip->CloseNewFile(true);
- globs->zip->CloseFile(NULL, true);
- build_global_filelist(globs);
- fprintf(stderr, "(EE) VFSCopyFromLocal: Error while copying in: [%d] %s, archive closed = %d.\n",
- e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
+ globs->zip->CloseNewFile (true);
+ globs->zip->CloseFile (NULL, true);
+ build_global_filelist (globs);
+ fprintf (stderr, "(EE) VFSCopyFromLocal: Error while copying in: [%d] %s, archive closed = %d.\n",
+ e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
switch (e.m_iCause) {
case CZipException::badPassword:
if (globs->callback_ask_password) {
- char *passwd = NULL;
- int res = globs->callback_ask_password ("The archive is encrypted and requires password",
- NULL, NULL, NULL, (TVFSAskPasswordFlags)(VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE),
- NULL, &passwd, NULL, NULL, NULL,
- globs->callback_data);
+ passwd = NULL;
+ res = globs->callback_ask_password ("The archive is encrypted and requires password",
+ NULL, NULL, NULL, (TVFSAskPasswordFlags)(VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE),
+ NULL, &passwd, NULL, NULL, NULL,
+ globs->callback_data);
if (res && passwd) {
- fprintf(stderr, " (II) VFSCopyFromLocal: setting password to '%s'\n", passwd);
- globs->zip->SetPassword(passwd);
+ fprintf (stderr, " (II) VFSCopyFromLocal: setting password to '%s'\n", passwd);
+ globs->zip->SetPassword (passwd);
try_again = TRUE;
break;
} else
return cVFS_Cancelled;
}
default:
- return get_vfs_errorcode(e.m_iCause);
+ return get_vfs_errorcode (e.m_iCause);
}
}
} while (try_again);
}
- catch (...)
- {
- fprintf(stderr, "(EE) VFSCopyFromLocal: Fatal error while copying in..., archive closed = %d.\n", globs->zip->IsClosed());
+ catch (...) {
+ fprintf (stderr, "(EE) VFSCopyFromLocal: Fatal error while copying in..., archive closed = %d.\n", globs->zip->IsClosed());
return cVFS_WriteErr;
}