[haiku-commits] r36114 - haiku/trunk/src/apps/stylededit

  • From: korli@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 10 Apr 2010 18:36:48 +0200 (CEST)

Author: korli
Date: 2010-04-10 18:36:48 +0200 (Sat, 10 Apr 2010)
New Revision: 36114
Changeset: http://dev.haiku-os.org/changeset/36114/haiku
Ticket: http://dev.haiku-os.org/ticket/5521

Modified:
   haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
Log:
* StyledEdit now checks the file permissions before writing it (bug #5521). An 
alert asks the user in case if not writable.


Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
===================================================================
--- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-04-10 
16:28:53 UTC (rev 36113)
+++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-04-10 
16:36:48 UTC (rev 36114)
@@ -841,14 +841,36 @@
 
        status_t status = B_ERROR;
        if (dir.InitCheck() == B_OK && entry.InitCheck() == B_OK) {
+               struct stat st;
                BFile file(&entry, B_READ_WRITE | B_CREATE_FILE);
-               if (file.InitCheck() == B_OK)
+               if (file.InitCheck() == B_OK
+                       && (status = file.GetStat(&st)) == B_OK) {
+                       // check the file permissions
+                       if (!((getuid() == st.st_uid && (S_IWUSR & st.st_mode))
+                               || (getgid() == st.st_gid && (S_IWGRP & 
st.st_mode))
+                               || (S_IWOTH & st.st_mode))) {
+                               BString alertText;
+                               bs_printf(&alertText, TR("This file is marked 
Read-Only. "
+                                       "Save changes to the document \"%s\"? 
"), name);
+                               switch (_ShowAlert(alertText, TR("Cancel"), 
TR("Don't save"),
+                                       TR("Save"), B_WARNING_ALERT)) {
+                                       case 0:
+                                               return B_CANCELED;
+                                       case 1:
+                                               return B_OK;
+                                       default:
+                                               break;
+                               }
+                       }
+                       
                        status = fTextView->WriteStyledEditFile(&file);
+               }
        }
 
        if (status != B_OK) {
                BString alertText;
-               bs_printf(&alertText, TR("Error saving \"%s\":\n%s"), name, 
strerror(status));
+               bs_printf(&alertText, TR("Error saving \"%s\":\n%s"), name,
+                       strerror(status));
 
                _ShowAlert(alertText, TR("OK"), "", "", B_STOP_ALERT);
                return status;


Other related posts:

  • » [haiku-commits] r36114 - haiku/trunk/src/apps/stylededit - korli