nautilus r15006 - in trunk: . libnautilus-private
- From: alexl svn gnome org
- To: svn-commits-list gnome org
- Subject: nautilus r15006 - in trunk: . libnautilus-private
- Date: Tue, 24 Feb 2009 14:03:24 +0000 (UTC)
Author: alexl
Date: Tue Feb 24 14:03:24 2009
New Revision: 15006
URL: http://svn.gnome.org/viewvc/nautilus?rev=15006&view=rev
Log:
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.
Modified:
trunk/ChangeLog
trunk/libnautilus-private/nautilus-file-operations.c
trunk/libnautilus-private/nautilus-file-operations.h
trunk/libnautilus-private/nautilus-mime-actions.c
Modified: trunk/libnautilus-private/nautilus-file-operations.c
==============================================================================
--- trunk/libnautilus-private/nautilus-file-operations.c (original)
+++ trunk/libnautilus-private/nautilus-file-operations.c Tue Feb 24 14:03:24 2009
@@ -136,6 +136,13 @@
GFile *file;
NautilusOpCallback done_callback;
gpointer done_callback_data;
+} MarkTrustedJob;
+
+typedef struct {
+ CommonJob common;
+ GFile *file;
+ NautilusOpCallback done_callback;
+ gpointer done_callback_data;
guint32 file_permissions;
guint32 file_mask;
guint32 dir_permissions;
@@ -5955,6 +5962,195 @@
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)
Modified: trunk/libnautilus-private/nautilus-file-operations.h
==============================================================================
--- trunk/libnautilus-private/nautilus-file-operations.h (original)
+++ trunk/libnautilus-private/nautilus-file-operations.h Tue Feb 24 14:03:24 2009
@@ -124,6 +124,10 @@
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 */
Modified: trunk/libnautilus-private/nautilus-mime-actions.c
==============================================================================
--- trunk/libnautilus-private/nautilus-mime-actions.c (original)
+++ trunk/libnautilus-private/nautilus-mime-actions.c Tue Feb 24 14:03:24 2009
@@ -1285,33 +1285,14 @@
}
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,
ActivateParametersDesktop *parameters)
{
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 @@
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 @@
}
gtk_widget_destroy (GTK_WIDGET (dialog));
- if (free_params) {
- activate_parameters_desktop_free (parameters);
- }
+ activate_parameters_desktop_free (parameters);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]