summaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2008-11-14 14:26:59 +0200
committerTimo Teras <timo.teras@iki.fi>2008-11-14 14:26:59 +0200
commit8e23a2ba4eb7f6192c6bce8a6da81004803eca3f (patch)
tree1450b08f0e2818a4bc12206081b6777b3e92b7f8 /src/io.c
parent86676ac8c40a96880f323c2b1a09a5714d85705e (diff)
downloadapk-tools-8e23a2ba4eb7f6192c6bce8a6da81004803eca3f.tar.bz2
apk-tools-8e23a2ba4eb7f6192c6bce8a6da81004803eca3f.tar.xz
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.
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c45
1 files changed, 28 insertions, 17 deletions
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;
+}