summaryrefslogtreecommitdiff
path: root/libarchive
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-10-05 11:04:26 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-10-05 11:04:26 +0200
commitd0caac91ac0a03e021d50d1de978733e11ba2ccd (patch)
treeb763e376e8f289baaccf332398d9354663115792 /libarchive
parentc41d3e7d896492dd70cd1d548ef4fd5b3cbe4954 (diff)
downloadtuxcmd-modules-d0caac91ac0a03e021d50d1de978733e11ba2ccd.tar.xz
VFS API break: Introduce FDisplayName propertyv0.6.52
Diffstat (limited to 'libarchive')
-rw-r--r--libarchive/libarchive.c98
1 files changed, 50 insertions, 48 deletions
diff --git a/libarchive/libarchive.c b/libarchive/libarchive.c
index ae7409e..dac84d4 100644
--- a/libarchive/libarchive.c
+++ b/libarchive/libarchive.c
@@ -1,12 +1,12 @@
/* libarchive plugin for Tux Commander
- * version 0.0.7, designed for libarchive 2.5.5
+ * version 0.1.0, designed for libarchive 2.5.5
* Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
* Check for updates on tuxcmd.sourceforge.net
*
* Uses libarchive library
* Copyright (c) 2003-2007 Tim Kientzle
- *
- *
+ *
+ *
* This program is free software; you can redistribute it and/or modify
@@ -47,8 +47,8 @@
-#define VERSION "0.0.7"
-#define BUILD_DATE "2008-09-15"
+#define VERSION "0.1.0"
+#define BUILD_DATE "2008-10-05"
#define DEFAULT_BLOCK_SIZE 65536
@@ -57,7 +57,7 @@
/******************************************************************************************************/
/** Auxiliary classes */
-/************** ****************/
+/************** ****************/
@@ -68,10 +68,10 @@ struct TVFSGlobs {
char *archive_path;
unsigned long block_size;
-
+
struct PathTree *files;
struct VfsFilelistData *vfs_filelist;
-
+
u_int64_t total_size;
};
@@ -102,7 +102,7 @@ void VFSDestroy(struct TVFSGlobs *globs)
int VFSVersion()
{
- return 3;
+ return cVFSVersion;
}
struct TVFSInfo VFSGetInfo()
@@ -111,7 +111,7 @@ struct TVFSInfo VFSGetInfo()
module_info.Name = "libarchive plugin";
module_info.Description = "libarchive archiving plugin";
char *s = (char*)malloc(255);
- snprintf(s, 255, "version %s, build date: %s\nusing %s\n",
+ snprintf(s, 255, "version %s, build date: %s\nusing %s\n",
VERSION, BUILD_DATE, ARCHIVE_LIBRARY_VERSION);
module_info.About = strdup(s);
free(s);
@@ -178,14 +178,14 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
globs->archive_path = strdup(sName);
globs->total_size = 0;
fprintf(stderr, "(--) VFSOpen: trying to open archive '%s'...\n", globs->archive_path);
-
+
TVFSResult Result;
struct archive *a;
struct archive_entry *entry;
int r;
-
+
Result = libarchive_open(&a, globs->archive_path, globs->block_size);
- if (Result == cVFS_OK)
+ if (Result == cVFS_OK)
{
for (;;) {
entry = NULL;
@@ -201,16 +201,16 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
Result = cVFS_Failed;
break;
}
-
+
log("found file: %s, mode = %x\n", archive_entry_pathname(entry), archive_entry_mode(entry));
-
+
// 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 = (u_int64_t)archive_entry_size(entry);
globs->total_size += item->iSize;
-
+
mode_t mode = archive_entry_mode(entry);
item->iMode = archive_entry_mode(entry);
if (S_ISREG(mode)) item->ItemType = vRegular;
@@ -223,14 +223,14 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
if (item->ItemType == vSymlink)
item->sLinkTo = strdup(archive_entry_symlink(entry));
-
+
item->iUID = geteuid();
item->iGID = getegid();
item->m_time = archive_entry_mtime(entry);
item->c_time = archive_entry_ctime(entry);
item->a_time = archive_entry_atime(entry);
-
- // Add item to the global list and continue with next file
+
+ // Add item to the global list and continue with next file
filelist_tree_add_item(globs->files, archive_entry_pathname(entry), item, 0);
}
archive_read_close(a);
@@ -238,12 +238,12 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
archive_read_finish(a);
fprintf(stderr, "(II) VFSOpen: done. \n");
- /* FIXME: temporarily disabled */
+ /* FIXME: temporarily disabled */
// filelist_tree_resolve_symlinks(globs->files);
printf("\n\nList of items:\n");
filelist_tree_print(globs->files);
-
+
return Result;
}
@@ -256,7 +256,7 @@ TVFSResult VFSClose(struct TVFSGlobs *globs)
if (globs->files) filelist_tree_free(globs->files);
if (globs->archive_path) free(globs->archive_path);
if (globs->curr_dir) free(globs->curr_dir);
- }
+ }
return cVFS_OK;
}
@@ -286,7 +286,7 @@ TVFSResult VFSChangeDir(struct TVFSGlobs *globs, char *NewPath)
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;
@@ -319,26 +319,26 @@ TVFSResult VFSListFirst(struct TVFSGlobs *globs, char *sDir, struct TVFSItem *It
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);
}
TVFSResult VFSListNext(struct TVFSGlobs *globs, char *sDir, struct TVFSItem *Item)
{
- return vfs_filelist_list_next(globs->vfs_filelist, sDir, Item);
+ return vfs_filelist_list_next(globs->vfs_filelist, sDir, Item);
}
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);
+ 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)
@@ -351,7 +351,7 @@ TVFSResult VFSFileInfo(struct TVFSGlobs *globs, char *AFileName, struct TVFSItem
/******************************************************************************************************/
/** Recursive tree size counting */
-/************** ****************/
+/************** ****************/
u_int64_t VFSGetDirSize(struct TVFSGlobs *globs, char *APath)
{
@@ -368,7 +368,7 @@ void VFSBreakGetDirSize(struct TVFSGlobs *globs)
/******************************************************************************************************/
/** Methods modifying the archive */
-/************** ****************/
+/************** ****************/
TVFSResult VFSMkDir(struct TVFSGlobs *globs, const char *sDirName)
{
@@ -486,18 +486,18 @@ my_archive_read_data_into_fd(struct archive *a, struct archive_entry *entry, con
off_t output_offset;
u_int64_t file_size;
gboolean cancel = FALSE;
-
-
+
+
printf("(II) my_archive_read_data_into_fd: extracting to '%s', Append = %d\n", sDstName, Append);
if (Append) fd = open(sDstName, O_APPEND | O_WRONLY);
- else fd = open(sDstName, O_CREAT | O_WRONLY | O_TRUNC,
+ else 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;
}
-
+
total_written = 0;
output_offset = 0;
file_size = (u_int64_t)archive_entry_size(entry);
@@ -522,7 +522,7 @@ my_archive_read_data_into_fd(struct archive *a, struct archive_entry *entry, con
total_written += bytes_written;
p += bytes_written;
size -= bytes_written;
-
+
log(" (II) my_archive_read_data_into_fd: bytes_written = %u, total_written = %u\n", bytes_written, total_written);
if (pCallBackProgress) {
if (! pCallBackProgress(total_written, file_size, data)) {
@@ -547,14 +547,14 @@ my_archive_read_data_into_fd(struct archive *a, struct archive_entry *entry, con
return cVFS_OK;
}
-
+
TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, TVFSCopyCallBackFunc pCallBackProgress, void *data, int Append)
{
if ((sSrcName == NULL) || (sDstName == NULL) || (strlen(sSrcName) < 1) || (strlen(sDstName) < 1)) {
printf("(EE) VFSCopyOut: The value of 'sSrcName' or 'sDstName' is NULL or empty\n");
return cVFS_Failed;
}
-
+
printf("(II) VFSCopyOut: copying file '%s' out to '%s'\n", sSrcName, sDstName);
char *src;
@@ -562,14 +562,14 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
else src = g_strdup(sSrcName);
printf("(II) VFSCopyOut: new src path: '%s'\n", src);
-
+
TVFSResult Result;
struct archive *a;
struct archive_entry *entry;
int r;
-
+
Result = libarchive_open(&a, globs->archive_path, globs->block_size);
- if (Result == cVFS_OK)
+ if (Result == cVFS_OK)
{
for (;;) {
entry = NULL;
@@ -585,18 +585,18 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
Result = cVFS_Failed;
break;
}
-
+
// printf ("found file: %s, mode = %x\n", archive_entry_pathname(entry), archive_entry_mode(entry));
- char *ssrc = src;
+ char *ssrc = src;
const char *asrc = archive_entry_pathname(entry);
if (IS_DIR_SEP(*ssrc)) ssrc++;
- if (IS_DIR_SEP(*asrc)) asrc++;
+ if (IS_DIR_SEP(*asrc)) asrc++;
// printf ("strcmp: '%s' vs. '%s'\n", ssrc, asrc);
if (strcmp(ssrc, asrc) == 0) {
// printf("--> found file, extracting\n");
fprintf(stderr, "(II) VFSCopyOut: extract_file_path(sDstName) = '%s', extract_file_name(sDstName) = '%s' \n", extract_file_path(sDstName), extract_file_name(sDstName));
-
+
Result = my_archive_read_data_into_fd(a, entry, sDstName, globs->block_size, pCallBackProgress, data, Append);
break;
}
@@ -605,7 +605,7 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
}
archive_read_finish(a);
g_free(src);
-
+
fprintf(stderr, "(II) VFSCopyOut: finished. \n");
return Result;
}
@@ -621,8 +621,10 @@ TVFSResult VFSCopyIn(struct TVFSGlobs *globs, const char *sSrcName, const char *
/**********
* TODO:
+ *
+ * - UTF-8, FName/FDisplayName and absolute/relative paths revision needed!
* - archive testing (needs new VFS API)
* - write support
* - support creating new archives (needs new VFS API)
- *
+ *
***/