[PATCH] simplify the conffile db commit process, add missing error checks
---
src/conffiles.c | 24 +++++++++---------------
1 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/src/conffiles.c b/src/conffiles.c
index db55538..96fdbd9 100644
--- a/src/conffiles.c
+++ b/src/conffiles.c
@@ -90,31 +90,25 @@ int conff_get_fd(const char *pkg, const char *path, conff_flag f){
void conff_commit_new(const char *pkg){
/* update the conffiles "db" dir. this consists of the following steps:
- * - ensure that foo_dpkg-old does not exist
- * - move the the db for foo to foo_dpkg-old
- * - move the the new db for foo from foo_dpkg-new to foo
- * - ensure that foo_dpkg-old does not exist
+ * - nuke the existing current db dir
+ * - move the new db into place
*/
- char *cfgdb=NULL, *cfgdbold=NULL, *cfgdbnew=NULL;
+ char *cfgdb=NULL, *cfgdbnew=NULL;
cfgdb = conff_db_path(pkg, NULL, conff_db_cur);
- cfgdbold = conff_db_path(pkg, NULL, conff_db_old);
cfgdbnew = conff_db_path(pkg, NULL, conff_db_new);
/* excuse the copious debug output here... just gotta be
* extra sure when doing rm -rf's :)
*/
- printf("conff_commit_new: rm -rf %s\n", cfgdbold);
- ensure_pathname_nonexisting(cfgdbold);
- printf("conff_commit_new: mv %s %s\n", cfgdb, cfgdbold);
- rename(cfgdb, cfgdbold);
- printf("conff_commit_new: mv %s %s\n", cfgdbnew, cfgdbold);
- rename(cfgdbnew, cfgdb);
- printf("conff_commit_new: rm -rf %s\n", cfgdbold);
- ensure_pathname_nonexisting(cfgdbold);
+ printf("conff_commit_new: rm -rf %s\n", cfgdb);
+ ensure_pathname_nonexisting(cfgdb);
+ printf("conff_commit_new: mv %s %s\n", cfgdbnew, cfgdb);
+ ensure_parent_directory(cfgdb);
+ if(rename(cfgdbnew, cfgdb))
+ ohshite("conff_commit_new: rename(%s,%s)", cfgdbnew, cfgdb);
free(cfgdb);
- free(cfgdbold);
free(cfgdbnew);
}
--
1.5.4.3
Reply to: