Commit a7957e26 authored by Mike Hibler's avatar Mike Hibler

Fix up writing of delta image signature file.

Also added option (-F) to write full-image signature (what we do).
parent 29628dee
......@@ -95,6 +95,7 @@ static int forcesig = 0;
static int debug = 0;
static int verify = 0;
static int clevel = 4;
static int fullsig = 0;
static int hashtype = HASH_TYPE_SHA1;
static int hashlen = 20;
static long hashblksize = HASHBLK_SIZE / 512;
......@@ -110,6 +111,7 @@ usage(void)
"\n"
"-S Use signature files when computing differences.\n"
"-V Verify consistency of image and signature.\n"
"-F Generate a full-image signature for the delta.\n"
"-f Force imagedelta to use a questionable sigfile.\n"
"-d Enable debugging.\n"
"-D hfunc Hash function to use (md5 or sha1).\n"
......@@ -663,7 +665,7 @@ main(int argc, char **argv)
{
int ch;
while ((ch = getopt(argc, argv, "SfdVb:D:")) != -1)
while ((ch = getopt(argc, argv, "SfdVb:D:F")) != -1)
switch(ch) {
case 'S':
usesigfiles = 1;
......@@ -704,6 +706,9 @@ main(int argc, char **argv)
usage();
}
break;
case 'F':
fullsig = 1;
break;
case 'h':
case '?':
default:
......@@ -856,8 +861,12 @@ main(int argc, char **argv)
}
free(cstate);
/* readjust to reflect the actual number of hash entries */
delta.ndz->hashentries = delta.ndz->hashcurentry;
/* write the new sigfile */
if (ndz_writehashinfo(delta.ndz, delta.sigfile) != 0) {
if (ndz_writehashinfo(fullsig ? ndz2.ndz : delta.ndz,
delta.sigfile, argv[2]) != 0) {
fprintf(stderr, "%s: could not write signature file %s\n",
argv[2], delta.sigfile);
}
......
......@@ -246,11 +246,10 @@ writehinfo(struct ndz_rangemap *map, struct ndz_range *range, void *arg)
* Write out hash (signature) info associated with the named image.
*/
int
ndz_writehashinfo(struct ndz_file *ndz, char *sigfile)
ndz_writehashinfo(struct ndz_file *ndz, char *sigfile, char *ifile)
{
int ofd, cc;
struct hashinfo hi;
char *iname;
if (ndz == NULL || ndz->hashmap == NULL || sigfile == NULL)
return -1;
......@@ -261,7 +260,8 @@ ndz_writehashinfo(struct ndz_file *ndz, char *sigfile)
return -1;
}
iname = ndz->fname;
if (ifile == NULL)
ifile = ndz->fname;
memset(&hi, 0, sizeof(hi));
strcpy((char *)hi.magic, HASH_MAGIC);
......@@ -277,7 +277,7 @@ ndz_writehashinfo(struct ndz_file *ndz, char *sigfile)
else
fprintf(stderr,
"%s: incomplete write (%d) to sigfile %s\n",
iname, cc, sigfile);
ifile, cc, sigfile);
close(ofd);
unlink(sigfile);
return -1;
......@@ -290,7 +290,7 @@ ndz_writehashinfo(struct ndz_file *ndz, char *sigfile)
(void *)(uintptr_t)ofd) != 0) {
fprintf(stderr,
"%s: could not write one or more hash entries to sigfile %s\n",
ndz->fname, sigfile);
ifile, sigfile);
close(ofd);
unlink(sigfile);
return -1;
......@@ -303,11 +303,11 @@ ndz_writehashinfo(struct ndz_file *ndz, char *sigfile)
* This is a crude (but fast!) method for matching images with
* signatures.
*/
if (strcmp(iname, "-") != 0) {
if (strcmp(ifile, "-") != 0) {
struct stat sb;
struct timeval tm[2];
cc = stat(iname, &sb);
cc = stat(ifile, &sb);
if (cc >= 0) {
#ifdef linux
tm[0].tv_sec = sb.st_atime;
......@@ -326,7 +326,7 @@ ndz_writehashinfo(struct ndz_file *ndz, char *sigfile)
sigfile, strerror(errno));
}
fprintf(stderr, "%s: new signature written to %s\n", iname, sigfile);
fprintf(stderr, "%s: new signature written to %s\n", ifile, sigfile);
return 0;
}
......
......@@ -104,7 +104,7 @@ ssize_t ndz_chunk_left(ndz_chunk_t chobj);
ssize_t ndz_chunk_append(ndz_chunk_t chobj, void *buf, size_t bytes);
struct ndz_rangemap *ndz_readhashinfo(struct ndz_file *ndz, char *sigfile);
int ndz_writehashinfo(struct ndz_file *ndz, char *sigfile);
int ndz_writehashinfo(struct ndz_file *ndz, char *sigfile, char *ifile);
void ndz_hash_data(struct ndz_file *ndz, unsigned char *data,
unsigned long count, unsigned char *hash);
char *ndz_hash_dump(unsigned char *h, int hlen);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment