diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-07-16 15:16:05 +0300 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-07-16 15:16:05 +0300 |
commit | 6b471bb614beaeadcfa08008918ef6a2d93ac7e0 (patch) | |
tree | fd46188956a5fb8c22801dc49efa5e8730b657c6 /src/archive.c | |
parent | 0f6d96a4f5a904fd95b96e13715b50befa6a0ee9 (diff) | |
download | apk-tools-6b471bb614beaeadcfa08008918ef6a2d93ac7e0.tar.gz apk-tools-6b471bb614beaeadcfa08008918ef6a2d93ac7e0.tar.bz2 apk-tools-6b471bb614beaeadcfa08008918ef6a2d93ac7e0.tar.xz apk-tools-6b471bb614beaeadcfa08008918ef6a2d93ac7e0.zip |
various: new style index generation
change the index generation to do old index, or the new style index
where package identity is sha1 of control block and it's contained
within an .tar.gz to allow signing in future.
Diffstat (limited to 'src/archive.c')
-rw-r--r-- | src/archive.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/archive.c b/src/archive.c index 8e55295..f30463f 100644 --- a/src/archive.c +++ b/src/archive.c @@ -93,7 +93,7 @@ static size_t tar_entry_read(void *stream, void *ptr, size_t size) return size; } -int apk_parse_tar(struct apk_istream *is, apk_archive_entry_parser parser, +int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser, void *ctx) { struct apk_file_info entry; @@ -205,11 +205,9 @@ err: return r; } -int apk_write_tar_entry(struct apk_ostream *os, const struct apk_file_info *ae, char *data) +int apk_tar_write_entry(struct apk_ostream *os, const struct apk_file_info *ae, char *data) { - static char padding[512]; struct tar_header buf; - int pad; memset(&buf, 0, sizeof(buf)); if (ae != NULL) { @@ -221,15 +219,17 @@ int apk_write_tar_entry(struct apk_ostream *os, const struct apk_file_info *ae, else return -1; - strncpy(buf.name, ae->name, sizeof(buf.name)); - strncpy(buf.uname, ae->uname, sizeof(buf.uname)); - strncpy(buf.gname, ae->gname, sizeof(buf.gname)); + if (ae->name != NULL) + strncpy(buf.name, ae->name, sizeof(buf.name)); + + strncpy(buf.uname, ae->uname ?: "root", sizeof(buf.uname)); + strncpy(buf.gname, ae->gname ?: "root", sizeof(buf.gname)); PUT_OCTAL(buf.size, ae->size); PUT_OCTAL(buf.uid, ae->uid); PUT_OCTAL(buf.gid, ae->gid); PUT_OCTAL(buf.mode, ae->mode & 07777); - PUT_OCTAL(buf.mtime, ae->mtime); + PUT_OCTAL(buf.mtime, ae->mtime ?: time(NULL)); /* Checksum */ strcpy(buf.magic, "ustar "); @@ -243,18 +243,33 @@ int apk_write_tar_entry(struct apk_ostream *os, const struct apk_file_info *ae, if (os->write(os, &buf, sizeof(buf)) != sizeof(buf)) return -1; - if (data != NULL) { + if (ae == NULL) { + /* End-of-archive is two empty headers */ + if (os->write(os, &buf, sizeof(buf)) != sizeof(buf)) + return -1; + } else if (data != NULL) { if (os->write(os, data, ae->size) != ae->size) return -1; - pad = 512 - (ae->size & 511); - if (pad != 512 && - os->write(os, padding, pad) != pad) + if (apk_tar_write_padding(os, ae) != 0) return -1; } return 0; } +int apk_tar_write_padding(struct apk_ostream *os, const struct apk_file_info *ae) +{ + static char padding[512]; + int pad; + + pad = 512 - (ae->size & 511); + if (pad != 512 && + os->write(os, padding, pad) != pad) + return -1; + + return 0; +} + int apk_archive_entry_extract(const struct apk_file_info *ae, struct apk_istream *is, const char *fn, apk_progress_cb cb, |