unsigned char tmp[32];
hash_state md;
sqlite3_stmt *ifile;
- int haverow,havedata;
+ int haverow = 0,havedata = 0;
int j,rc,type;
char hashbuf[65];
sprintf(hash+j*2, "%02x", (unsigned)tmp[j]);
}
hash[64] = 0;
-// fprintf(stderr, "file %s: %s\n", path, hash);
+ fprintf(stderr, "file %s: %s\n", path, hash);
- /* compress */
- outbuf = compresslzma(content, sbuf.st_size, &outlen);
-// fprintf(stderr, "compressed to %zu\n", outlen);
-
- /* don't need the original file now */
- munmap(content, sbuf.st_size);
- close(fd);
/* prepare and bind */
/* TODO check null */
rc = sqlite3_prepare(db, "select size, content is not null from files where hash = ?", -1, &ifile,0);
if (rc != SQLITE_OK) {
SQLERROR(sqlite3_errmsg(db));
- return 1;
+ return 0;
}
/* hash, filename */
sqlite3_finalize(ifile);
if (!havedata) {
+ /* compress */
+ outbuf = compresslzma(content, sbuf.st_size, &outlen);
+ if (!outbuf) {
+ fprintf(stderr, "compresslzma failed\n");
+ return 0;
+ }
+ fprintf(stderr, "compressed to %zu\n", outlen);
+ /* don't need the original file now */
+ munmap(content, sbuf.st_size);
+ close(fd);
+
/* start a transaction */
// do that outside of here
//zpm_begin(pkg);
/* insert */
if (haverow) {
+ fprintf(stderr, "adding file data\n");
rc = sqlite3_prepare(db, "update files set size = ?, content = ? where hash = ?", -1, &ifile,0);
} else {
-// fprintf(stderr, "missing file data\n");
+ fprintf(stderr, "creating new data row\n");
rc = sqlite3_prepare(db, "insert into files (size, content, hash) values (?,?,?)", -1, &ifile,0);
}
if (rc != SQLITE_OK) {
/* commit */
//zpm_commit(pkg);
+ } else {
+ /* don't need the original file now */
+ munmap(content, sbuf.st_size);
+ close(fd);
}
+
/* if package and not nopackage flag, add to package */
if (pkg->pkgname && (!ZPM_NOPACKAGE)) {
/* TODO */