summaryrefslogtreecommitdiff
path: root/src/eom-image.c
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2015-06-12 19:24:18 +0200
committerraveit65 <[email protected]>2015-06-12 19:24:18 +0200
commit14ddcdad31e8d405b1693095f77151b465f433e6 (patch)
tree32dbccfdba074ace7d880ab8b3fde4709add9075 /src/eom-image.c
parent319803b5ac8b34ef7204ab2bd1b5b0123440ded9 (diff)
parent41b8e5c1e21b02f7ebd0f7f61f9225be5e6f07f5 (diff)
downloadeom-14ddcdad31e8d405b1693095f77151b465f433e6.tar.bz2
eom-14ddcdad31e8d405b1693095f77151b465f433e6.tar.xz
Merge branch 'master' of github.com:mate-desktop/eom
Diffstat (limited to 'src/eom-image.c')
-rw-r--r--src/eom-image.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/eom-image.c b/src/eom-image.c
index d990f98..523f37f 100644
--- a/src/eom-image.c
+++ b/src/eom-image.c
@@ -1433,6 +1433,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)) {
+ eom_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) {
+ eom_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) {
+ eom_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) {
+ eom_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) {
+ eom_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 (EomImage *image,
GFile *tmpfile,
@@ -1443,6 +1547,10 @@ tmp_file_move_to_uri (EomImage *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) |