forked from GitHub/gf-core
remove the newly created .ngf on error.
This commit is contained in:
@@ -84,8 +84,10 @@ PgfPGF *pgf_boot_ngf(const char* pgf_path, const char* ngf_path, PgfExn* err)
|
|||||||
err->msg = strdup(e.what());
|
err->msg = strdup(e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pgf != NULL)
|
if (pgf != NULL) {
|
||||||
delete pgf;
|
delete pgf;
|
||||||
|
remove(ngf_path);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -97,10 +99,13 @@ PgfPGF *pgf_read_ngf(const char *fpath, PgfExn* err)
|
|||||||
|
|
||||||
pgf_exn_clear(err);
|
pgf_exn_clear(err);
|
||||||
|
|
||||||
|
bool is_new = false;
|
||||||
try {
|
try {
|
||||||
pgf = new PgfPGF(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
pgf = new PgfPGF(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
if (DB::get_root<PgfPGFRoot>() == 0) {
|
if (DB::get_root<PgfPGFRoot>() == 0) {
|
||||||
|
is_new = true;
|
||||||
|
|
||||||
DB_scope scope(pgf, WRITER_SCOPE);
|
DB_scope scope(pgf, WRITER_SCOPE);
|
||||||
|
|
||||||
ref<PgfPGFRoot> root = DB::malloc<PgfPGFRoot>();
|
ref<PgfPGFRoot> root = DB::malloc<PgfPGFRoot>();
|
||||||
@@ -123,8 +128,11 @@ PgfPGF *pgf_read_ngf(const char *fpath, PgfExn* err)
|
|||||||
err->msg = strdup(e.what());
|
err->msg = strdup(e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pgf != NULL)
|
if (pgf != NULL) {
|
||||||
delete pgf;
|
delete pgf;
|
||||||
|
if (is_new)
|
||||||
|
remove(ngf_path);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user