Skip to content

Commit 682acf3

Browse files
committed
Fix open-as-root crash
1 parent 2e72e87 commit 682acf3

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

src/nemo-view.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7197,19 +7197,24 @@ cb_open_as_root_watch (GPid pid, gint status, gpointer user_data)
71977197
}
71987198

71997199
static void
7200-
open_as_admin (NemoView *view, const gchar *path) {
7201-
g_autoptr(GUri) uri_obj = g_uri_build (0, "admin", NULL, NULL, -1, path, NULL, NULL);
7202-
g_autofree gchar *uri = g_uri_to_string (uri_obj);
7203-
g_autoptr(GFile) location = g_file_new_for_uri (uri);
7200+
open_as_admin (const gchar *path) {
7201+
g_autofree gchar *uri = g_strconcat ("admin://", path, NULL);
72047202

7205-
nemo_window_slot_open_location (view->details->slot, location, 0);
7203+
gchar *argv[3];
7204+
argv[0] = "nemo";
7205+
argv[1] = uri;
7206+
argv[2] = NULL;
7207+
GPid pid;
7208+
g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
7209+
NULL, NULL, &pid, NULL);
7210+
g_child_watch_add (pid, (GChildWatchFunc) cb_open_as_root_watch, NULL);
72067211
}
72077212

72087213
static void
72097214
open_as_root (NemoView *view, const gchar *path)
72107215
{
72117216
if (eel_check_is_wayland ()) {
7212-
open_as_admin (view, path);
7217+
open_as_admin (path);
72137218
return;
72147219
}
72157220

@@ -7277,17 +7282,27 @@ action_open_as_root_callback (GtkAction *action,
72777282
selection = nemo_view_get_selection (view);
72787283
if (selection != NULL) {
72797284
gchar *path = nemo_file_get_path (NEMO_FILE (selection->data));
7280-
open_as_root (view, path);
7285+
if (path != NULL) {
7286+
open_as_root (view, path);
7287+
g_free (path);
7288+
}
72817289
nemo_file_list_free (selection);
7282-
g_free (path);
72837290
} else {
7284-
gchar *path;
72857291
gchar *uri = nemo_view_get_uri (view);
7292+
if (uri == NULL) {
7293+
return;
7294+
}
72867295
GFile *gfile = g_file_new_for_uri (uri);
7296+
gchar *path;
72877297
if (g_file_has_uri_scheme (gfile, "x-nemo-desktop")) {
72887298
path = nemo_get_desktop_directory ();
72897299
} else {
72907300
path = g_file_get_path (gfile);
7301+
if (path == NULL) {
7302+
g_free (uri);
7303+
g_object_unref (gfile);
7304+
return;
7305+
}
72917306
}
72927307
open_as_root (view, path);
72937308
g_free (uri);

0 commit comments

Comments
 (0)