Skip to content

Commit

Permalink
Various fix and imprvements.
Browse files Browse the repository at this point in the history
- Fix compilation (due to a remaining util.h include).
- Fix binding logic of the flatsize (binded after the statement is
executed...)
- Use SQLITE_STATIC instead of SQLITE_TRANSIENT to avoid copy.
SQLITE_TRANSIENT is useful when we can not guarrantee that the binded
data will be there at statement exectution time.
- Fix const qualifier mess.
- Fix a FTS leak.
  • Loading branch information
jlaffaye committed Jan 24, 2011
1 parent afc9c7e commit 31ccec6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion libpkg/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const char *pkg_option_opt(struct pkg_option *);
const char *pkg_option_value(struct pkg_option *);

/* pkg_repo */
int pkg_create_repo(const char *, void (*)(struct pkg *, void *), void *);
int pkg_create_repo(char *, void (*)(struct pkg *, void *), void *);

/* pkgdb */
int pkgdb_open(struct pkgdb **);
Expand Down
2 changes: 1 addition & 1 deletion libpkg/pkg_manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <sys/types.h>
#include <sys/sbuf.h>

#include "util.h"
#include "pkg_util.h"
#include "pkg.h"
#include "pkg_private.h"

Expand Down
52 changes: 27 additions & 25 deletions libpkg/pkg_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
#include "pkg_private.h"
#include "pkg_util.h"


int
pkg_create_repo(const char *path, void (progress)(struct pkg *pkg, void *data), void *data)
pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *data)
{
FTS *fts;
FTSENT *ent;
Expand All @@ -29,7 +28,8 @@ pkg_create_repo(const char *path, void (progress)(struct pkg *pkg, void *data),

int i;

char *repopath[2], repodb[MAXPATHLEN];
char *repopath[2];
char repodb[MAXPATHLEN];

const char initsql[] = ""
"CREATE TABLE packages ("
Expand Down Expand Up @@ -61,7 +61,7 @@ pkg_create_repo(const char *path, void (progress)(struct pkg *pkg, void *data),
if (!is_dir(path))
return (EPKG_FATAL);

repopath[0] = (char *)path;
repopath[0] = path;
repopath[1] = NULL;

snprintf(repodb, MAXPATHLEN, "%s/repo.db", path);
Expand Down Expand Up @@ -106,42 +106,44 @@ pkg_create_repo(const char *path, void (progress)(struct pkg *pkg, void *data),

if (progress != NULL)
progress(pkg, data);
sqlite3_bind_text(stmt_pkg, 1, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 2, pkg_get(pkg, PKG_NAME), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 3, pkg_get(pkg, PKG_VERSION), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 4, pkg_get(pkg, PKG_COMMENT), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 5, pkg_get(pkg, PKG_DESC), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 6, pkg_get(pkg, PKG_ARCH), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 7, pkg_get(pkg, PKG_OSVERSION), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 8, pkg_get(pkg, PKG_MAINTAINER), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_pkg, 9, pkg_get(pkg, PKG_WWW), -1, SQLITE_TRANSIENT);

/* Compute the fat size (uncompressed) */
if ((files = pkg_files(pkg)) != NULL) {
for (i = 0; files[i] != NULL; i++) {
flatsize += pkg_file_size(files[i]);
}
}

sqlite3_bind_text(stmt_pkg, 1, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 2, pkg_get(pkg, PKG_NAME), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 3, pkg_get(pkg, PKG_VERSION), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 4, pkg_get(pkg, PKG_COMMENT), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 5, pkg_get(pkg, PKG_DESC), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 6, pkg_get(pkg, PKG_ARCH), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 7, pkg_get(pkg, PKG_OSVERSION), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 8, pkg_get(pkg, PKG_MAINTAINER), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_pkg, 9, pkg_get(pkg, PKG_WWW), -1, SQLITE_STATIC);
sqlite3_bind_int(stmt_pkg, 11, ent->fts_statp->st_size);
sqlite3_bind_int(stmt_pkg, 12, flatsize);

sqlite3_step(stmt_pkg);
sqlite3_reset(stmt_pkg);

if ((deps = pkg_deps(pkg)) != NULL) {
for (i = 0; deps[i] != NULL; i++) {
sqlite3_bind_text(stmt_deps, 1, pkg_get(deps[i], PKG_ORIGIN), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_deps, 2, pkg_get(deps[i], PKG_NAME), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_deps, 3, pkg_get(deps[i], PKG_VERSION), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_deps, 4, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt_deps, 1, pkg_get(deps[i], PKG_ORIGIN), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_deps, 2, pkg_get(deps[i], PKG_NAME), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_deps, 3, pkg_get(deps[i], PKG_VERSION), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt_deps, 4, pkg_get(pkg, PKG_ORIGIN), -1, SQLITE_STATIC);

sqlite3_step(stmt_deps);
sqlite3_reset(stmt_deps);
}
}

if ((files = pkg_files(pkg)) != NULL) {
for (i = 0; files[i] != NULL; i++) {
flatsize += pkg_file_size(files[i]);
}
}

sqlite3_bind_int(stmt_pkg, 12, flatsize);

pkg_free(pkg);
}
fts_close(fts);

sqlite3_finalize(stmt_pkg);
sqlite3_finalize(stmt_deps);
Expand Down

0 comments on commit 31ccec6

Please sign in to comment.