file-operations: Limit use of NautilusFile's in threads
NautilusFile/NautilusDirectory is not threadsafe. Nautilus crashes
when rapid fire copying files due to a regression in [1] which calls
nautilus_file_get() in a thread. When nautilus_file_get() is called
before the file exists in a NautilusDirectory, it attempts to create
the file, but that same file may already be in the process of being
created in another thread. Since the use of the NautilusFile was
simply to check if the file is a directory, use the existing is_dir()
function (which in turn calls g_file_query_file_type()) instead.
The performance differential is negligible (if any), and is not even
called from the main thread.
We have a nice utility function for checking if a GFile is a
directory, but we don't pass the CommonJob's cancellabe. Use
the cancellable, and use the function consistently.
grid-view, list-view: don't sort directories before files in search results
As described in #2968, directories are currently sorted before files in search results
if this option is enabled in preferences, leading to less relevant results being shown
first if they are directories. Intended behaviour is for this preference to be ignored
when searching. This bug was originally fixed in 9ec56a2d48ddf5db18757e680deb2421c15189da,
it is caused by the directories_first check being made at init, which is before the
location has been set.
This commit moves the directories_first check to real_begin_loading in the grid view
and list view classes. This causes the directories_first preference to be ignored when
presenting search results, as expected.
window-slot: Fix conditions to restore selection when reloading
Currently, the `nautilus_window_slot_force_reload` function doesn't
preserve selection or position. However, there is a code that should do
it. The code is executed only when `new_content_view != NULL`, but it
is based on the `content_view` property. This seems to be a regression
caused by the commit 9806d70e. Let's fix that condition in order to
ensure that the selection and position are restored.
file-utilities: Prevent passing NULL to g_object_unref
The `nautilus_find_existing_uri_in_hierarchy` function calls the
`g_object_unref` with a `NULL` pointer when `g_file_query_info` fails.
This leads to a crash e.g. when parent directory of the currently
opened location is removed. Let's port the code to use `g_autoptr` to
avoid that.
pathbar: Do nothing when current location disappears
The pathbar automatically clear all the buttons when the current location
is marked as gone. This was needed earlier, when child folders where shown
in some cases, but this is no more needed nowadays. Let's drop that code.
window-slot: Force reload current location when it reappears
When the currently opened location disappears, nautilus tries to
reopen it thanks to the commit b0e28bc1. However, the
`nautilus_window_slot_open_location_full` function doesn't begin the
location change when the old location is the same as the new one. This
is a problem because the old `NautilusFile` object is marked as gone
and thus monitoring and perhaps some other stuff won't work. Let's use
the `nautilus_window_slot_force_reload` function instead, in this case,
to ensure that the underlying `NautilusFile` is updated.