Confirm project deletion and honor scr.interactive on reopen ##project

* Add broken test for projects reopen
This commit is contained in:
pancake 2022-05-05 11:28:49 +02:00 committed by pancake
parent a314a7ebde
commit 4be0d2b9a4
4 changed files with 54 additions and 14 deletions

View File

@ -441,7 +441,9 @@ static void cmd_open_bin(RCore *core, const char *input) {
}
// TODO: discuss the output format
static void map_list(RIO *io, ut64 off, int mode, RPrint *print, int fd) {
static void map_list(RCore *core, int mode, RPrint *print, int fd) {
RIO *io = core->io;
ut64 off = core->offset;
r_return_if_fail (io && print && print->cb_printf);
PJ *pj = NULL;
if (mode == 'j') {
@ -658,7 +660,7 @@ static bool cmd_om(RCore *core, const char *input) {
} else {
int fd = r_io_fd_get_current (core->io);
if (r_io_desc_get (core->io, fd)) {
map_list (core->io, core->offset, 0, core->print, fd);
map_list (core, 0, core->print, fd);
} else {
eprintf ("Invalid fd %d\n", (int)fd);
}
@ -1076,9 +1078,9 @@ static void cmd_open_map(RCore *core, const char *input) {
}
} else {
if (input[1] && input[2] == 'q') { // "omqq"
map_list (core->io, core->offset, input[1], core->print, -2);
map_list (core, input[1], core->print, -2);
} else {
map_list (core->io, core->offset, input[1], core->print, -1);
map_list (core, input[1], core->print, -1);
}
}
break;

View File

@ -67,8 +67,10 @@ static int cmd_project(void *data, const char *input) {
eprintf ("Usage: Pc [prjname]\n");
}
break;
case ' ': // "P [prj]"
case 'o': // "Po" DEPRECATED
eprintf ("TODO: Po is deprecated, use 'P [prjname]' instead\n");
// fallthru
case ' ': // "P [prj]"
if (input[1] == '&') { // "Po&"
r_core_cmdf (core, "& Po %s", file);
} else if (input[1]) { // "Po"
@ -84,9 +86,14 @@ static int cmd_project(void *data, const char *input) {
char *pdir = r_file_new (
r_config_get (core->config, "dir.projects"),
r_config_get (core->config, "prj.name"), NULL);
r_syscmd_pushd (pdir);
r_sys_cmdf ("git diff @~%d", atoi (input + 1));
r_syscmd_popd ();
if (r_syscmd_pushd (pdir)) {
if (r_file_is_directory (".git")) {
r_sys_cmdf ("git diff @~%d", atoi (input + 1));
} else {
eprintf ("TODO: Not a git project. Diffing projects is WIP for now.\n");
}
r_syscmd_popd ();
}
free (pdir);
}
break;

View File

@ -154,7 +154,13 @@ R_API int r_core_project_delete(RCore *core, const char *prjfile) {
free (path);
return false;
}
r_file_rm_rf (prj_dir);
bool must_rm = true;
if (r_config_get_b (core->config, "scr.interactive")) {
must_rm = r_cons_yesno ('y', "Confirm project deletion? (Y/n)");
}
if (must_rm) {
r_file_rm_rf (prj_dir);
}
free (prj_dir);
}
free (path);
@ -346,10 +352,13 @@ R_API RThread *r_core_project_load_bg(RCore *core, const char *prj_name, const c
R_API bool r_core_project_open(RCore *core, const char *prj_path) {
r_return_val_if_fail (core && !R_STR_ISEMPTY (prj_path), false);
int ret, close_current_session = 1;
bool interactive = r_config_get_b (core->config, "scr.interactive");
bool close_current_session = true;
bool ask_for_closing = true;
if (r_project_is_loaded (core->prj)) {
eprintf ("There's a project already opened\n");
bool ccs = r_cons_yesno ('y', "Close current session? (Y/n)");
ask_for_closing = false;
bool ccs = interactive? r_cons_yesno ('y', "Close current session? (Y/n)"): true;
if (ccs) {
r_core_cmd0 (core, "o--");
} else {
@ -363,16 +372,16 @@ R_API bool r_core_project_open(RCore *core, const char *prj_path) {
eprintf ("Invalid project name '%s'\n", prj_path);
return false;
}
if (r_project_is_loaded (core->prj)) {
if (ask_for_closing && r_project_is_loaded (core->prj)) {
if (r_cons_is_interactive ()) {
close_current_session = r_cons_yesno ('y', "Close current session? (Y/n)");
close_current_session = interactive? r_cons_yesno ('y', "Close current session? (Y/n)"): true;
}
}
if (close_current_session) {
r_core_cmd0 (core, "e prj.name=;o--");
}
/* load sdb stuff in here */
ret = r_core_project_load (core, prj_name, prj_script);
bool ret = r_core_project_load (core, prj_name, prj_script);
free (prj_name);
free (prj_script);
if (ret) {

View File

@ -1,3 +1,25 @@
NAME=Resaving fails
FILE=bins/mach0/ls-m1
BROKEN=1
CMDS=<<EOF
e prj.vc=false
e scr.interactive=false
e dir.projects = bins/other/projects
p8 16
P+ls
P ls
p8 16
o
om
EOF
EXPECT=<<EOF
7f2303d5fc6fbaa9fa6701a9f85f02a9
7f2303d5fc6fbaa9fa6701a9f85f02a9
3 * r-x 0x0002daa0 bins/mach0/ls-m1
* 2 fd: 3 +0x00000000 0x00000000 - 0x0002da9f r-x
EOF
RUN
NAME=Import project
FILE=malloc://512
CMDS=<<EOF