mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 05:27:38 +00:00
Add symlink feature to cpio
This commit is contained in:
parent
2e25431bb6
commit
2212800a23
@ -47,6 +47,7 @@ void dump_cpio(struct vector *v, const char *filename);
|
||||
void cpio_vec_destroy(struct vector *v);
|
||||
void cpio_rm(struct vector *v, int recursive, const char *entry);
|
||||
void cpio_mkdir(struct vector *v, mode_t mode, const char *entry);
|
||||
void cpio_ln(struct vector *v, const char *target, const char *entry);
|
||||
void cpio_add(struct vector *v, mode_t mode, const char *entry, const char *filename);
|
||||
int cpio_mv(struct vector *v, const char *from, const char *to);
|
||||
int cpio_extract(struct vector *v, const char *entry, const char *filename);
|
||||
|
@ -35,9 +35,11 @@ static void usage(char *arg0) {
|
||||
" Do cpio related cmds to <incpio> (modifications are done directly)\n"
|
||||
" Supported commands:\n"
|
||||
" -rm [-r] <entry>\n"
|
||||
" Remove entry from <incpio>, flag -r to remove recursively\n"
|
||||
" Remove entry from <incpio>, flag [-r] to remove recursively\n"
|
||||
" -mkdir <mode> <entry>\n"
|
||||
" Create directory as an <entry>\n"
|
||||
" -ln <target> <entry>\n"
|
||||
" Create symlink <entry> to point to <target>\n"
|
||||
" -add <mode> <entry> <infile>\n"
|
||||
" Add <infile> as an <entry>; replaces <entry> if already exists\n"
|
||||
" -mv <from-entry> <to-entry>\n"
|
||||
|
@ -105,6 +105,8 @@ int cpio_commands(const char *command, int argc, char *argv[]) {
|
||||
return cpio_extract(&v, argv[0], argv[1]);
|
||||
} else if (argc == 2 && strcmp(command, "mkdir") == 0) {
|
||||
cpio_mkdir(&v, strtoul(argv[0], NULL, 8), argv[1]);
|
||||
} else if (argc == 2 && strcmp(command, "ln") == 0) {
|
||||
cpio_ln(&v, argv[0], argv[1]);
|
||||
} else if (argc == 3 && strcmp(command, "add") == 0) {
|
||||
cpio_add(&v, strtoul(argv[0], NULL, 8), argv[1], argv[2]);
|
||||
} else {
|
||||
|
@ -164,6 +164,15 @@ void cpio_mkdir(struct vector *v, mode_t mode, const char *entry) {
|
||||
fprintf(stderr, "Create directory [%s] (%04o)\n",entry, mode);
|
||||
}
|
||||
|
||||
void cpio_ln(struct vector *v, const char *target, const char *entry) {
|
||||
cpio_entry *f = xcalloc(sizeof(*f), 1);
|
||||
f->mode = S_IFLNK;
|
||||
f->filename = strdup(entry);
|
||||
f->data = strdup(target);
|
||||
cpio_vec_insert(v, f);
|
||||
fprintf(stderr, "Create symlink [%s] -> [%s]\n", entry, target);
|
||||
}
|
||||
|
||||
void cpio_add(struct vector *v, mode_t mode, const char *entry, const char *filename) {
|
||||
int fd = xopen(filename, O_RDONLY);
|
||||
cpio_entry *f = xcalloc(sizeof(*f), 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user