diff options
author | Timo Teräs <timo.teras@iki.fi> | 2012-02-14 15:51:12 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2012-02-14 15:51:26 +0200 |
commit | 97bd260bfd27337ff348180ecc51a8eb798a2651 (patch) | |
tree | 5bdf2eb09cc4fcef6b9455264371e05deae7ec78 /src | |
parent | 087c587e57b057cb03791b778c1a25dc07b8a243 (diff) | |
download | apk-tools-97bd260bfd27337ff348180ecc51a8eb798a2651.tar.gz apk-tools-97bd260bfd27337ff348180ecc51a8eb798a2651.tar.bz2 apk-tools-97bd260bfd27337ff348180ecc51a8eb798a2651.tar.xz apk-tools-97bd260bfd27337ff348180ecc51a8eb798a2651.zip |
db: record file uid/gid/mode in installed db
Diffstat (limited to 'src')
-rw-r--r-- | src/apk_database.h | 10 | ||||
-rw-r--r-- | src/database.c | 28 | ||||
-rw-r--r-- | src/package.c | 1 |
3 files changed, 34 insertions, 5 deletions
diff --git a/src/apk_database.h b/src/apk_database.h index 17be61c..690b757 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -48,6 +48,10 @@ struct apk_db_file { struct hlist_node diri_files_list; struct apk_db_dir_instance *diri; + mode_t mode; + uid_t uid; + gid_t gid; + unsigned short namelen; struct apk_checksum csum; char name[]; @@ -60,14 +64,14 @@ struct apk_db_file { struct apk_db_dir { apk_hash_node hash_node; - unsigned long hash; struct apk_db_dir *parent; - unsigned short refs; - unsigned short namelen; mode_t mode; uid_t uid; gid_t gid; + + unsigned short refs; + unsigned short namelen; unsigned char flags; char rooted_name[1]; char name[]; diff --git a/src/database.c b/src/database.c index 75b58a6..35479d4 100644 --- a/src/database.c +++ b/src/database.c @@ -383,7 +383,7 @@ static void apk_db_dir_apply_diri_permissions(struct apk_db_dir_instance *diri) static void apk_db_diri_set(struct apk_db_dir_instance *diri, mode_t mode, uid_t uid, gid_t gid) { - diri->mode = mode; + diri->mode = mode & 07777; diri->uid = uid; diri->gid = gid; apk_db_dir_apply_diri_permissions(diri); @@ -438,6 +438,13 @@ static struct apk_db_file *apk_db_file_new(struct apk_db_dir_instance *diri, return file; } +static void apk_db_file_set(struct apk_db_file *file, mode_t mode, uid_t uid, gid_t gid) +{ + file->mode = mode & 07777; + file->uid = uid; + file->gid = gid; +} + static struct apk_db_file *apk_db_file_get(struct apk_database *db, struct apk_db_dir_instance *diri, apk_blob_t name, @@ -707,6 +714,11 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) diri = apk_db_diri_new(db, pkg, l, &diri_node); file_diri_node = &diri->owned_files.first; break; + case 'a': + if (file == NULL) { + apk_error("FDB file attribute metadata entry before file entry"); + return -1; + } case 'M': if (diri == NULL) { apk_error("FDB directory metadata entry before directory entry"); @@ -717,7 +729,10 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) gid = apk_blob_pull_uint(&l, 10); apk_blob_pull_char(&l, ':'); mode = apk_blob_pull_uint(&l, 8); - apk_db_diri_set(diri, mode, uid, gid); + if (field == 'M') + apk_db_diri_set(diri, mode, uid, gid); + else + apk_db_file_set(file, mode, uid, gid); break; case 'R': if (diri == NULL) { @@ -800,6 +815,14 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os) hlist_for_each_entry(file, c2, &diri->owned_files, diri_files_list) { apk_blob_push_blob(&bbuf, APK_BLOB_STR("R:")); apk_blob_push_blob(&bbuf, APK_BLOB_PTR_LEN(file->name, file->namelen)); + if (file->mode != 0 || file->uid != 0 || file->gid != 0) { + apk_blob_push_blob(&bbuf, APK_BLOB_STR("\na:")); + apk_blob_push_uint(&bbuf, file->uid, 10); + apk_blob_push_blob(&bbuf, APK_BLOB_STR(":")); + apk_blob_push_uint(&bbuf, file->gid, 10); + apk_blob_push_blob(&bbuf, APK_BLOB_STR(":")); + apk_blob_push_uint(&bbuf, file->mode, 8); + } if (file->csum.type != APK_CHECKSUM_NONE) { apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nZ:")); apk_blob_push_csum(&bbuf, &file->csum); @@ -2067,6 +2090,7 @@ static int apk_db_install_archive_entry(void *_ctx, apk_message("%s", ae->name); /* Extract the file as name.apk-new */ + apk_db_file_set(file, ae->mode, ae->uid, ae->gid); r = apk_archive_entry_extract(db->root_fd, ae, ".apk-new", is, extract_cb, ctx); diff --git a/src/package.c b/src/package.c index 20895cb..1c85e12 100644 --- a/src/package.c +++ b/src/package.c @@ -739,6 +739,7 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg, pkg->commit = apk_blob_cstr(value); break; case 'F': case 'M': case 'R': case 'Z': case 'r': case 'q': + case 'a': /* installed db entries which are handled in database.c */ return 1; default: |