db: record file uid/gid/mode in installed db

cute-signatures
Timo Teräs 2012-02-14 15:51:12 +02:00
parent 087c587e57
commit 97bd260bfd
3 changed files with 34 additions and 5 deletions

View File

@ -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[];

View File

@ -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);

View File

@ -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: