/*
* Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2008 Michael Rasmussen and the Claws Mail Team
+ * Copyright (C) 1999-2018 Michael Rasmussen and the Claws Mail Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
*/
#ifdef HAVE_CONFIG_H
#include <glib.h>
#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include "libarchive_archive.h"
#include <string.h>
#include <unistd.h>
#include <dirent.h>
-#include <glib.h>
#include <libgen.h>
#define READ_BLOCK_SIZE 10240
gdate = g_date_new();
parts = g_strsplit(date, "-", 3);
- if (! is_iso_string(parts))
- return NULL;
if (!parts)
return NULL;
+ if (! is_iso_string(parts))
+ return NULL;
for (i = 0; i < 3; i++) {
int t = atoi(parts[i]);
switch (i) {
debug_print("Cut-off date: %s\n", before);
if ((date = iso2GDate(before)) == NULL) {
- g_warning("Bad date format: %s\n", before);
+ g_warning("Bad date format: %s", before);
return FALSE;
}
}
if (! g_date_valid(file_t)) {
- g_warning("Invalid msg date\n");
+ g_warning("Invalid msg date");
return FALSE;
}
}
static gchar* strip_leading_dot_slash(gchar* path) {
- gchar* stripped = path;
- gchar* result = NULL;
+ if (path && strlen(path) > 1 && path[0] == '.' && path[1] == '/')
+ return g_strdup(&(path[2]));
- if (stripped && stripped[0] == '.') {
- ++stripped;
- if (stripped && stripped[0] == '/')
- ++stripped;
- result = g_strdup(stripped);
- }
- else
- result = g_strdup(path);
- return result;
+ return g_strdup(path);
}
static gchar* get_full_path(struct file_info* file) {
#endif
void archive_add_file(gchar* path) {
- struct file_info* file = archive_new_file_info();
+ struct file_info* file;
gchar* filename = NULL;
g_return_if_fail(path != NULL);
g_return_if_fail(filename != NULL);
filename++;
+ file = archive_new_file_info();
file->name = g_strdup(filename);
file->path = strip_leading_dot_slash(dirname(path));
archive_add_to_list(file);
const gchar* archive_create(const char* archive_name, GSList* files,
COMPRESS_METHOD method, ARCHIVE_FORMAT format) {
struct archive* arch;
- struct archive_entry* entry;
- char* buf = NULL;
- ssize_t len;
- int fd;
- struct stat st;
- struct file_info* file;
- gchar* filename = NULL;
- gchar* msg = NULL;
#ifndef _TEST
gint num = 0;
debug_print("File: %s\n", archive_name);
arch = archive_write_new();
switch (method) {
- case ZIP:
+ case GZIP:
#if ARCHIVE_VERSION_NUMBER < 3000000
if (archive_write_set_compression_gzip(arch) != ARCHIVE_OK)
#else
#endif
return archive_error_string(arch);
break;
+#if ARCHIVE_VERSION_NUMBER >= 2006990
+ case LZMA:
+#if ARCHIVE_VERSION_NUMBER < 3000000
+ if (archive_write_set_compression_lzma(arch) != ARCHIVE_OK)
+#else
+ if (archive_write_add_filter_lzma(arch) != ARCHIVE_OK)
+#endif
+ return archive_error_string(arch);
+ break;
+ case XZ:
+#if ARCHIVE_VERSION_NUMBER < 3000000
+ if (archive_write_set_compression_xz(arch) != ARCHIVE_OK)
+#else
+ if (archive_write_add_filter_xz(arch) != ARCHIVE_OK)
+#endif
+ return archive_error_string(arch);
+ break;
+#endif
+#if ARCHIVE_VERSION_NUMBER >= 3000000
+ case LZIP:
+ if (archive_write_add_filter_lzip(arch) != ARCHIVE_OK)
+ return archive_error_string(arch);
+ break;
+#endif
+#if ARCHIVE_VERSION_NUMBER >= 3001000
+ case LRZIP:
+ if (archive_write_add_filter_lrzip(arch) != ARCHIVE_OK)
+ return archive_error_string(arch);
+ break;
+ case LZOP:
+ if (archive_write_add_filter_lzop(arch) != ARCHIVE_OK)
+ return archive_error_string(arch);
+ break;
+ case GRZIP:
+ if (archive_write_add_filter_grzip(arch) != ARCHIVE_OK)
+ return archive_error_string(arch);
+ break;
+#endif
+#if ARCHIVE_VERSION_NUMBER >= 3001900
+ case LZ4:
+ if (archive_write_add_filter_lz4(arch) != ARCHIVE_OK)
+ return archive_error_string(arch);
+ break;
+#endif
case NO_COMPRESS:
#if ARCHIVE_VERSION_NUMBER < 3000000
if (archive_write_set_compression_none(arch) != ARCHIVE_OK)
return archive_error_string(arch);
while (files && ! stop_action) {
+ struct file_info* file;
+ gchar* filename = NULL;
+
#ifndef _TEST
set_progress_print_all(num++, total, 30);
#endif
#endif
}
else {
+ struct archive_entry* entry;
+ char* buf = NULL;
+ ssize_t len;
+ GError* err = NULL;
+ GStatBuf st;
+ int fd;
+ gchar* msg = NULL;
+
#ifndef _TEST
debug_print("Adding: %s\n", filename);
msg = g_strdup_printf("%s", filename);
set_progress_file_label(msg);
g_free(msg);
#endif
- entry = archive_entry_new();
- lstat(filename, &st);
- if ((fd = open(filename, O_RDONLY)) == -1) {
- perror("open file");
+ if ((fd = g_open(filename, O_RDONLY, 0)) == -1) {
+ FILE_OP_ERROR(filename, "g_open");
}
else {
- archive_entry_copy_stat(entry, &st);
- archive_entry_set_pathname(entry, filename);
- if (S_ISLNK(st.st_mode)) {
- buf = NULL;
- buf = malloc(PATH_MAX + 1);
- if ((len = readlink(filename, buf, PATH_MAX)) < 0)
- perror("error in readlink");
- else
- buf[len] = '\0';
- archive_entry_set_symlink(entry, buf);
- g_free(buf);
- archive_entry_set_size(entry, 0);
- archive_write_header(arch, entry);
- }
- else {
- if (archive_write_header(arch, entry) != ARCHIVE_OK)
- g_warning("%s", archive_error_string(arch));
- buf = NULL;
- buf = malloc(READ_BLOCK_SIZE);
- len = read(fd, buf, READ_BLOCK_SIZE);
- while (len > 0) {
- if (archive_write_data(arch, buf, len) == -1)
+ if (g_stat(filename, &st) == -1) {
+ FILE_OP_ERROR(filename, "g_stat");
+ } else {
+ entry = archive_entry_new();
+ archive_entry_copy_stat(entry, &st);
+ archive_entry_set_pathname(entry, filename);
+ if (S_ISLNK(st.st_mode)) {
+
+ buf = g_file_read_link(filename, &err);
+ if (err) {
+ FILE_OP_ERROR(filename, "g_file_read_link");
+ } else {
+ archive_entry_set_symlink(entry, buf);
+ g_free(buf);
+ archive_entry_set_size(entry, 0);
+ archive_write_header(arch, entry);
+ }
+ }
+ else {
+ if (archive_write_header(arch, entry) != ARCHIVE_OK)
g_warning("%s", archive_error_string(arch));
- memset(buf, 0, READ_BLOCK_SIZE);
- len = read(fd, buf, READ_BLOCK_SIZE);
+ if ((buf = malloc(READ_BLOCK_SIZE)) != NULL) {
+ len = read(fd, buf, READ_BLOCK_SIZE);
+ while (len > 0) {
+ if (archive_write_data(arch, buf, len) == -1)
+ g_warning("%s", archive_error_string(arch));
+ memset(buf, 0, READ_BLOCK_SIZE);
+ len = read(fd, buf, READ_BLOCK_SIZE);
+ }
+ g_free(buf);
+ }
}
- g_free(buf);
+ archive_entry_free(entry);
}
- close(fd);
- archive_entry_free(entry);
+ if (!g_close(fd, &err) || err)
+ FILE_OP_ERROR(filename, "g_close");
}
}
g_free(filename);
while ((ent = readdir(root)) != NULL) {
if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0)
continue;
- g_stat(ent->d_name, &st);
+ if (g_stat(ent->d_name, &st) == -1) {
+ FILE_OP_ERROR(filename, "g_stat");
+ continue;
+ }
sprintf(path, "%s/%s", dir, ent->d_name);
if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
archive_add_file(path);
return EXIT_SUCCESS;
}
#endif
+
+void archiver_set_tooltip(GtkWidget* widget, gchar* text) {
+ gtk_widget_set_tooltip_text(widget, text);
+ g_free(text);
+}