summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2020-05-19 11:39:21 +0300
committerTimo Teräs <timo.teras@iki.fi>2020-05-19 12:02:56 +0300
commitd0edeec8fb8fa5abee8b3065cea5e4882d0c51c4 (patch)
tree10dbc6d72c9cef13a26cb539df43e92e4bf78d74 /src/io.c
parent12fdf6fc219321d22825042ae08efd322acc0310 (diff)
downloadapk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.gz
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.bz2
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.xz
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.zip
make the atom functions not use global state
This greatly helps with memory management on applications that may want to daemonize and open/close database several times. Also the lifetime and "owner" of memory for all data is now explicitly bound to owning struct apk_database, which might be helpful when writing language bindings. As side effect, the interned "atoms" are unique only within what apk_database, so comparing packages from different apk_database may not work as expected. Fixes #10697
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/io.c b/src/io.c
index 92f1a32..9643218 100644
--- a/src/io.c
+++ b/src/io.c
@@ -692,7 +692,7 @@ void apk_fileinfo_hash_xattr(struct apk_file_info *fi)
}
int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags,
- struct apk_file_info *fi)
+ struct apk_file_info *fi, struct apk_atom_pool *atoms)
{
struct stat64 st;
unsigned int checksum = flags & 0xff;
@@ -735,7 +735,7 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags,
}
*apk_xattr_array_add(&xattrs) = (struct apk_xattr) {
.name = &buf[i],
- .value = *apk_blob_atomize_dup(APK_BLOB_PTR_LEN(val, vlen)),
+ .value = *apk_atomize_dup(atoms, APK_BLOB_PTR_LEN(val, vlen)),
};
}
apk_fileinfo_hash_xattr_array(xattrs, apk_checksum_evp(xattr_checksum), &fi->xattr_csum);
@@ -747,11 +747,8 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags,
if (r && r != ENOTSUP) return -r;
}
- if (checksum == APK_CHECKSUM_NONE)
- return 0;
-
- if (S_ISDIR(st.st_mode))
- return 0;
+ if (checksum == APK_CHECKSUM_NONE) return 0;
+ if (S_ISDIR(st.st_mode)) return 0;
/* Checksum file content */
if ((flags & APK_FI_NOFOLLOW) && S_ISLNK(st.st_mode)) {