summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2013-05-20 12:05:10 +0200
committerportix <portix@gmx.net>2013-05-20 12:05:10 +0200
commit7c054ff422b42b712bfaa6d3a526b8c864b2310b (patch)
treea57706dd6c662672f659f1cd315ac4717f193f7c
parenta7e6d0c76a2ff20afe944e9211ec4f6deba37cba (diff)
downloaddwb-7c054ff422b42b712bfaa6d3a526b8c864b2310b.zip
Implementing exar_append
-rw-r--r--dwbem/dwbem.c63
-rw-r--r--exar/exar.c48
-rw-r--r--exar/exar.h12
3 files changed, 77 insertions, 46 deletions
diff --git a/dwbem/dwbem.c b/dwbem/dwbem.c
index 98be3455..12a3f944 100644
--- a/dwbem/dwbem.c
+++ b/dwbem/dwbem.c
@@ -64,16 +64,17 @@
#define FREE0(X) (X == NULL ? NULL : (X = (g_free(X), NULL)))
enum {
- EXAR_FLAG_V = 1<<0,
- EXAR_FLAG_P = 1<<3,
- EXAR_FLAG_U = 1<<4,
- EXAR_FLAG_E = 1<<6,
- EXAR_FLAG_D = 1<<7,
- EXAR_FLAG_L = 1<<8,
- EXAR_FLAG_S = 1<<9,
+ EXAR_FLAG_v = 1<<0,
+ EXAR_FLAG_p = 1<<3,
+ EXAR_FLAG_u = 1<<4,
+ EXAR_FLAG_e = 1<<6,
+ EXAR_FLAG_d = 1<<7,
+ EXAR_FLAG_l = 1<<8,
+ EXAR_FLAG_s = 1<<9,
+ EXAR_FLAG_a = 1<<10,
};
#define EXAR_OPTION_FLAG (0xffff & ~(0x7))
-#define EXAR_CHECK_FLAG(x, flag) !!(((x) & (flag)) && !((x) & ( (EXAR_OPTION_FLAG)^(flag) ) ))
+#define EXAR_CHECK_FLAG(x, flag) !!(((x) & (EXAR_FLAG_##flag)) && !((x) & ( (EXAR_OPTION_FLAG)^(EXAR_FLAG_##flag) ) ))
enum
{
@@ -1169,6 +1170,7 @@ exar_help(int ret)
" dwbem --archive option [arguments]\n\n"
"OPTIONS:\n"
" h Print this help and exit.\n"
+ " a[v] archive file Appends a file or directory to an archive\n"
" d[v] archive file Deletes a file from an archive, the file path is the\n"
" relative file path of the file in the archive\n"
" e[v] archive file Extracts a file from an archive and writes the content\n"
@@ -1221,26 +1223,29 @@ parse_exar_options(char **argv)
{
switch (*options)
{
- case 'p' :
- flag |= EXAR_FLAG_P;
+ case 'a' :
+ flag |= EXAR_FLAG_a;
break;
- case 'u' :
- flag |= EXAR_FLAG_U;
+ case 'd' :
+ flag |= EXAR_FLAG_d;
break;
case 'e' :
- flag |= EXAR_FLAG_E;
- break;
- case 'd' :
- flag |= EXAR_FLAG_D;
+ flag |= EXAR_FLAG_e;
break;
case 'l' :
- flag |= EXAR_FLAG_L;
+ flag |= EXAR_FLAG_l;
+ break;
+ case 'p' :
+ flag |= EXAR_FLAG_p;
break;
case 's' :
- flag |= EXAR_FLAG_S;
+ flag |= EXAR_FLAG_s;
+ break;
+ case 'u' :
+ flag |= EXAR_FLAG_u;
break;
case 'v' :
- flag |= MAX(EXAR_FLAG_V, MIN(EXAR_VERBOSE_MASK, ((flag & EXAR_VERBOSE_MASK) << 1)));
+ flag |= MAX(EXAR_FLAG_v, MIN(EXAR_VERBOSE_MASK, ((flag & EXAR_VERBOSE_MASK) << 1)));
break;
case 'h' :
exar_help(EXIT_SUCCESS);
@@ -1252,18 +1257,20 @@ parse_exar_options(char **argv)
if (flag & EXAR_VERBOSE_MASK)
exar_verbose(flag);
- if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_U))
- exar_unpack(argv[1], argv[2]);
- else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_P))
- exar_pack(argv[1]);
- else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_L))
- exar_info(argv[1]);
- else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_D) && argc > 2)
+ if (EXAR_CHECK_FLAG(flag, a) && argc > 2)
+ exar_append(argv[1], argv[2]);
+ else if (EXAR_CHECK_FLAG(flag, d) && argc > 2)
exar_delete(argv[1], argv[2]);
- else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_E) && argc > 2)
+ else if (EXAR_CHECK_FLAG(flag, e) && argc > 2)
exar_xextract(argv[1], argv[2], exar_extract);
- else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_S) && argc > 2)
+ else if (EXAR_CHECK_FLAG(flag, l))
+ exar_info(argv[1]);
+ else if (EXAR_CHECK_FLAG(flag, p))
+ exar_pack(argv[1]);
+ else if (EXAR_CHECK_FLAG(flag, s) && argc > 2)
exar_xextract(argv[1], argv[2], exar_search_extract);
+ else if (EXAR_CHECK_FLAG(flag, u))
+ exar_unpack(argv[1], argv[2]);
else
exar_help(EXIT_FAILURE);
}
diff --git a/exar/exar.c b/exar/exar.c
index 556b7e3f..90f005d6 100644
--- a/exar/exar.c
+++ b/exar/exar.c
@@ -322,7 +322,7 @@ write_file_header(FILE *f, const char *name, char flag, size_t r)
}
static int
-pack(const char *fpath, const struct stat *st, int tf)
+ftw_pack(const char *fpath, const struct stat *st, int tf)
{
(void)tf;
@@ -373,33 +373,49 @@ finish:
close_file(f, fpath);
return result;
}
+static int
+pack (const char *archive, const char *path, const char *mode)
+{
+ int ret = EE_OK;
+
+ LOG(3, "Opening %s for writing\n", archive);
+ if ((s_out = fopen(archive, mode)) == NULL)
+ {
+ perror(archive);
+ return EE_ERROR;
+ }
+
+ ret = ftw(path, ftw_pack, MAX_FILE_HANDLES);
+
+ LOG(3, "Closing %s\n", archive);
+
+ fclose(s_out);
+ return ret;
+}
int
exar_pack(const char *path)
{
assert(path != NULL);
- int ret;
- char buffer[512];
+ char archive[EXAR_NAME_MAX];
int i = 0;
- s_offset = get_offset(buffer, sizeof(buffer), path, &i);
-
- strncpy(&buffer[i], "." EXTENSION, sizeof(buffer) - i);
+ s_offset = get_offset(archive, sizeof(archive), path, &i);
- LOG(3, "Opening %s for writing\n", buffer);
- if ((s_out = fopen(buffer, "w")) == NULL)
- {
- perror(buffer);
- return EE_ERROR;
- }
+ strncpy(&archive[i], "." EXTENSION, sizeof(archive) - i);
- ret = ftw(path, pack, MAX_FILE_HANDLES);
+ return pack(archive, path, "w");
+}
+int
+exar_append(const char *archive, const char *path)
+{
+ assert(path != NULL);
+ char stripped[EXAR_NAME_MAX];
- LOG(3, "Closing %s\n", buffer);
+ s_offset = get_offset(stripped, sizeof(stripped), path, 0);
- fclose(s_out);
- return ret;
+ return pack(archive, path, "a");
}
int
diff --git a/exar/exar.h b/exar/exar.h
index cb7a489d..105610cb 100644
--- a/exar/exar.h
+++ b/exar/exar.h
@@ -40,8 +40,6 @@
#include <stdio.h>
-
-
enum {
EXAR_VERBOSE_L1 = 1<<0,
EXAR_VERBOSE_L2 = 1<<1,
@@ -59,6 +57,16 @@ int
exar_pack(const char *path);
/*
+ * Appends a file or directory to the archive
+ * @archive The archive
+ * @path The file or directory to append
+ *
+ * @returns 0 on success
+ */
+int
+exar_append(const char *archive, const char *path);
+
+/*
* Unpacks an archive
* @path: Path to the extension archive
* @dest: Destination directory or NULL for current directory