Skip to content

Commit

Permalink
Set prj.name before saving a project to save that value correctly (ra…
Browse files Browse the repository at this point in the history
  • Loading branch information
thestr4ng3r authored and radare committed May 14, 2017
1 parent c7cc81e commit 6e1595d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 0 additions & 1 deletion libr/core/cmd_project.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ static int cmd_project(void *data, const char *input) {
file = str;
}
if (r_core_project_save (core, file)) {
r_config_set (core->config, "prj.name", file);
r_cons_println (file);
}
break;
Expand Down
14 changes: 13 additions & 1 deletion libr/core/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ R_API bool r_core_project_save(RCore *core, const char *prjName) {
char *scriptPath, *prjDir;
SdbListIter *it;
SdbNs *ns;
char *oldPrjName = NULL;

if (!prjName || !*prjName) {
return false;
Expand Down Expand Up @@ -650,11 +651,17 @@ R_API bool r_core_project_save(RCore *core, const char *prjName) {
free (rop_path);
}
}

const char *oldPrjNameC = r_config_get (core->config, "prj.name");
if (oldPrjNameC) {
oldPrjName = strdup (oldPrjNameC);
}
r_config_set (core->config, "prj.name", prjName);

if (!projectSaveScript (core, scriptPath, R_CORE_PRJ_ALL ^ R_CORE_PRJ_XREFS)) {
eprintf ("Cannot open '%s' for writing\n", prjName);
ret = false;
}

if (r_config_get_i (core->config, "prj.files")) {
eprintf ("TODO: prj.files: support copying more than one file into the project directory\n");
char *binFile = r_core_project_info (core, prjName);
Expand Down Expand Up @@ -706,6 +713,11 @@ R_API bool r_core_project_save(RCore *core, const char *prjName) {
if (scr_null) {
r_config_set_i (core->config, "scr.null", true);
}
if (!ret) {
// reset prj.name on fail
r_config_set (core->config, "prj.name", oldPrjName);
}
free(oldPrjName);
return ret;
}

Expand Down

0 comments on commit 6e1595d

Please sign in to comment.