summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-07-23 14:39:38 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-07-23 15:08:40 +0300
commitc13969849d6d072c22ae4a2eddb40c0974b70a31 (patch)
tree49b62b736c4e045f80ddf1d8556c04b999029b64 /src/io.c
parent6854da9271bf30dc8273ca446dd5f18b4036c7a9 (diff)
downloadapk-tools-c13969849d6d072c22ae4a2eddb40c0974b70a31.tar.gz
apk-tools-c13969849d6d072c22ae4a2eddb40c0974b70a31.tar.bz2
apk-tools-c13969849d6d072c22ae4a2eddb40c0974b70a31.tar.xz
apk-tools-c13969849d6d072c22ae4a2eddb40c0974b70a31.zip
db: allow read-only operations without cache
fixes #10748
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index b693ac4..22ef386 100644
--- a/src/io.c
+++ b/src/io.c
@@ -34,6 +34,11 @@
size_t apk_io_bufsize = 128*1024;
+static inline int atfd_error(int atfd)
+{
+ return atfd < -1 && atfd != AT_FDCWD;
+}
+
static void apk_file_meta_from_fd(int fd, struct apk_file_meta *meta)
{
struct stat st;
@@ -314,6 +319,7 @@ struct apk_istream *apk_istream_tee(struct apk_istream *from, int atfd, const ch
int fd, r;
if (IS_ERR_OR_NULL(from)) return ERR_CAST(from);
+ if (atfd_error(atfd)) return ERR_PTR(atfd);
fd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -482,6 +488,8 @@ struct apk_istream *apk_istream_from_file(int atfd, const char *file)
{
int fd;
+ if (atfd_error(atfd)) return ERR_PTR(atfd);
+
fd = openat(atfd, file, O_RDONLY | O_CLOEXEC);
if (fd < 0) return ERR_PTR(-errno);
@@ -604,6 +612,8 @@ apk_blob_t apk_blob_from_file(int atfd, const char *file)
struct stat st;
char *buf;
+ if (atfd_error(atfd)) return APK_BLOB_NULL;
+
fd = openat(atfd, file, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return APK_BLOB_NULL;
@@ -631,6 +641,8 @@ int apk_blob_to_file(int atfd, const char *file, apk_blob_t b, unsigned int flag
{
int fd, r, len;
+ if (atfd_error(atfd)) return atfd;
+
fd = openat(atfd, file, O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
if (fd < 0)
return -errno;
@@ -707,6 +719,9 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags,
unsigned int xattr_checksum = (flags >> 8) & 0xff;
int atflags = 0;
+ if (atfd_error(atfd)) return atfd;
+
+ memset(fi, 0, sizeof *fi);
if (flags & APK_FI_NOFOLLOW)
atflags |= AT_SYMLINK_NOFOLLOW;
@@ -959,6 +974,8 @@ struct apk_ostream *apk_ostream_to_file(int atfd,
struct apk_ostream *os;
int fd;
+ if (atfd_error(atfd)) return ERR_PTR(atfd);
+
fd = openat(atfd, tmpfile ?: file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, mode);
if (fd < 0) return ERR_PTR(-errno);