diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-12-13 14:36:33 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-12-13 14:36:33 +0100 |
| commit | e42a4ff3031aa1c1aaf27aa34d9395fec185924b (patch) | |
| tree | 51987665008a0f7a28c1351aaa4bb2eb1e37c46f /zip/zip.cpp | |
| parent | 016687cc49c811589951ebd064a86bdde1405866 (diff) | |
| download | tuxcmd-modules-e42a4ff3031aa1c1aaf27aa34d9395fec185924b.tar.xz | |
Error system transformation to GErrorv0.6.74
Diffstat (limited to 'zip/zip.cpp')
| -rw-r--r-- | zip/zip.cpp | 389 |
1 files changed, 224 insertions, 165 deletions
diff --git a/zip/zip.cpp b/zip/zip.cpp index 8e2e1e7..e7dc7ed 100644 --- a/zip/zip.cpp +++ b/zip/zip.cpp @@ -1,5 +1,5 @@ /* ZIP plugin for Tux Commander - * version 0.6.1, designed for ZipArchive v3.2.0 + * version 0.6.2, designed for ZipArchive v3.2.0 * Copyright (C) 2004-2009 Tomas Bzatek <tbzatek@users.sourceforge.net> * Check for updates on tuxcmd.sourceforge.net * @@ -34,6 +34,7 @@ #include <fnmatch.h> #include <unistd.h> #include <glib.h> +#include <gio/gio.h> #include "tuxcmd-vfs.h" #include "strutils.h" @@ -47,59 +48,80 @@ -#define VERSION "0.6.1" -#define BUILD_DATE "2009-11-29" +#define VERSION "0.6.2" +#define BUILD_DATE "2009-12-13" #define DEFAULT_BLOCK_SIZE 65536 using namespace std; extern "C" { + /******************************************************************************************************/ /** Utilities */ /************** ****************/ -static TVFSResult -get_vfs_errorcode (int m_iCause) +static void +zip_error_to_gerror (CZipException e, GError **error) { - switch (m_iCause) { - case 13: return cVFS_WriteErr; // Permission denied - case CZipException::noError: return cVFS_WriteErr; // No error. - case CZipException::genericError: return cVFS_WriteErr; // An unknown error. - case CZipException::badZipFile: return cVFS_ReadErr; // Damaged or not a zip file. - case CZipException::badCrc: return cVFS_ReadErr; // Crc is mismatched. - case CZipException::noCallback: return cVFS_Failed; // There is no spanned archive callback object set. - case CZipException::aborted: return cVFS_Failed; // The disk change callback method returned false. - case CZipException::abortedAction: return cVFS_Failed; // The action callback method returned false. - case CZipException::abortedSafely: return cVFS_Failed; // The action callback method returned false, but the data is not corrupted. - case CZipException::nonRemovable: return cVFS_WriteErr; // The device selected for the spanned archive is not removable. - case CZipException::tooManyVolumes: return cVFS_WriteErr; // The limit of the maximum volumes reached. - case CZipException::tooManyFiles: return cVFS_ReadErr; // The limit of the maximum files in an archive reached. - case CZipException::tooLongData: return cVFS_ReadErr; // The filename, the comment or the local or central extra field of the file added to the archive is too long. - case CZipException::tooBigSize: return cVFS_ReadErr; // The file size is too large to be supported. - case CZipException::badPassword: return cVFS_ReadErr; // An incorrect password set for the file being decrypted. - case CZipException::dirWithSize: return cVFS_ReadErr; // The directory with a non-zero size found while testing. - case CZipException::internalError: return cVFS_WriteErr; // An internal error. - case CZipException::notRemoved: return cVFS_WriteErr; // Error while removing a file - case CZipException::notRenamed: return cVFS_WriteErr; // Error while renaming a file (under Windows call GetLastError() to find out more). - case CZipException::platfNotSupp: return cVFS_WriteErr; // Cannot create a file for the specified platform. - case CZipException::cdirNotFound: return cVFS_ReadErr; // The central directory was not found in the archive (or you were trying to open not the last disk of a segmented archive). + gint code; + + switch (e.m_iCause) { + case CZipException::noError: // No error. + code = G_IO_ERROR_UNKNOWN; + break; + case CZipException::genericError: // An unknown error. + case CZipException::badCrc: // Crc is mismatched. + case CZipException::internalError: // An internal error. + case CZipException::badPassword: // An incorrect password set for the file being decrypted. + case CZipException::dirWithSize: // The directory with a non-zero size found while testing. + case CZipException::streamEnd: // Zlib library error. + case CZipException::needDict: // Zlib library error. + case CZipException::errNo: // Zlib library error. + case CZipException::streamError: // Zlib library error. + case CZipException::dataError: // Zlib library error. + case CZipException::memError: // Zlib library or CZipMemFile error. + case CZipException::bufError: // Zlib library error. + code = G_IO_ERROR_FAILED; + break; + case CZipException::badZipFile: // Damaged or not a zip file. + code = G_IO_ERROR_NOT_MOUNTABLE_FILE; + break; + case CZipException::aborted: // The disk change callback method returned false. + case CZipException::abortedAction: // The action callback method returned false. + case CZipException::abortedSafely: // The action callback method returned false, but the data is not corrupted. + code = G_IO_ERROR_CANCELLED; + break; + case CZipException::nonRemovable: // The device selected for the spanned archive is not removable. + case CZipException::tooManyVolumes: // The limit of the maximum volumes reached. + case CZipException::tooManyFiles: // The limit of the maximum files in an archive reached. + case CZipException::tooLongData: // The filename, the comment or the local or central extra field of the file added to the archive is too long. + case CZipException::tooBigSize: // The file size is too large to be supported. + code = G_IO_ERROR_NOT_SUPPORTED; + break; + + case CZipException::notRemoved: // Error while removing a file + case CZipException::notRenamed: // Error while renaming a file (under Windows call GetLastError() to find out more). + code = G_IO_ERROR_NOT_EMPTY; + break; + case CZipException::cdirNotFound: // The central directory was not found in the archive (or you were trying to open not the last disk of a segmented archive). + code = G_IO_ERROR_NOT_FOUND; + break; // case CZipException::cdir64NotFound: return cVFS_ReadErr; // The Zip64 central directory signature was not found in the archive where expected. // case CZipException::noBBZInZip64: return cVFS_ReadErr; // The number of bytes before a zip archive must be zero in the Zip64 format. // case CZipException::badAesAuthCode: return cVFS_ReadErr; // Mismatched authentication code in WinZip AEC decrypted data. - case CZipException::noZip64: return cVFS_ReadErr; // The Zip64 format has not been enabled for the library, but is required to open the archive. - case CZipException::noAES: return cVFS_ReadErr; // WinZip AES encryption has not been enabled for the library, but is required to decompress the archive. - case CZipException::outOfBounds: return cVFS_ReadErr; // The collection is empty and the bounds do not exist. + case CZipException::platfNotSupp: // Cannot create a file for the specified platform. + case CZipException::noZip64: // The Zip64 format has not been enabled for the library, but is required to open the archive. + case CZipException::noAES: // WinZip AES encryption has not been enabled for the library, but is required to decompress the archive. + code = G_IO_ERROR_NOT_SUPPORTED; + break; + case CZipException::noCallback: // There is no spanned archive callback object set. + case CZipException::outOfBounds: // The collection is empty and the bounds do not exist. + case CZipException::versionError: // Zlib library error. + code = G_IO_ERROR_INVALID_ARGUMENT; + break; // case CZipException::mutexError: return cVFS_ReadErr; // Locking or unlocking resources access was unsuccessful. - case CZipException::streamEnd: return cVFS_ReadErr; // Zlib library error. - case CZipException::needDict: return cVFS_ReadErr; // Zlib library error. - case CZipException::errNo: return cVFS_ReadErr; // Zlib library error. - case CZipException::streamError: return cVFS_ReadErr; // Zlib library error. - case CZipException::dataError: return cVFS_ReadErr; // Zlib library error. - case CZipException::memError: return cVFS_ReadErr; // Zlib library or CZipMemFile error. - case CZipException::bufError: return cVFS_ReadErr; // Zlib library error. - case CZipException::versionError: return cVFS_ReadErr; // Zlib library error. // case CZipException::bzSequenceError: return cVFS_ReadErr; // Bzlib library error. // case CZipException::bzParamError: return cVFS_ReadErr; // Bzlib library error. // case CZipException::bzMemError: return cVFS_ReadErr; // Bzlib library error. @@ -110,8 +132,11 @@ get_vfs_errorcode (int m_iCause) // case CZipException::bzOutbuffFull: return cVFS_ReadErr; // Bzlib library error. // case CZipException::bzConfigError: return cVFS_ReadErr; // Bzlib library error. // case CZipException::bzInternalError: return cVFS_ReadErr; // Internal Bzlib library error. - default: return cVFS_WriteErr; - } + default: + code = G_IO_ERROR_FAILED; + break; + } + g_set_error_literal (error, G_IO_ERROR, code, (LPCTSTR)e.GetErrorDescription()); } @@ -164,7 +189,7 @@ struct ZIP_API CVFSZipActionCallback : public CZipActionCallback bool ret = true; try { if (globs && globs->callback_progress) - ret = globs->callback_progress (m_uProcessed, m_uTotalToProcess, globs->callback_data); + ret = globs->callback_progress (m_uProcessed, NULL, globs->callback_data); } catch (...) { fprintf (stderr, "(EE) extract_callback: Fatal error occured when calling pCallBackProgress\n"); @@ -338,8 +363,8 @@ VFSGetArchiveExts () /**************************************************************************************************************************************/ /**************************************************************************************************************************************/ -TVFSResult -VFSOpenArchive (struct TVFSGlobs *globs, const char *sName) +gboolean +VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error) { int iCount; @@ -355,7 +380,8 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName) try { if (! globs->zip->Open (sName, CZipArchive::zipOpen, 0)) { printf ("(EE) VFSOpenArchive: error opening zip archive\n"); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error opening zip archive."); + return FALSE; } } catch (...) { @@ -364,18 +390,22 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName) /* 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; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error opening readonly zip archive."); + return FALSE; } } - catch (...) { + catch (CZipException e) { printf ("(EE) VFSOpenArchive: error opening readonly zip\n"); - return cVFS_Failed; + zip_error_to_gerror (e, error); + return FALSE; } } 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; + if (iCount < 1) { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No files found in the archive."); + return FALSE; + } /* build global file list */ build_global_filelist (globs); @@ -396,22 +426,24 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName) else printf ("(EE) VFSOpenArchive: Filename in error object: %s\n\n", (LPCTSTR)e.m_szFileName); globs->zip->Close (true); - return cVFS_Failed; + zip_error_to_gerror (e, error); + return FALSE; } catch (...) { printf ("(EE) VFSOpenArchive: Unknown error while processing archive %s\n\n", (LPCTSTR) sName); globs->zip->Close (true); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown error while processing zip archive."); + return FALSE; } globs->archive_path = g_strdup (sName); globs->archive_modified = FALSE; - return cVFS_OK; + return TRUE; } -TVFSResult -VFSClose (struct TVFSGlobs *globs) +gboolean +VFSClose (struct TVFSGlobs *globs, GError **error) { if (globs) { /* close the archive... */ @@ -420,14 +452,15 @@ VFSClose (struct TVFSGlobs *globs) 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 + * (use when an exception was thrown, the 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; + zip_error_to_gerror (e, error); + return FALSE; } /* free the ZIP objects... */ @@ -438,7 +471,8 @@ VFSClose (struct TVFSGlobs *globs) } catch (...) { fprintf (stderr, "(EE) VFSClose: Error freeing ZipArchive objects\n"); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error freeing ZipArchive objects."); + return FALSE; } /* free the filelist */ @@ -451,7 +485,7 @@ VFSClose (struct TVFSGlobs *globs) /* free the rest... */ g_free (globs->archive_path); } - return cVFS_OK; + return TRUE; } char * @@ -460,7 +494,7 @@ VFSGetPath (struct TVFSGlobs *globs) return g_strdup (globs->curr_dir); } -TVFSResult +void VFSGetFileSystemInfo (struct TVFSGlobs *globs, const char *APath, gint64 *FSSize, gint64 *FSFree, char **FSLabel) { if (FSSize) @@ -469,25 +503,23 @@ VFSGetFileSystemInfo (struct TVFSGlobs *globs, const char *APath, gint64 *FSSize *FSFree = 0; if (FSLabel) *FSLabel = NULL; - return cVFS_OK; } /******************************************************************************************************/ -TVFSResult -VFSChangeDir (struct TVFSGlobs *globs, const char *NewPath) +gboolean +VFSChangeDir (struct TVFSGlobs *globs, const char *NewPath, GError **error) { - if (NewPath == NULL) { - printf ("(EE) VFSChangeDir: NewPath is NULL!\n"); - return cVFS_Failed; - } + char *s; - globs->curr_dir = vfs_filelist_change_dir (globs->vfs_filelist, NewPath); - if (globs->curr_dir) - return cVFS_OK; + s = vfs_filelist_change_dir (globs->vfs_filelist, NewPath, error); + if (s) { + globs->curr_dir = s; + return TRUE; + } else - return cVFS_Failed; + return FALSE; } gboolean @@ -508,40 +540,35 @@ VFSResetPassword (struct TVFSGlobs *globs) /******************************************************************************************************/ -TVFSResult -VFSListFirst (struct TVFSGlobs *globs, const char *sDir, struct TVFSItem *Item, gboolean FollowSymlinks, gboolean AddFullPath) +struct TVFSItem * +VFSListFirst (struct TVFSGlobs *globs, const char *sDir, gboolean FollowSymlinks, gboolean AddFullPath, GError **error) { - if (sDir == NULL) { - 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, FollowSymlinks, AddFullPath); + return vfs_filelist_list_first (globs->vfs_filelist, sDir, FollowSymlinks, AddFullPath, error); } -TVFSResult -VFSListNext (struct TVFSGlobs *globs, struct TVFSItem *Item) +struct TVFSItem * +VFSListNext (struct TVFSGlobs *globs, GError **error) { - return vfs_filelist_list_next (globs->vfs_filelist, Item); + return vfs_filelist_list_next (globs->vfs_filelist, error); } -TVFSResult -VFSListClose (struct TVFSGlobs *globs) +gboolean +VFSListClose (struct TVFSGlobs *globs, GError **error) { - return vfs_filelist_list_close (globs->vfs_filelist); + return vfs_filelist_list_close (globs->vfs_filelist, error); } /******************************************************************************************************/ -TVFSResult -VFSFileInfo (struct TVFSGlobs *globs, const char *AFileName, struct TVFSItem *Item, gboolean FollowSymlinks, gboolean AddFullPath) +struct TVFSItem * +VFSFileInfo (struct TVFSGlobs *globs, const char *AFileName, gboolean FollowSymlinks, gboolean AddFullPath, GError **error) { 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); + + return vfs_filelist_file_info (globs->vfs_filelist, AFileName, FollowSymlinks, AddFullPath, error); } /******************************************************************************************************/ @@ -569,8 +596,8 @@ VFSBreakGetDirSize (struct TVFSGlobs *globs) /** Methods modifying the archive */ /************** ****************/ -TVFSResult -VFSMkDir (struct TVFSGlobs *globs, const char *sDirName) +gboolean +VFSMkDir (struct TVFSGlobs *globs, const char *sDirName, GError **error) { CZipFileHeader header; char *s; @@ -578,11 +605,13 @@ 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; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "The value of 'sDirName' is NULL or empty."); + return FALSE; } if (strcmp (sDirName, "/") == 0) { - printf ("(EE) VFSMkDir: Invalid value '%s' (duplicate root entry?)\n", sDirName); - return cVFS_Failed; + printf ("(EE) VFSMkDir: Invalid value '%s' (duplicate the root entry?)\n", sDirName); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid value '%s' (duplicate the root entry?)", sDirName); + return FALSE; } printf ("(II) VFSMkDir: Going to create new directory '%s'...\n", sDirName); @@ -598,29 +627,32 @@ VFSMkDir (struct TVFSGlobs *globs, const char *sDirName) globs->zip->CloseNewFile (); if (! bRet) { printf ("(EE) VFSMkDir: Error creating new directory '%s'\n", sDirName); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error creating new directory."); + return FALSE; } globs->archive_modified = TRUE; build_global_filelist (globs); - return cVFS_OK; + return TRUE; } 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); + zip_error_to_gerror (e, error); + return FALSE; } } catch (...) { printf ("(EE) VFSMkDir: Error creating new directory '%s'\n", sDirName); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error creating new directory."); + return FALSE; } } -TVFSResult -VFSRemove (struct TVFSGlobs *globs, const char *APath) +gboolean +VFSRemove (struct TVFSGlobs *globs, const char *APath, GError **error) { char *AFile, *AFile1, *AFile2, *AFile3; long int file_no; @@ -634,14 +666,16 @@ VFSRemove (struct TVFSGlobs *globs, const char *APath) if (file_no < 0) { printf ("(EE) VFSRemove: can't find the file specified: '%s'\n", APath); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Can't find the file specified."); + return FALSE; } try { try { if (! globs->zip->RemoveFile (file_no)) { printf ("(EE) VFSRemove: Delete file '%s' failed.\n", APath); - return cVFS_Failed; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Delete file '%s' failed.", APath); + return FALSE; } build_global_filelist (globs); globs->archive_modified = TRUE; @@ -659,31 +693,33 @@ VFSRemove (struct TVFSGlobs *globs, const char *APath) 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); + VFSMkDir (globs, AFile3, NULL); } } g_free (AFile1); g_free (AFile2); g_free (AFile3); - return cVFS_OK; + return TRUE; } 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); + zip_error_to_gerror (e, error); + return FALSE; } } catch (...) { printf ("(EE) VFSRemove: Delete file '%s' failed.\n", APath); - return cVFS_Failed; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Delete file '%s' failed.", APath); + return FALSE; } } -TVFSResult -VFSRename (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName) +gboolean +VFSRename (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, GError **error) { char *AFile; char *ADestFile; @@ -698,44 +734,49 @@ VFSRename (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName) if (file_no < 0) { printf ("(EE) VFSRename: can't find the file specified: '%s'\n", sSrcName); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Can't find the file specified."); + return FALSE; } try { try { if (! globs->zip->RenameFile (file_no, ADestFile)) { printf ("(EE) VFSRename: Rename/move file '%s' failed.\n", sSrcName); - return cVFS_Failed; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Rename/move file '%s' failed.", sSrcName); + return FALSE; } g_free (ADestFile); build_global_filelist (globs); globs->archive_modified = TRUE; - return cVFS_OK; + return TRUE; } 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); + zip_error_to_gerror (e, error); + return FALSE; } } catch (...) { printf ("(EE) VFSRename: Rename/move file failed.\n"); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Rename/move file failed."); + return FALSE; } } -TVFSResult -VFSMakeSymLink (struct TVFSGlobs *globs, const char *NewFileName, const char *PointTo) +gboolean +VFSMakeSymLink (struct TVFSGlobs *globs, const char *NewFileName, const char *PointTo, GError **error) { fprintf (stderr, "(EE) VFSMakeSymLink: Symbolic links not supported in ZIP archives.\n"); - return cVFS_Not_Supported; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Symbolic links not supported in ZIP archives."); + return FALSE; } -TVFSResult -VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode) +gboolean +VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode, GError **error) { char *AFile; long int file_no; @@ -749,7 +790,8 @@ VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode) if (file_no < 0) { printf ("(EE) VFSChmod: can't find the file specified: '%s'\n", FileName); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Can't find the file specified."); + return FALSE; } try { @@ -764,7 +806,8 @@ VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode) header = globs->zip->GetFileInfo (file_no); if (! header) { printf ("(EE) VFSChmod: Permissions modification of the file '%s' failed: NULL returned by GetFileInfo()\n", FileName); - return cVFS_Failed; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Permissions modification of the file '%s' failed: NULL returned by GetFileInfo()", FileName); + return FALSE; } // We need to change only 0xF000FFFF mask // The 0xF_______ bits represents file/directory type, the 0x____FFFF represents ZIP attributes and 0x_FFF____ represents unix permissions @@ -795,33 +838,36 @@ VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode) printf ("(II) VFSChmod OK.\n"); build_global_filelist (globs); globs->archive_modified = TRUE; - return cVFS_OK; + return TRUE; } catch (CZipException e) { 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); + zip_error_to_gerror (e, error); + return FALSE; } } catch (...) { printf ("(EE) VFSChmod: permissions modification of the file '%s' failed.\n", FileName); - return cVFS_Failed; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Permissions modification of the file '%s' failed.", FileName); + return FALSE; } } -TVFSResult -VFSChown (struct TVFSGlobs *globs, const char *FileName, guint32 UID, guint32 GID) +gboolean +VFSChown (struct TVFSGlobs *globs, const char *FileName, guint32 UID, guint32 GID, GError **error) { fprintf (stderr, "(EE) VFSChown: Owner changing is not supported in ZIP archives.\n"); - return cVFS_Not_Supported; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Owner changing is not supported in ZIP archives."); + return FALSE; } -TVFSResult -VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint32 atime) +gboolean +VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint32 atime, GError **error) { char *AFile; long int file_no; @@ -835,7 +881,8 @@ VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint if (file_no < 0) { printf ("(EE) VFSChangeTimes: can't find the file specified: '%s'\n", APath); - return cVFS_Failed; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Can't find the file specified."); + return FALSE; } try { @@ -845,7 +892,8 @@ VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint header = globs->zip->GetFileInfo (file_no); if (! header) { printf ("(EE) VFSChangeTimes: DateTime modification of the file '%s' failed: NULL returned by GetFileInfo()\n", APath); - return cVFS_Failed; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "DateTime modification of the file '%s' failed: NULL returned by GetFileInfo()", APath); + return FALSE; } /* change the header data */ header->SetTime (mtime); @@ -864,18 +912,20 @@ VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint printf ("(II) VFSChangeTimes OK.\n"); build_global_filelist (globs); globs->archive_modified = TRUE; - return cVFS_OK; + return TRUE; } 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); + zip_error_to_gerror (e, error); + return FALSE; } } catch (...) { printf ("(EE) VFSChangeTimes: DateTime modification of the file '%s' failed.\n", APath); - return cVFS_Failed; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "DateTime modification of the file '%s' failed.", APath); + return FALSE; } } @@ -884,6 +934,7 @@ VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////// +#if 0 TVFSFileDes VFSOpenFile(struct TVFSGlobs *globs, const char *APath, int Mode, int *Error) { *Error = cVFS_Not_Supported; @@ -912,6 +963,7 @@ int VFSWriteFile(struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, void *Buff *Error = cVFS_Not_Supported; return 0; } +#endif void VFSSetBlockSize (struct TVFSGlobs *globs, guint32 Value) @@ -939,26 +991,21 @@ VFSTwoSameFiles (struct TVFSGlobs *globs, const char *Path1, const char *Path2, //////////////////////// -TVFSResult -VFSStartCopyOperation (struct TVFSGlobs *globs) +gboolean +VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error) { - TVFSResult Result; - - g_return_val_if_fail (globs != NULL, cVFS_Failed); + g_return_val_if_fail (globs != NULL, FALSE); printf ("(II) VFSStartCopyOperation: doing nothing for the moment.\n"); - Result = cVFS_OK; - return Result; + return TRUE; } -TVFSResult -VFSStopCopyOperation (struct TVFSGlobs *globs) +gboolean +VFSStopCopyOperation (struct TVFSGlobs *globs, GError **error) { - TVFSResult Result; - - g_return_val_if_fail (globs != NULL, cVFS_Failed); + g_return_val_if_fail (globs != NULL, FALSE); if (globs->archive_modified) { printf ("(II) VFSStopCopyOperation: rebuilding tree.\n"); @@ -967,9 +1014,8 @@ VFSStopCopyOperation (struct TVFSGlobs *globs) } else { printf ("(II) VFSStartCopyOperation: doing nothing for the moment.\n"); } - Result = cVFS_OK; - return Result; + return TRUE; } @@ -977,8 +1023,8 @@ VFSStopCopyOperation (struct TVFSGlobs *globs) * - 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 +VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append, GError **error) { gboolean try_again; long int file_no; @@ -991,7 +1037,8 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN 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; + 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); @@ -999,7 +1046,8 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN 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); - return cVFS_ReadErr; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "cannot find file '%s'", sSrcName); + return FALSE; } s = exclude_trailing_path_sep (sDstName); @@ -1015,7 +1063,8 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN 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; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error while copying out."); + return FALSE; } fprintf (stderr, "(II) VFSCopyToLocal: copy OK, archive closed = %d.\n", globs->zip->IsClosed ()); } @@ -1036,11 +1085,14 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN globs->zip->SetPassword (passwd); try_again = TRUE; break; - } else - return cVFS_Cancelled; + } else { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Operation has been cancelled."); + return FALSE; + } } default: - return get_vfs_errorcode (e.m_iCause); + zip_error_to_gerror (e, error); + return FALSE; } } } while (try_again); @@ -1048,12 +1100,13 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN catch (...) { fprintf (stderr, "(EE) VFSCopyToLocal: Fatal error while copying out..., archive closed = %d.\n", globs->zip->IsClosed()); - return cVFS_WriteErr; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Fatal error while copying out."); + return FALSE; } g_free (dest_path); g_free (dest_filename); - return cVFS_OK; + return TRUE; } @@ -1062,8 +1115,8 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN * - encrypted files are unreadable after copy in * **/ -TVFSResult -VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append) +gboolean +VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append, GError **error) { gboolean try_again; char *s; @@ -1072,7 +1125,8 @@ VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDs 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; + 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) VFSCopyFromLocal: copying file '%s' in to '%s'\n", sSrcName, sDstName); @@ -1086,7 +1140,8 @@ VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDs globs->zip->CloseNewFile (true); globs->zip->CloseFile (NULL, true); fprintf (stderr, "(EE) VFSCopyFromLocal: Error while copying in, archive closed = %d.\n", globs->zip->IsClosed ()); - return cVFS_WriteErr; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error while copying in."); + return FALSE; } printf ("(II) VFSCopyFromLocal: copy OK, archive closed = %d.\n", globs->zip->IsClosed ()); @@ -1126,21 +1181,25 @@ VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDs globs->zip->SetPassword (passwd); try_again = TRUE; break; - } else - return cVFS_Cancelled; + } else { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Operation has been cancelled."); + return FALSE; + } } default: - return get_vfs_errorcode (e.m_iCause); + zip_error_to_gerror (e, error); + return FALSE; } } } while (try_again); } catch (...) { fprintf (stderr, "(EE) VFSCopyFromLocal: Fatal error while copying in..., archive closed = %d.\n", globs->zip->IsClosed()); - return cVFS_WriteErr; + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Fatal error while copying in."); + return FALSE; } - return cVFS_OK; + return TRUE; } |
