Set mode in constructor

This commit is contained in:
topjohnwu 2019-02-23 15:22:11 -05:00
parent 9c89e56c56
commit 4a398642b8
3 changed files with 9 additions and 14 deletions

View File

@ -134,8 +134,7 @@ void magisk_cpio::backup(const char *orig) {
entry_map bkup_entries;
string remv;
auto b = new cpio_entry(".backup");
b->mode = S_IFDIR;
auto b = new cpio_entry(".backup", S_IFDIR);
bkup_entries[b->filename].reset(b);
magisk_cpio o(orig);
@ -195,8 +194,7 @@ void magisk_cpio::backup(const char *orig) {
}
if (!remv.empty()) {
auto rmlist = new cpio_entry(".backup/.rmlist");
rmlist->mode = S_IFREG;
auto rmlist = new cpio_entry(".backup/.rmlist", S_IFREG);
rmlist->filesize = remv.length();
rmlist->data = xmalloc(remv.length());
memcpy(rmlist->data, remv.data(), remv.length());
@ -216,8 +214,7 @@ void magisk_cpio::compress() {
encoder.finalize();
entries.clear();
entries.insert(std::move(init));
auto xz = new cpio_entry(ramdisk_xz);
xz->mode = S_IFREG;
auto xz = new cpio_entry(ramdisk_xz, S_IFREG);
static_cast<BufOutStream *>(encoder.get_out())->release(xz->data, xz->filesize);
insert(xz);
}

View File

@ -197,8 +197,7 @@ void cpio_rw::add(mode_t mode, const char *name, const char *file) {
void *buf;
size_t sz;
mmap_ro(file, &buf, &sz);
auto e = new cpio_entry(name);
e->mode = S_IFREG | mode;
auto e = new cpio_entry(name, S_IFREG | mode);
e->filesize = sz;
e->data = xmalloc(sz);
memcpy(e->data, buf, sz);
@ -208,15 +207,12 @@ void cpio_rw::add(mode_t mode, const char *name, const char *file) {
}
void cpio_rw::makedir(mode_t mode, const char *name) {
auto e = new cpio_entry(name);
e->mode = S_IFDIR | mode;
insert(e);
insert(new cpio_entry(name, S_IFDIR | mode));
fprintf(stderr, "Create directory [%s] (%04o)\n", name, mode);
}
void cpio_rw::ln(const char *target, const char *name) {
auto e = new cpio_entry(name);
e->mode = S_IFLNK;
auto e = new cpio_entry(name, S_IFLNK);
e->filesize = strlen(target);
e->data = strdup(target);
insert(e);

View File

@ -27,7 +27,9 @@ struct cpio_entry : public cpio_entry_base {
std::string filename;
cpio_entry() = default;
explicit cpio_entry(const char *name) : filename(name) {}
explicit cpio_entry(const char *name, uint32_t mode) : filename(name) {
this->mode = mode;
}
cpio_entry(int fd, cpio_newc_header &header);
~cpio_entry() override;
};