User forums > General (but related to Code::Blocks)

Linux file save permission bug

<< < (3/5) > >>

Ceniza:
Playing with ACLs looks like a lot more trouble. Searching the MSDN, it seems the right functions to play with are GetNamedSecurityInfo and SetNamedSecurityInfo. Furthermore, it should be checked, at runtime, that those functions are available under the version of Windows CB is running on (opening advapi32.dll and calling GetProcAddress for the needed functions). Anyone up to the task?

Jenna:

--- Quote from: Ceniza on April 07, 2008, 10:30:57 am ---Playing with ACLs looks like a lot more trouble. Searching the MSDN, it seems the right functions to play with are GetNamedSecurityInfo and SetNamedSecurityInfo. Furthermore, it should be checked, at runtime, that those functions are available under the version of Windows CB is running on (opening advapi32.dll and calling GetProcAddress for the needed functions). Anyone up to the task?

--- End quote ---

I surely will look for this, but I don't know when I find the time to do.

Another problem what came in my mind are ACLs on linux. I think a simple stat and chmod will not be enough to copy/restore them.

Another way to do copying could be to:
 1. write the changed file to disk (as backup-file)
 2. if there was no error -> write the changed data to the original-file.
 3. if there was again no error -> delete the backup-file

that should work and there is no need to deal with file-permissions, and there should not be any risk of losing data as long as wxWidgets reports correctly if there was an error or not.

Biplab:
This patch should solve the issue. I've tested this on Windows. :)


--- Code: ---Index: src/sdk/filemanager.cpp
===================================================================
--- src/sdk/filemanager.cpp (revision 4999)
+++ src/sdk/filemanager.cpp (working copy)
@@ -299,29 +299,35 @@
         return WriteWxStringToFile(f, data, encoding, bom);
     }
 
-    if(platform::windows)
-    {
-        wxFile f;
-        if(!f.Open(name, wxFile::read_write))
-            return false;
-    }
+    wxFile f;
+    if (!f.Open(name, wxFile::read_write))
+        return false;
 
     wxString tempName(name + _T(".cbTemp"));
     do
     {
-        wxFile f(tempName, wxFile::write);
-        if(!f.IsOpened())
+        if (!wxCopyFile(name, tempName))
+        {
+            f.Close();
             return false;
+        }
 
         if(WriteWxStringToFile(f, data, encoding, bom) == false)
         {
             f.Close();
-            wxRemoveFile(tempName);
+            // Keep the backup file as the original file has been destroyed
             return false;
         }
+        else
+        {
+            wxRemoveFile(tempName);
+        }
+
+        f.Close();
+
     }while(false);
 
-    return ReplaceFile(name, tempName);
+    return true;
 }
 
 bool FileManager::ReplaceFile(const wxString& old_file, const wxString& new_file)

--- End code ---


@Thomas,

If you know the exact version of wx which has the buggy wxCopyFile() implementation, then we can specify the exact version users should avoid. :)

Jenna:
There are two "Save"-functions, one with BOM and one without. It should be changed in both (I forgot it in my first patch too  :oops: ).

Biplab:
The Save() function without BOM should not be used at all. :)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version