GNOME Bugzilla – Bug 773671
Offers to replace directory with file
Last modified: 2017-10-28 12:02:26 UTC
Follow-up from bug 773670 I don't know how that would work, but nautilus offers to replace the directory with a file when they have the same name. In the example, directory gbiblio.m7 contains a file called gbiblio.m7. Trying to move the file to the parent directory throws the error attached. Selecting "Replace" will simply fail.
Created attachment 338774 [details] screenshot
Created attachment 351256 [details] [review] operations-ui: check and handle file on folder copy. nautilus offers to replace the directory with a file when they have the same name. for example, directory gbiblio.m7 contains a file called gbiblio.m7. Trying to move the file gbiblio.m7 to the parent directory throws the error attached. Selecting "Replace" will simply fail. This patch adds a error dialog and cancels the operation
Review of attachment 351256 [details] [review]: Hey Vyas, I like the solution as it simple. However there are some points to take care: ::: src/nautilus-operations-ui-manager.c @@ +489,3 @@ + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CANCEL, + int response_id; I think it's better to not use "strong" entonations with exclamations for errors. So I think it's better if we remove the exclamation symbol. @@ +517,3 @@ data->destination_directory_name = destination_directory_name; + data->source = nautilus_file_get (data->source_name); we don't use nautilus cache on pourpose in file operations. That requires to poke the disk before hand with the *call_when_ready operations. In here you would need to use directly GFile operations. @@ +537,3 @@ + { + invoke_main_context_sync (NULL, + invoke_main_context_sync (NULL, maybe this dialog should have a parameter to wheter the problem is folder vs file replacement? So we can use it on other conflicts, other than here, and we avoid another function and more code.
Created attachment 356079 [details] [review] operations-ui: check and handle file on folder copy. operations-ui: check and handle file on folder nautilus offers to replace the directory with a file when they have the same name. for example, directory gbiblio.m7 contains a file called gbiblio.m7. Trying to move the file gbiblio.m7 to the parent directory throws the error attached. Selecting "Replace" will simply fail. This patch adds a error dialog and cancels the operation
Review of attachment 356079 [details] [review]: I don’t agree with this solution, because this is working around the fact that the operations were written in a way that allows overwriting directories with regular files. There is a simpler way to do this, but the result is an uglier dialog. The problem there is twofold: copying or moving a file over a directory results in G_IO_ERROR_EXISTS (when the overwrite flag is unset), so what works in copy_move_file() and move_file_prepare() is setting it and retrying, because then you get G_IO_ERROR_IS_DIRECTORY, which is what we want to display the error, but which is, again, special cased in the operation code (just a removal of a couple of lines). ::: src/nautilus-operations-ui-manager.c @@ +531,3 @@ + NULL); + GFileInfo *destination_info = g_file_query_info (destination_name, + "standart::display-name, standard::type", Better to use GIO definitions for attribute strings to avoid typos like this.
Comment on attachment 356079 [details] [review] operations-ui: check and handle file on folder copy. Changing the status of the patch to reduce the noise in the list of reviewed patches.
Created attachment 358603 [details] [review] file-operations: fail when overwriting directory with file GIO does not allow that and for a good reason.
Review of attachment 358603 [details] [review]: The most important part of this patch is the reasoning, and it's what is missing. Could you expand on the commit message? The code looks good!
Review of attachment 356079 [details] [review]: rejected in favour of Ernestas patch that removes support for overwriting directories with files.
Created attachment 358608 [details] [review] file-operations: fail when overwriting directory with file GIO documentation (and therefore code) mandates that copies and moves of files over directories should fail, but Nautilus has support for such (possibly dangerous) operations even to this day. This commit works with the assumption that whatever backend happens to be used, it will fail as expected and not overwrite the directory.
Review of attachment 358608 [details] [review]: Looks good now, thanks Ernestas!
Attachment 358608 [details] pushed as 1349a35 - file-operations: fail when overwriting directory with file
*** Bug 425980 has been marked as a duplicate of this bug. ***