actually _use_ the ask permission

This commit is contained in:
Kartik K. Agaram 2022-04-07 09:19:55 -07:00
parent dad78ac424
commit 98e657d6e2
1 changed files with 29 additions and 1 deletions

View File

@ -1367,7 +1367,28 @@ static const char* user_configuration_filename() {
return config_filename;
}
int file_operation_permitted(const char* filename, const char* mode) {
static int file_operation_permitted_manually(const char* filename, const char* mode) {
int old_y, old_x;
getyx(stdscr, old_y, old_x);
attr_t old_attrs;
short old_pair;
attr_get(&old_attrs, &old_pair, NULL);
attrset(A_NORMAL);
mvaddstr(LINES-1, 0, "");
clrtoeol();
attrset(A_REVERSE);
if (strncmp(mode, "r", /*strlen("r") + 1 for NULL*/ 2) == 0)
mvprintw(LINES-1, 0, "open file \"%s\" for reading? ", filename);
else
mvprintw(LINES-1, 0, "open file \"%s\" for reading and writing? ", filename);
attrset(A_NORMAL);
int response = getch();
attr_set(old_attrs, old_pair, NULL);
mvaddstr(old_y, old_x, "");
return response == 'y';
}
static int file_operation_permitted_automatically(const char* filename, const char* mode) {
int oldtop = lua_gettop(trustedL);
lua_getglobal(trustedL, "file_operation_permitted");
lua_pushstring(trustedL, filename);
@ -1386,6 +1407,13 @@ int file_operation_permitted(const char* filename, const char* mode) {
return should_allow;
}
int file_operation_permitted(const char* filename, const char* mode) {
if (ask_for_permission_on_every_file_operation)
return file_operation_permitted_manually(filename, mode);
else
return file_operation_permitted_automatically(filename, mode);
}
static void permissions_menu() {
attrset(A_REVERSE);
for (int x = 0; x < COLS; ++x)