[Midnightbsd-cvs] src: lib/libmport: Add the cleanup code to create.
ctriv at midnightbsd.org
ctriv at midnightbsd.org
Mon Sep 24 16:58:01 EDT 2007
Log Message:
-----------
Add the cleanup code to create. Various bug fixes.
Modified Files:
--------------
src/lib/libmport:
create_pkg.c (r1.3 -> r1.4)
error.c (r1.2 -> r1.3)
mport.h (r1.2 -> r1.3)
util.c (r1.3 -> r1.4)
-------------- next part --------------
Index: util.c
===================================================================
RCS file: /home/cvs/src/lib/libmport/util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Llib/libmport/util.c -Llib/libmport/util.c -u -r1.3 -r1.4
--- lib/libmport/util.c
+++ lib/libmport/util.c
@@ -64,6 +64,26 @@
free(pack);
}
+
+/* deletes the entire directory tree at name.
+ * think rm -r filename
+ */
+int mport_rmtree(const char *filename)
+{
+ char *cmnd;
+ int ret;
+
+ asprintf(&cmnd, "/bin/rm -r %s", filename);
+
+ if ((ret = system(cmnd)) != 0) {
+ RETURN_ERROR(MPORT_ERR_SYSCALL_FAILED, strerror(errno));
+ }
+
+ free(cmnd);
+ return MPORT_OK;
+}
+
+
/*
*Copy fromname to toname
*
Index: mport.h
===================================================================
RCS file: /home/cvs/src/lib/libmport/mport.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -Llib/libmport/mport.h -Llib/libmport/mport.h -u -r1.2 -r1.3
--- lib/libmport/mport.h
+++ lib/libmport/mport.h
@@ -123,6 +123,7 @@
/* Utils */
int mport_copy_file(const char *, const char *);
+int mport_rmtree(const char *);
int mport_file_exists(const char *);
void mport_parselist(char *, char ***);
Index: error.c
===================================================================
RCS file: /home/cvs/src/lib/libmport/error.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Llib/libmport/error.c -Llib/libmport/error.c -u -r1.2 -r1.3
--- lib/libmport/error.c
+++ lib/libmport/error.c
@@ -83,11 +83,16 @@
{
va_list args;
char *err;
+ int ret;
va_start(args, fmt);
if (vasprintf(&err, fmt, args) == -1) {
fprintf(stderr, "fatal error: mport_set_errx can't format the string.\n");
exit(255);
}
- return mport_set_err(code, err);
+ ret = mport_set_err(code, err);
+
+ free(err);
+
+ return ret;
}
Index: create_pkg.c
===================================================================
RCS file: /home/cvs/src/lib/libmport/create_pkg.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Llib/libmport/create_pkg.c -Llib/libmport/create_pkg.c -u -r1.3 -r1.4
--- lib/libmport/create_pkg.c
+++ lib/libmport/create_pkg.c
@@ -213,13 +213,13 @@
}
sqlite3_finalize(stmnt);
-
+
/* insert depends and conflicts */
if ((ret = insert_depends(db, pack)) != MPORT_OK)
return ret;
if ((ret = insert_conflicts(db, pack)) != MPORT_OK)
return ret;
-
+
return MPORT_OK;
}
@@ -231,6 +231,10 @@
char **conflict = pack->conflicts;
const char *rest = 0;
+ /* we're done if there are no conflicts to record. */
+ if (conflict == NULL)
+ return MPORT_OK;
+
if (sqlite3_prepare_v2(db, sql, -1, &stmnt, &rest) != SQLITE_OK) {
RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
}
@@ -263,6 +267,10 @@
char **depend = pack->depends;
const char *rest = 0;
+ /* we're done if there are no deps to record. */
+ if (depend == NULL)
+ return MPORT_OK;
+
if (sqlite3_prepare_v2(db, sql, -1, &stmnt, &rest) != SQLITE_OK) {
RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
}
@@ -410,7 +418,19 @@
archive_write_finish(a);
}
+#ifdef DEBUG
+
static int clean_up(const char *tmpdir)
{
+ /* do nothing */
+}
+
+#else
+
+static int clean_up(const char *tmpdir)
+{
+ return mport_rmtree(tmpdir);
}
+#endif
+
More information about the Midnightbsd-cvs
mailing list