[gnome-autoar/wip/oholy/compressor-hardlink-fixes: 1/3] compressor: Fix hardlink detection for remote files




commit 7e8147efb45e431119660ae08be1e5e6fe3b0735
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Mar 24 15:09:52 2021 +0100

    compressor: Fix hardlink detection for remote files
    
    Currently, all files are considered as hardlinks when compressing files provided
    by GVfs (e.g. SFTP) to TAR format, so the file content is lost for those files.
    This is because the `inode`, `device`, and/or `nlink` attributes are not set for
    those files. Let's do not call `archive_entry_linkify` in this case to not create
    broken archives.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-autoar/-/issues/25

 gnome-autoar/autoar-compressor.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/gnome-autoar/autoar-compressor.c b/gnome-autoar/autoar-compressor.c
index 1650f43..02748b5 100644
--- a/gnome-autoar/autoar-compressor.c
+++ b/gnome-autoar/autoar-compressor.c
@@ -946,7 +946,18 @@ autoar_compressor_do_add_to_archive (AutoarCompressor *self,
     struct archive_entry *entry, *sparse;
 
     entry = self->entry;
-    archive_entry_linkify (self->resolver, &entry, &sparse);
+
+     /* Hardlinks are handled in different ways by the archive formats. The
+     * archive_entry_linkify function is a unified interface, which handling
+     * the complexity behind the scene. It assumes that archive_entry instances
+     * have valid nlinks, inode and device values. The inode and device value
+     * is used to match entries. The nlinks value is used to determined if all
+     * references have been found and if the internal references can be
+     * recycled. */
+    if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_DEVICE) &&
+        g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_INODE) &&
+        g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_NLINK))
+      archive_entry_linkify (self->resolver, &entry, &sparse);
 
     if (entry != NULL) {
       GFile *file_to_read;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]