From 66f699ec52d1fa4215e3440025095e948125fce5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 26 Jul 2014 18:44:47 -0400 Subject: [PATCH 1/1] Make new desktop files owner-executable. --- exo-desktop-item-edit/exo-die-utils.c | 84 +++++++++++++++++++++++++++++++++++ exo-desktop-item-edit/exo-die-utils.h | 7 +++ 2 files changed, 91 insertions(+) diff --git a/exo-desktop-item-edit/exo-die-utils.c b/exo-desktop-item-edit/exo-die-utils.c index 9bd0d37..8b09f3d 100644 --- a/exo-desktop-item-edit/exo-die-utils.c +++ b/exo-desktop-item-edit/exo-die-utils.c @@ -26,6 +26,8 @@ #endif #include +#include + #include @@ -192,6 +194,13 @@ exo_die_g_key_file_save (GKeyFile *key_file, * file before the origional desktop file is replaced */ path = g_file_get_path (file); result = g_file_set_contents (path, data, length, error); + + if (result) { + /* If the file is local, we should make it executable. Do we + need to do this if the file is remote? */ + exo_die_g_file_make_owner_executable(path, error); + } + g_free (path); } else @@ -212,3 +221,78 @@ exo_die_g_key_file_save (GKeyFile *key_file, +/** + * exo_die_g_file_make_owner_executable: + * @path : the path the the file that we want to make owner-executable + * @error : return location for errors or %NULL. + * + * Return value: %TRUE if successful, %FALSE otherwise. + **/ +gboolean +exo_die_g_file_make_owner_executable (const gchar *path, + GError **error) +{ + gint perms; /* permission bits of the file */ + gboolean perms_result; /* result of fetching the file's permissions */ + gint chmod_result; /* result of changing the file's permissions */ + + /* Bail if we're given a bum GError pointer (pointer) . */ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + perms_result = exo_die_g_file_get_mode (path, &perms, error); + + if (!perms_result) { + return FALSE; + } + + /* Add the owner-execute bit to perms and try to chmod the file */ + perms = perms | S_IXUSR; + chmod_result = g_chmod(path, perms); + + if (chmod_result == -1) { + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + _("Unable to chmod %s."), + path); + return FALSE; + } + + return TRUE; +} + + +/** + * exo_die_g_file_get_mode: + * @path : the path the the file whose mode we want. + * @mode : a pointer to an int where we'll store the mode bits if successful. + * @error : return location for errors or %NULL. + * + * Return value: %TRUE if successful, %FALSE otherwise. + **/ +gboolean +exo_die_g_file_get_mode (const gchar *path, + gint *mode, + GError **error) +{ + int stat_result; + GStatBuf statbuf; + + /* Bail if we're given a bum GError pointer (pointer) . */ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + stat_result = g_stat(path, &statbuf); + + if (stat_result == -1) { + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + _("Unable to stat %s."), + path); + return FALSE; + } + + *mode = statbuf.st_mode; + + return TRUE; +} diff --git a/exo-desktop-item-edit/exo-die-utils.h b/exo-desktop-item-edit/exo-die-utils.h index 3c03ae0..fbd64e6 100644 --- a/exo-desktop-item-edit/exo-die-utils.h +++ b/exo-desktop-item-edit/exo-die-utils.h @@ -37,6 +37,13 @@ gboolean exo_die_g_key_file_save (GKeyFile *key_file, ExoDieEditorMode mode, GError **error); +gboolean exo_die_g_file_make_owner_executable (const gchar *path, + GError **error); + +gboolean exo_die_g_file_get_mode (const gchar *path, + gint *mode, + GError **error); + G_END_DECLS #endif /* !__EXO_DIE_UTILS_H__ */ -- 1.8.5.5