ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=5cc05b66d60fad5399d664f663f0f7c690e9c53b

commit 5cc05b66d60fad5399d664f663f0f7c690e9c53b
Author: Alastair Poole <nets...@gmail.com>
Date:   Sun Sep 9 21:19:31 2018 +0100

    elm_code_file: preserve file permissions on save.
    
    Test Plan:
     * Run Edi (Python project)
     * Edit setup.py
     * Run build
     * Permissions should be preserved.
     * setup.py should build.
    
    Reviewers: ajwillia.ms
    
    Subscribers: cedric, #reviewers, #committers
    
    Tags: #efl
    
    Differential Revision: https://phab.enlightenment.org/D7008
---
 src/lib/elementary/elm_code_file.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/lib/elementary/elm_code_file.c 
b/src/lib/elementary/elm_code_file.c
index 32b32a3449..aa01cd1b8e 100644
--- a/src/lib/elementary/elm_code_file.c
+++ b/src/lib/elementary/elm_code_file.c
@@ -167,17 +167,26 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
    Eina_List *item;
    Elm_Code *code;
    Elm_Code_Line *line_item;
+   FILE *out;
    const char *path, *content, *crchars;
    char *tmp;
    unsigned int length;
    short crlength;
-   FILE *out;
+   struct stat st;
+   mode_t mode;
+   Eina_Bool have_mode = EINA_FALSE;
 
    code = file->parent;
    path = elm_code_file_path_get(file);
    tmp = _elm_code_file_tmp_path_get(file);
    crchars = elm_code_file_line_ending_chars_get(file, &crlength);
 
+   if (stat(path, &st) != -1)
+     {
+        mode = st.st_mode;
+        have_mode = EINA_TRUE;
+     }
+
    out = fopen(tmp, "w");
    if (out == NULL)
      {
@@ -202,6 +211,9 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
    ecore_file_mv(tmp, path);
    free(tmp);
 
+   if (have_mode)
+     chmod(path, mode);
+
    if (file->parent)
      {
         _elm_code_parse_reset_file(file->parent, file);

-- 


Reply via email to