summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2021-09-24 08:40:23 +0200
committerOndrej Holy <oholy@redhat.com>2021-10-25 14:44:25 +0000
commitd09b34cde210c4f817d2442cc9378b1ddf73aee9 (patch)
treeb6a4a6a1b6a96639b185537e7242a030192edeff
parent83f1153e787aaac066cf8af52ee28848be6c140b (diff)
downloadnautilus-d09b34cde210c4f817d2442cc9378b1ddf73aee9.tar.gz
file-operations: Remove leftover files after extraction failure
Empty, or corrupted files are left in the output directory in the case of extraction failure, e.g. when wrong password is supplied. This is in most cases undesired. Let's recursively delete all the leftover files in the case of extraction failure. Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/1954
-rw-r--r--src/nautilus-file-operations.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index 7927bd504..13da2cb39 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -204,6 +204,7 @@ typedef struct
GList *source_files;
GFile *destination_directory;
GList *output_files;
+ gboolean destination_decided;
gdouble base_progress;
@@ -8202,8 +8203,14 @@ extract_job_on_decide_destination (AutoarExtractor *extractor,
return NULL;
}
+ /* The extract_job->destination_decided variable signalizes whether the
+ * extract_job->output_files list already contains the final location as
+ * its first link. There is no way to get this over the AutoarExtractor
+ * API currently.
+ */
extract_job->output_files = g_list_prepend (extract_job->output_files,
decided_destination);
+ extract_job->destination_decided = TRUE;
return g_object_ref (decided_destination);
}
@@ -8336,6 +8343,15 @@ extract_job_on_error (AutoarExtractor *extractor,
return;
}
+ /* It is safe to use extract_job->output_files->data only when the
+ * extract_job->destination_decided variable was set, see comment in the
+ * extract_job_on_decide_destination function.
+ */
+ if (extract_job->destination_decided)
+ {
+ delete_file_recursively (extract_job->output_files->data, NULL, NULL, NULL);
+ }
+
basename = get_basename (source_file);
nautilus_progress_info_take_status (extract_job->common.progress,
g_strdup_printf (_("Error extracting ā€œ%sā€"),
@@ -8657,6 +8673,7 @@ extract_task_thread_func (GTask *task,
extract_job);
extract_job->archive_compressed_size = archive_compressed_sizes[i];
+ extract_job->destination_decided = FALSE;
autoar_extractor_start (extractor,
extract_job->common.cancellable);