Просмотр исходного кода

dpkg: Compute and track hashes for newly unpacked file

This will be used for checksum generation at unpack time, and for shared
file verification.
Guillem Jover лет назад: 14
Родитель
Сommit
1309c6a7d3
3 измененных файлов с 14 добавлено и 4 удалено
  1. 9 4
      src/archives.c
  2. 2 0
      src/filesdb.c
  3. 3 0
      src/filesdb.h

+ 9 - 4
src/archives.c

@@ -254,6 +254,7 @@ tarobject_extract(struct tarcontext *tc, struct tar_entry *te,
 
   struct filenamenode *linknode;
   char fnamebuf[256];
+  char *newhash;
 
   switch (te->type) {
   case tar_filetype_file:
@@ -267,9 +268,12 @@ tarobject_extract(struct tarcontext *tc, struct tar_entry *te,
     debug(dbg_eachfiledetail, "tarobject file open size=%jd",
           (intmax_t)te->size);
 
-    fd_fd_copy(tc->backendpipe, fd, te->size,
-               _("backend dpkg-deb during `%.255s'"),
-               path_quote_filename(fnamebuf, te->name, 256));
+    newhash = nfmalloc(MD5HASHLEN + 1);
+    fd_fd_copy_and_md5(tc->backendpipe, fd, newhash, te->size,
+                       _("backend dpkg-deb during `%.255s'"),
+                       path_quote_filename(fnamebuf, te->name, 256));
+    namenode->newhash = newhash;
+    debug(dbg_eachfiledetail, "tarobject file hash=%s", namenode->newhash);
 
     tarobject_skip_padding(tc, te);
 
@@ -320,7 +324,8 @@ tarobject_extract(struct tarcontext *tc, struct tar_entry *te,
     varbuf_end_str(&hardlinkfn);
     if (link(hardlinkfn.buf, path))
       ohshite(_("error creating hard link `%.255s'"), te->name);
-    debug(dbg_eachfiledetail, "tarobject hardlink");
+    namenode->newhash = linknode->newhash;
+    debug(dbg_eachfiledetail, "tarobject hardlink hash=%s", namenode->newhash);
     break;
   case tar_filetype_symlink:
     /* We've already checked for an existing directory. */

+ 2 - 0
src/filesdb.c

@@ -628,6 +628,7 @@ void filesdbinit(void) {
     for (fnn= bins[i]; fnn; fnn= fnn->next) {
       fnn->flags= 0;
       fnn->oldhash = NULL;
+      fnn->newhash = EMPTYHASHFLAG;
       fnn->filestat = NULL;
     }
 }
@@ -671,6 +672,7 @@ struct filenamenode *findnamenode(const char *name, enum fnnflags flags) {
   newnode->next = NULL;
   newnode->divert = NULL;
   newnode->statoverride = NULL;
+  newnode->newhash = EMPTYHASHFLAG;
   newnode->filestat = NULL;
   newnode->trig_interested = NULL;
   *pointerp= newnode;

+ 3 - 0
src/filesdb.h

@@ -97,6 +97,9 @@ struct filenamenode {
   /* Valid iff this namenode is in the newconffiles list. */
   const char *oldhash;
 
+  /* Valid iff the file was unpacked and hashed on this run. */
+  const char *newhash;
+
   struct stat *filestat;
   struct trigfileint *trig_interested;
 };