[gnome-autoar/wip/oholy/various-fixes: 13/23] extractor: Explicitely delete files that should be overwritten
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar/wip/oholy/various-fixes: 13/23] extractor: Explicitely delete files that should be overwritten
- Date: Fri, 12 Mar 2021 15:42:21 +0000 (UTC)
commit f26d32e02d04ed6686ec9e2af737f0a6258c582c
Author: Ondrej Holy <oholy redhat com>
Date: Wed Feb 24 16:31:53 2021 +0100
extractor: Explicitely delete files that should be overwritten
Currently, `g_file_replace` is used to write files. However, it uses
`G_FILE_CREATE_NONE` which keeps old permissions. It should rather use
`G_FILE_CREATE_REPLACE_DESTINATION` instead to not keep any old permissions
as it is among others used by File Roller. However, there is bug in
`G_FILE_CREATE_REPLACE_DESTINATION` implementaion, see GNOME/glib#2325.
Let's explicitely delete that file and use `g_file_create` instead.
This will also fix problems when overwriting file by directory and
ensures that hardlinks will be replaced and not just modified.
gnome-autoar/autoar-extractor.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gnome-autoar/autoar-extractor.c b/gnome-autoar/autoar-extractor.c
index ec1b17e..0ce809a 100644
--- a/gnome-autoar/autoar-extractor.c
+++ b/gnome-autoar/autoar-extractor.c
@@ -1152,12 +1152,10 @@ autoar_extractor_do_write_entry (AutoarExtractor *self,
g_debug ("autoar_extractor_do_write_entry: case REG");
- ostream = (GOutputStream*)g_file_replace (dest,
- NULL,
- FALSE,
- G_FILE_CREATE_NONE,
- self->cancellable,
- &(self->error));
+ ostream = (GOutputStream*)g_file_create (dest,
+ G_FILE_CREATE_NONE,
+ self->cancellable,
+ &(self->error));
if (self->error != NULL) {
g_object_unref (info);
return;
@@ -1956,6 +1954,14 @@ autoar_extractor_step_extract (AutoarExtractor *self) {
switch (action) {
case AUTOAR_CONFLICT_OVERWRITE:
+ /* It is expected that this will fail for non-empty directories to
+ * prevent data loss.
+ */
+ g_file_delete (extracted_filename, self->cancellable, &self->error);
+ if (self->error != NULL) {
+ archive_read_free (a);
+ return;
+ }
break;
case AUTOAR_CONFLICT_CHANGE_DESTINATION:
g_assert_nonnull (new_extracted_filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]