From 8e23a2ba4eb7f6192c6bce8a6da81004803eca3f Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Fri, 14 Nov 2008 14:26:59 +0200 Subject: db: checksum installed files, protect config files Checksum of installed is computed on the fly when extracting them and it'll be saved to fdb. When installing config files those are diverted with suffix .apk-new if earlier version of same file with local changes exist. --- src/io.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index 418c7f8..2bb8afc 100644 --- a/src/io.c +++ b/src/io.c @@ -47,22 +47,6 @@ static size_t fd_read(void *stream, void *ptr, size_t size) return i; } -static size_t fd_splice(void *stream, int fd, size_t size) -{ - struct apk_fd_istream *fis = - container_of(stream, struct apk_fd_istream, is); - size_t i = 0, r; - - while (i != size) { - r = splice(fis->fd, NULL, fd, NULL, size - i, SPLICE_F_MOVE); - if (r == -1) - return i; - i += r; - } - - return i; -} - static void fd_close(void *stream) { struct apk_fd_istream *fis = @@ -82,7 +66,6 @@ struct apk_istream *apk_istream_from_fd(int fd) *fis = (struct apk_fd_istream) { .is.read = fd_read, - .is.splice = fd_splice, .is.close = fd_close, .fd = fd, }; @@ -322,3 +305,31 @@ apk_blob_t apk_blob_from_istream(struct apk_istream *is, size_t size) return APK_BLOB_PTR_LEN(ptr, rsize); } +int apk_file_get_info(const char *filename, struct apk_file_info *fi) +{ + struct stat st; + struct apk_bstream *bs; + int fd; + + if (stat(filename, &st) != 0) + return -1; + + *fi = (struct apk_file_info) { + .size = st.st_size, + .uid = st.st_uid, + .gid = st.st_gid, + .mode = st.st_mode, + .mtime = st.st_mtime, + .device = st.st_dev, + }; + + fd = open(filename, O_RDONLY); + if (fd < 0) + return 0; + + bs = apk_bstream_from_fd(fd); + if (bs != NULL) + bs->close(bs, fi->csum); + + return 0; +} -- cgit v1.2.3