[eog] Fixed Bug 653065 - On edit of image, permissions changed.
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog] Fixed Bug 653065 - On edit of image, permissions changed.
- Date: Sun, 30 Oct 2011 16:25:25 +0000 (UTC)
commit 4626596c2c179bfe35c4212efced15c38d7337d6
Author: Javier SÃnchez <jsanchez deskblue com>
Date: Sun Oct 16 13:55:09 2011 +0200
Fixed Bug 653065 - On edit of image, permissions changed.
- Try to restore file UID, GID, and MODE attributes from original
image file to temp image file, before replace it.
https://bugzilla.gnome.org/show_bug.cgi?id=653065
src/eog-image.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/eog-jobs.c | 27 --------------
2 files changed, 108 insertions(+), 27 deletions(-)
---
diff --git a/src/eog-image.c b/src/eog-image.c
index 5e96b82..a34c2f6 100644
--- a/src/eog-image.c
+++ b/src/eog-image.c
@@ -1512,6 +1512,110 @@ transfer_progress_cb (goffset cur_bytes,
}
}
+static void
+tmp_file_restore_unix_attributes (GFile *temp_file,
+ GFile *target_file)
+{
+ GFileInfo *file_info;
+ guint uid;
+ guint gid;
+ guint mode;
+ guint mode_mask = 00600;
+
+ GError *error = NULL;
+
+ g_return_if_fail (G_IS_FILE (temp_file));
+ g_return_if_fail (G_IS_FILE (target_file));
+
+ /* check if file exists */
+ if (!g_file_query_exists (target_file, NULL)) {
+ eog_debug_message (DEBUG_IMAGE_SAVE,
+ "Target file doesn't exist. Setting default attributes.");
+ return;
+ }
+
+ /* retrieve UID, GID, and MODE of the original file info */
+ file_info = g_file_query_info (target_file,
+ "unix::uid,unix::gid,unix::mode",
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ /* check that there aren't any error */
+ if (error != NULL) {
+ eog_debug_message (DEBUG_IMAGE_SAVE,
+ "File information not available. Setting default attributes.");
+
+ /* free objects */
+ g_object_unref (file_info);
+ g_clear_error (&error);
+
+ return;
+ }
+
+ /* save UID, GID and MODE values */
+ uid = g_file_info_get_attribute_uint32 (file_info,
+ G_FILE_ATTRIBUTE_UNIX_UID);
+
+ gid = g_file_info_get_attribute_uint32 (file_info,
+ G_FILE_ATTRIBUTE_UNIX_GID);
+
+ mode = g_file_info_get_attribute_uint32 (file_info,
+ G_FILE_ATTRIBUTE_UNIX_MODE);
+
+ /* apply default mode mask to file mode */
+ mode |= mode_mask;
+
+ /* restore original UID, GID, and MODE into the temporal file */
+ g_file_set_attribute_uint32 (temp_file,
+ G_FILE_ATTRIBUTE_UNIX_UID,
+ uid,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ /* check that there aren't any error */
+ if (error != NULL) {
+ eog_debug_message (DEBUG_IMAGE_SAVE,
+ "You do not have the permissions necessary to change the file UID.");
+
+ g_clear_error (&error);
+ }
+
+ g_file_set_attribute_uint32 (temp_file,
+ G_FILE_ATTRIBUTE_UNIX_GID,
+ gid,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ /* check that there aren't any error */
+ if (error != NULL) {
+ eog_debug_message (DEBUG_IMAGE_SAVE,
+ "You do not have the permissions necessary to change the file GID. Setting user default GID.");
+
+ g_clear_error (&error);
+ }
+
+ g_file_set_attribute_uint32 (temp_file,
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ mode,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ /* check that there aren't any error */
+ if (error != NULL) {
+ eog_debug_message (DEBUG_IMAGE_SAVE,
+ "You do not have the permissions necessary to change the file MODE.");
+
+ g_clear_error (&error);
+ }
+
+ /* free objects */
+ g_object_unref (file_info);
+}
+
static gboolean
tmp_file_move_to_uri (EogImage *image,
GFile *tmpfile,
@@ -1522,6 +1626,10 @@ tmp_file_move_to_uri (EogImage *image,
gboolean result;
GError *ioerror = NULL;
+ /* try to restore target file unix attributes */
+ tmp_file_restore_unix_attributes (tmpfile, file);
+
+ /* replace target file with temporal file */
result = g_file_move (tmpfile,
file,
(overwrite ? G_FILE_COPY_OVERWRITE : 0) |
diff --git a/src/eog-jobs.c b/src/eog-jobs.c
index 3e5d743..d7978c6 100644
--- a/src/eog-jobs.c
+++ b/src/eog-jobs.c
@@ -706,9 +706,6 @@ eog_job_save_as_run (EogJob *ejob)
EogJobSaveAs *saveas_job;
GList *it;
guint n_images;
- guint file_permissions = 00000;
- guint permissions_mask = 00600;
- GFileInfo *info;
g_return_if_fail (EOG_IS_JOB_SAVE_AS (ejob));
@@ -797,30 +794,6 @@ eog_job_save_as_run (EogJob *ejob)
dest_info,
&ejob->error);
- /* get file permissions */
- info = g_file_query_info (saveas_job->file,
- G_FILE_ATTRIBUTE_UNIX_MODE,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- NULL);
-
- /* if we can't retrieve file permission apply default */
- if (info != NULL) {
- file_permissions = g_file_info_get_attribute_uint32 (info,
- G_FILE_ATTRIBUTE_UNIX_MODE);
- g_object_unref (info);
- }
-
- /* apply permission mask to file permissions */
- file_permissions |= permissions_mask;
-
- g_file_set_attribute_uint32 (saveas_job->file,
- G_FILE_ATTRIBUTE_UNIX_MODE,
- file_permissions,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- NULL);
-
if (src_info)
g_object_unref (src_info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]