[gnome-autoar/wip/oholy/compressor-hardlink-fixes: 2/3] compressor: Do not set unknown attributes
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar/wip/oholy/compressor-hardlink-fixes: 2/3] compressor: Do not set unknown attributes
- Date: Thu, 25 Mar 2021 07:32:41 +0000 (UTC)
commit 5adee72a228bc5ff7e59b0a690d816e510b6d6a5
Author: Ondrej Holy <oholy redhat com>
Date: Wed Mar 24 16:12:58 2021 +0100
compressor: Do not set unknown attributes
Currently, various filesystem attributes are passed to libarchive
without checks. But it may happen that not all those attributes are
available, especially for files provided over GVfs. Let's set only
those which are available for sure.
Relates: https://gitlab.gnome.org/GNOME/gnome-autoar/-/issues/25
gnome-autoar/autoar-compressor.c | 76 +++++++++++++++++++++++++++-------------
1 file changed, 51 insertions(+), 25 deletions(-)
---
diff --git a/gnome-autoar/autoar-compressor.c b/gnome-autoar/autoar-compressor.c
index c831c6a..6f3e27e 100644
--- a/gnome-autoar/autoar-compressor.c
+++ b/gnome-autoar/autoar-compressor.c
@@ -75,6 +75,7 @@ G_DEFINE_QUARK (autoar-compressor, autoar_compressor)
#define INVALID_FORMAT 1
#define INVALID_FILTER 2
+#define UNKNOWN_FILE_SIZE 3
struct _AutoarCompressor
{
@@ -851,33 +852,58 @@ autoar_compressor_do_add_to_archive (AutoarCompressor *self,
time_t atime, btime, ctime, mtime;
long atimeu, btimeu, ctimeu, mtimeu;
- atime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
- btime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED);
- ctime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED);
- mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
-
- atimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC);
- btimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CREATED_USEC);
- ctimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CHANGED_USEC);
- mtimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
-
- archive_entry_set_atime (self->entry, atime, atimeu * 1000);
- archive_entry_set_birthtime (self->entry, btime, btimeu * 1000);
- archive_entry_set_ctime (self->entry, ctime, ctimeu * 1000);
- archive_entry_set_mtime (self->entry, mtime, mtimeu * 1000);
-
- archive_entry_set_uid (self->entry, g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID));
- archive_entry_set_gid (self->entry, g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID));
- archive_entry_set_uname (self->entry, g_file_info_get_attribute_string (info,
G_FILE_ATTRIBUTE_OWNER_USER));
- archive_entry_set_gname (self->entry, g_file_info_get_attribute_string (info,
G_FILE_ATTRIBUTE_OWNER_GROUP));
- archive_entry_set_mode (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_MODE));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_ACCESS)) {
+ atime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
+ atimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC);
+ archive_entry_set_atime (self->entry, atime, atimeu * 1000);
+ }
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_CREATED)) {
+ btime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED);
+ btimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CREATED_USEC);
+ archive_entry_set_birthtime (self->entry, btime, btimeu * 1000);
+ }
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_CHANGED)) {
+ ctime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED);
+ ctimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CHANGED_USEC);
+ archive_entry_set_ctime (self->entry, ctime, ctimeu * 1000);
+ }
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) {
+ mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ mtimeu = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
+ archive_entry_set_mtime (self->entry, mtime, mtimeu * 1000);
+ }
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_UID))
+ archive_entry_set_uid (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_UID));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_GID))
+ archive_entry_set_gid (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_GID));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_OWNER_USER))
+ archive_entry_set_uname (self->entry, g_file_info_get_attribute_string (info,
G_FILE_ATTRIBUTE_OWNER_USER));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_OWNER_GROUP))
+ archive_entry_set_gname (self->entry, g_file_info_get_attribute_string (info,
G_FILE_ATTRIBUTE_OWNER_GROUP));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE))
+ archive_entry_set_mode (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_MODE));
+ }
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) {
+ archive_entry_set_size (self->entry, g_file_info_get_attribute_uint64 (info,
G_FILE_ATTRIBUTE_STANDARD_SIZE));
+ } else {
+ self->error = g_error_new (AUTOAR_COMPRESSOR_ERROR, UNKNOWN_SIZE,
+ "'%s': Unknown file size", archive_entry_pathname (entry));
+ return;
}
- archive_entry_set_size (self->entry, g_file_info_get_attribute_uint64 (info,
G_FILE_ATTRIBUTE_STANDARD_SIZE));
- archive_entry_set_dev (self->entry, g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_DEVICE));
- archive_entry_set_ino64 (self->entry, g_file_info_get_attribute_uint64 (info,
G_FILE_ATTRIBUTE_UNIX_INODE));
- archive_entry_set_nlink (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_NLINK));
- archive_entry_set_rdev (self->entry, g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_RDEV));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_DEVICE))
+ archive_entry_set_dev (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_DEVICE));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_INODE))
+ archive_entry_set_ino64 (self->entry, g_file_info_get_attribute_uint64 (info,
G_FILE_ATTRIBUTE_UNIX_INODE));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_NLINK))
+ archive_entry_set_nlink (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_NLINK));
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_RDEV))
+ archive_entry_set_rdev (self->entry, g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_RDEV));
switch (filetype) {
case G_FILE_TYPE_DIRECTORY:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]