Commit ca2fd475 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add nautilus_file_mark_desktop_file_trusted(), this now adds a #! line if

2009-02-24  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-file-operations.c:
        * libnautilus-private/nautilus-file-operations.h:
	Add nautilus_file_mark_desktop_file_trusted(), this now
	adds a #! line if there is none as well as makes the file
	executable.

        * libnautilus-private/nautilus-mime-actions.c:
	Use nautilus_file_mark_desktop_file_trusted() instead of
	just setting the permissions.



svn path=/trunk/; revision=15006
parent 9641b4ea
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
* libnautilus-private/nautilus-file-operations.h:
Add nautilus_file_mark_desktop_file_trusted(), this now
adds a #! line if there is none as well as makes the file
executable.
* libnautilus-private/nautilus-mime-actions.c:
Use nautilus_file_mark_desktop_file_trusted() instead of
just setting the permissions.
2009-02-24 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-mime-actions.c (activate_desktop_file):
......
......@@ -131,6 +131,13 @@ typedef struct {
gpointer done_callback_data;
} EmptyTrashJob;
typedef struct {
CommonJob common;
GFile *file;
NautilusOpCallback done_callback;
gpointer done_callback_data;
} MarkTrustedJob;
typedef struct {
CommonJob common;
GFile *file;
......@@ -5955,6 +5962,195 @@ nautilus_file_operations_empty_trash (GtkWidget *parent_view)
NULL);
}
static gboolean
mark_trusted_job_done (gpointer user_data)
{
MarkTrustedJob *job = user_data;
g_object_unref (job->file);
if (job->done_callback) {
job->done_callback (job->done_callback_data);
}
finalize_common ((CommonJob *)job);
return FALSE;
}
#define TRUSTED_SHEBANG "#!/usr/bin/env xdg-open\n"
static gboolean
mark_trusted_job (GIOSchedulerJob *io_job,
GCancellable *cancellable,
gpointer user_data)
{
MarkTrustedJob *job = user_data;
CommonJob *common;
char *contents, *new_contents;
gsize length, new_length;
GError *error;
guint32 current;
int response;
GFileInfo *info;
common = (CommonJob *)job;
common->io_job = io_job;
nautilus_progress_info_start (job->common.progress);
retry:
error = NULL;
if (!g_file_load_contents (job->file,
cancellable,
&contents, &length,
NULL, &error)) {
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
if (!g_str_has_prefix (contents, "#!")) {
new_length = length + strlen (TRUSTED_SHEBANG);
new_contents = g_malloc (new_length);
strcpy (new_contents, TRUSTED_SHEBANG);
memcpy (new_contents + strlen (TRUSTED_SHEBANG),
contents, length);
if (!g_file_replace_contents (job->file,
new_contents,
new_length,
NULL,
FALSE, 0,
NULL, cancellable, &error)) {
g_free (contents);
g_free (new_contents);
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
g_free (new_contents);
}
g_free (contents);
info = g_file_query_info (job->file,
G_FILE_ATTRIBUTE_STANDARD_TYPE","
G_FILE_ATTRIBUTE_UNIX_MODE,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
common->cancellable,
&error);
if (info == NULL) {
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) {
current = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
current = current | S_IXGRP | S_IXUSR | S_IXOTH;
if (!g_file_set_attribute_uint32 (job->file, G_FILE_ATTRIBUTE_UNIX_MODE,
current, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
common->cancellable, &error))
{
g_object_unref (info);
response = run_error (common,
g_strdup (_("Unable to mark launcher trusted (executable)")),
error->message,
NULL,
FALSE,
GTK_STOCK_CANCEL, RETRY,
NULL);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) {
goto retry;
} else {
g_assert_not_reached ();
}
goto out;
}
}
g_object_unref (info);
out:
g_io_scheduler_job_send_to_mainloop_async (io_job,
mark_trusted_job_done,
job,
NULL);
return FALSE;
}
void
nautilus_file_mark_desktop_file_trusted (GFile *file,
GtkWindow *parent_window,
NautilusOpCallback done_callback,
gpointer done_callback_data)
{
MarkTrustedJob *job;
job = op_job_new (MarkTrustedJob, parent_window);
job->file = g_object_ref (file);
job->done_callback = done_callback;
job->done_callback_data = done_callback_data;
g_io_scheduler_push_job (mark_trusted_job,
job,
NULL,
0,
NULL);
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
......
......@@ -124,6 +124,10 @@ void nautilus_file_operations_link (GList *files,
GtkWindow *parent_window,
NautilusCopyCallback done_callback,
gpointer done_callback_data);
void nautilus_file_mark_desktop_file_trusted (GFile *file,
GtkWindow *parent_window,
NautilusOpCallback done_callback,
gpointer done_callback_data);
#endif /* NAUTILUS_FILE_OPERATIONS_H */
......@@ -1284,24 +1284,6 @@ activate_parameters_desktop_free (ActivateParametersDesktop *parameters_desktop)
g_free (parameters_desktop);
}
static void
mark_trusted_callback (NautilusFile *file,
GFile *result_location,
GError *error,
gpointer callback_data)
{
ActivateParametersDesktop *parameters;
parameters = callback_data;
if (error) {
eel_show_error_dialog (_("Unable to mark launcher trusted (executable)"),
error->message,
parameters->parent_window);
}
activate_parameters_desktop_free (parameters);
}
static void
untrusted_launcher_response_callback (GtkDialog *dialog,
int response_id,
......@@ -1309,9 +1291,8 @@ untrusted_launcher_response_callback (GtkDialog *dialog,
{
GdkScreen *screen;
char *uri;
gboolean free_params;
GFile *file;
free_params = TRUE;
switch (response_id) {
case RESPONSE_RUN:
screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
......@@ -1324,11 +1305,11 @@ untrusted_launcher_response_callback (GtkDialog *dialog,
g_free (uri);
break;
case RESPONSE_MARK_TRUSTED:
nautilus_file_set_permissions (parameters->file,
nautilus_file_get_permissions (parameters->file) | S_IXGRP | S_IXUSR | S_IXOTH,
mark_trusted_callback,
parameters);
free_params = FALSE;
file = nautilus_file_get_location (parameters->file);
nautilus_file_mark_desktop_file_trusted (file,
parameters->parent_window,
NULL, NULL);
g_object_unref (file);
break;
default:
/* Just destroy dialog */
......@@ -1336,9 +1317,7 @@ untrusted_launcher_response_callback (GtkDialog *dialog,
}
gtk_widget_destroy (GTK_WIDGET (dialog));
if (free_params) {
activate_parameters_desktop_free (parameters);
}
activate_parameters_desktop_free (parameters);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment