From 77b2080187a845bfb08f38e394fb256eaf6c54e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 10 Apr 2010 16:36:48 +0000 Subject: [PATCH] * StyledEdit now checks the file permissions before writing it (bug #5521). An alert asks the user in case if not writable. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36114 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/StyledEditWindow.cpp | 26 ++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index 626e7383f5..73689b6728 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -841,14 +841,36 @@ StyledEditWindow::Save(BMessage* message) 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;