|
|
af40a0 |
From 32f347bd83495edf2bda746d17e613c868a7c379 Mon Sep 17 00:00:00 2001
|
|
|
af40a0 |
From: Carlos Soriano <csoriano@redhat.com>
|
|
|
af40a0 |
Date: Tue, 7 Aug 2018 11:51:54 +0200
|
|
|
af40a0 |
Subject: [PATCH 05/11] file-operations: Don't crash if source file not present
|
|
|
af40a0 |
on creation
|
|
|
af40a0 |
|
|
|
af40a0 |
When creating a file it was checking if the file already exists, and if
|
|
|
af40a0 |
so it tried to give a new name based on the original file that was being
|
|
|
af40a0 |
duplicated from which is the case for the regular copy/paste and the
|
|
|
af40a0 |
template creation.
|
|
|
af40a0 |
|
|
|
af40a0 |
However, creating a file is not only about duplicating from another one,
|
|
|
af40a0 |
it also can come from creating a folder, that although in the UI it
|
|
|
af40a0 |
prevents doing so, it can still be done through the dbus operation.
|
|
|
af40a0 |
|
|
|
af40a0 |
Fix that by checking whether there is an actual source file, and if not,
|
|
|
af40a0 |
use the name provided as base name.
|
|
|
af40a0 |
---
|
|
|
af40a0 |
src/nautilus-file-operations.c | 36 ++++++++++++++++------------------
|
|
|
af40a0 |
1 file changed, 17 insertions(+), 19 deletions(-)
|
|
|
af40a0 |
|
|
|
af40a0 |
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
|
|
|
af40a0 |
index 4d84b98be..cf5e7f46b 100644
|
|
|
af40a0 |
--- a/src/nautilus-file-operations.c
|
|
|
af40a0 |
+++ b/src/nautilus-file-operations.c
|
|
|
af40a0 |
@@ -7324,20 +7324,18 @@ retry:
|
|
|
af40a0 |
{
|
|
|
af40a0 |
g_autofree char *filename2 = NULL;
|
|
|
af40a0 |
g_autofree char *suffix = NULL;
|
|
|
af40a0 |
- NautilusFile *file;
|
|
|
af40a0 |
|
|
|
af40a0 |
- file = nautilus_file_get (job->src);
|
|
|
af40a0 |
- if (nautilus_file_is_directory (file))
|
|
|
af40a0 |
- {
|
|
|
af40a0 |
- filename_base = filename;
|
|
|
af40a0 |
- }
|
|
|
af40a0 |
- else
|
|
|
af40a0 |
+ filename_base = filename;
|
|
|
af40a0 |
+ if (job->src != NULL)
|
|
|
af40a0 |
{
|
|
|
af40a0 |
- filename_base = eel_filename_strip_extension (filename);
|
|
|
af40a0 |
+ g_autoptr (NautilusFile) file = NULL;
|
|
|
af40a0 |
+ file = nautilus_file_get (job->src);
|
|
|
af40a0 |
+ if (!nautilus_file_is_directory (file))
|
|
|
af40a0 |
+ {
|
|
|
af40a0 |
+ filename_base = eel_filename_strip_extension (filename);
|
|
|
af40a0 |
+ }
|
|
|
af40a0 |
}
|
|
|
af40a0 |
|
|
|
af40a0 |
- nautilus_file_unref (file);
|
|
|
af40a0 |
-
|
|
|
af40a0 |
offset = strlen (filename_base);
|
|
|
af40a0 |
suffix = g_strdup (filename + offset);
|
|
|
af40a0 |
|
|
|
af40a0 |
@@ -7377,21 +7375,21 @@ retry:
|
|
|
af40a0 |
{
|
|
|
af40a0 |
g_autofree char *suffix = NULL;
|
|
|
af40a0 |
g_autofree gchar *filename2 = NULL;
|
|
|
af40a0 |
- NautilusFile *file;
|
|
|
af40a0 |
|
|
|
af40a0 |
g_clear_object (&dest);
|
|
|
af40a0 |
|
|
|
af40a0 |
- file = nautilus_file_get (job->src);
|
|
|
af40a0 |
- if (nautilus_file_is_directory (file))
|
|
|
af40a0 |
- {
|
|
|
af40a0 |
- filename_base = filename;
|
|
|
af40a0 |
- }
|
|
|
af40a0 |
- else
|
|
|
af40a0 |
+ filename_base = filename;
|
|
|
af40a0 |
+ if (job->src != NULL)
|
|
|
af40a0 |
{
|
|
|
af40a0 |
- filename_base = eel_filename_strip_extension (filename);
|
|
|
af40a0 |
+ g_autoptr (NautilusFile) file = NULL;
|
|
|
af40a0 |
+
|
|
|
af40a0 |
+ file = nautilus_file_get (job->src);
|
|
|
af40a0 |
+ if (!nautilus_file_is_directory (file))
|
|
|
af40a0 |
+ {
|
|
|
af40a0 |
+ filename_base = eel_filename_strip_extension (filename);
|
|
|
af40a0 |
+ }
|
|
|
af40a0 |
}
|
|
|
af40a0 |
|
|
|
af40a0 |
- nautilus_file_unref (file);
|
|
|
af40a0 |
|
|
|
af40a0 |
offset = strlen (filename_base);
|
|
|
af40a0 |
suffix = g_strdup (filename + offset);
|
|
|
af40a0 |
--
|
|
|
af40a0 |
2.17.1
|
|
|
af40a0 |
|