[gnome-autoar/wip/oholy/various-fixes: 9/23] extractor: Fix default action for conflicts




commit 2955faea3dddbeea7c8b2e64e1a7efebdc64f430
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Feb 18 12:54:24 2021 +0100

    extractor: Fix default action for conflicts
    
    The `AUTOAR_CONFLICT_OVERWRITE` is set as default value for the action
    variable when conflict occured. However, `g_signal_emit` clears that
    variable to `0` if the signal is unhandled. But `0` is currently mapped
    to `AUTOAR_CONFLICT_SKIP`. So the code is a little bit confusing. I think
    that overwrite is the right thing in most cases and also this is the
    default behavior of `tar` as an archive may contain several versions of
    some file and the last one is the newest. However, gnome-autoar allows
    extraction in the non-empty folders and has conflict API, so it would be
    really safer to use the skip action by default. Let's add the
    `AUTOAR_CONFLICT_UNHANDLED` action for better control and use the
    `AUTOAR_CONFLICT_SKIP` action by default.

 gnome-autoar/autoar-extractor.c | 4 +++-
 gnome-autoar/autoar-extractor.h | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/gnome-autoar/autoar-extractor.c b/gnome-autoar/autoar-extractor.c
index 9ec16d3..ec1b17e 100644
--- a/gnome-autoar/autoar-extractor.c
+++ b/gnome-autoar/autoar-extractor.c
@@ -780,13 +780,15 @@ autoar_extractor_signal_conflict (AutoarExtractor  *self,
                                   GFile            *file,
                                   GFile           **new_file)
 {
-  AutoarConflictAction action = AUTOAR_CONFLICT_OVERWRITE;
+  AutoarConflictAction action = AUTOAR_CONFLICT_UNHANDLED;
 
   autoar_common_g_signal_emit (self, self->in_thread,
                                autoar_extractor_signals[CONFLICT], 0,
                                file,
                                new_file,
                                &action);
+  if (action == AUTOAR_CONFLICT_UNHANDLED)
+    return AUTOAR_CONFLICT_SKIP;
 
   if (*new_file) {
     g_autofree char *previous_path;
diff --git a/gnome-autoar/autoar-extractor.h b/gnome-autoar/autoar-extractor.h
index 6d59160..fbe44e1 100644
--- a/gnome-autoar/autoar-extractor.h
+++ b/gnome-autoar/autoar-extractor.h
@@ -72,7 +72,8 @@ void             autoar_extractor_set_notify_interval         (AutoarExtractor *
                                                                gint64           notify_interval);
 
 typedef enum {
-    AUTOAR_CONFLICT_SKIP = 0,
+    AUTOAR_CONFLICT_UNHANDLED = 0,
+    AUTOAR_CONFLICT_SKIP,
     AUTOAR_CONFLICT_OVERWRITE,
     AUTOAR_CONFLICT_CHANGE_DESTINATION
 } AutoarConflictAction;


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