* 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:
parent
4f8e0c8604
commit
77b2080187
|
@ -841,14 +841,36 @@ StyledEditWindow::Save(BMessage* message)
|
||||||
|
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
if (dir.InitCheck() == B_OK && entry.InitCheck() == B_OK) {
|
if (dir.InitCheck() == B_OK && entry.InitCheck() == B_OK) {
|
||||||
|
struct stat st;
|
||||||
BFile file(&entry, B_READ_WRITE | B_CREATE_FILE);
|
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);
|
status = fTextView->WriteStyledEditFile(&file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
BString alertText;
|
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);
|
_ShowAlert(alertText, TR("OK"), "", "", B_STOP_ALERT);
|
||||||
return status;
|
return status;
|
||||||
|
|
Loading…
Reference in New Issue