* 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
This commit is contained in:
Jérôme Duval 2010-04-10 16:36:48 +00:00
parent 4f8e0c8604
commit 77b2080187
1 changed files with 24 additions and 2 deletions

View File

@ -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;