summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-03-16 16:52:14 +0200
committerTimo Teräs <timo.teras@iki.fi>2011-03-16 16:53:07 +0200
commit93eb38a31ae97f1cb470f18c6019ede19c5c314e (patch)
tree55d46db3a9accd28bb19dc95127a40e96e1b59a5 /src/io.c
parent2222a15eddad9c5fac8d032f51f65811c0947495 (diff)
downloadapk-tools-93eb38a31ae97f1cb470f18c6019ede19c5c314e.tar.gz
apk-tools-93eb38a31ae97f1cb470f18c6019ede19c5c314e.tar.bz2
apk-tools-93eb38a31ae97f1cb470f18c6019ede19c5c314e.tar.xz
apk-tools-93eb38a31ae97f1cb470f18c6019ede19c5c314e.zip
db: relocate from /var/lib/apk
move all files therein to other places. this allows /var to be mounted from harddisk, but rest of system be run from ramdisk. this also removes support for historical version of the scripts database which was obsoleted in 2.0_pre16 (in July 2009).
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index 7eecbf8..e4b3710 100644
--- a/src/io.c
+++ b/src/io.c
@@ -739,6 +739,37 @@ size_t apk_ostream_write_string(struct apk_ostream *os, const char *string)
return len;
}
+int apk_move_file(int atfd, const char *from, const char *to)
+{
+ struct apk_istream *is;
+ struct stat64 st;
+ int rc, tofd;
+
+ if (renameat(atfd, from, atfd, to) == 0)
+ return 0;
+
+ if (fstatat64(atfd, from, &st, 0) != 0)
+ return -errno;
+
+ is = apk_istream_from_file(atfd, from);
+ if (is == NULL)
+ return -ENOENT;
+
+ tofd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (tofd < 0) {
+ rc = -errno;
+ goto close_is;
+ }
+
+ rc = apk_istream_splice(is, tofd, st.st_size, NULL, NULL);
+ close(tofd);
+ unlinkat(atfd, from, 0);
+close_is:
+ is->close(is);
+ return rc;
+}
+
struct cache_item {
apk_hash_node hash_node;
unsigned int genid;