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

View File

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

View File

@ -27,7 +27,9 @@ struct cpio_entry : public cpio_entry_base {
std::string filename; std::string filename;
cpio_entry() = default; 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(int fd, cpio_newc_header &header);
~cpio_entry() override; ~cpio_entry() override;
}; };