From 1fae89cbb6344f11fcf1c7b5dbaad5849061b34e Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 5 Dec 2018 20:27:48 -0500 Subject: [PATCH] Add new cpio command: "exists", to magiskboot --- native/jni/magiskboot/main.cpp | 2 ++ native/jni/magiskboot/ramdisk.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/native/jni/magiskboot/main.cpp b/native/jni/magiskboot/main.cpp index ef9020047..762b65aac 100644 --- a/native/jni/magiskboot/main.cpp +++ b/native/jni/magiskboot/main.cpp @@ -39,6 +39,8 @@ static void usage(char *arg0) { " Do cpio commands to (modifications are done directly)\n" " Each command is a single argument, use quotes if necessary\n" " Supported commands:\n" + " exists ENTRY\n" + " Return 0 if ENTRY exists, else return 1\n" " rm [-r] ENTRY\n" " Remove ENTRY, specify [-r] to remove recursively\n" " mkdir MODE ENTRY\n" diff --git a/native/jni/magiskboot/ramdisk.cpp b/native/jni/magiskboot/ramdisk.cpp index 4699c7928..df65dd415 100644 --- a/native/jni/magiskboot/ramdisk.cpp +++ b/native/jni/magiskboot/ramdisk.cpp @@ -230,7 +230,9 @@ int cpio_commands(int argc, char *argv[]) { char *sha1 = cpio.sha1(); if (sha1) printf("%s\n", sha1); return 0; - } else if (cmdc >= 2 && strcmp(cmdv[0], "backup") == 0) { + } else if (cmdc == 2 && strcmp(cmdv[0], "exists") == 0) { + exit(cpio.find(cmdv[1]) < 0); + } else if (cmdc == 2 && strcmp(cmdv[0], "backup") == 0) { cpio.backup(cmdv[1]); } else if (cmdc >= 2 && strcmp(cmdv[0], "rm") == 0) { bool r = cmdc > 2 && strcmp(cmdv[1], "-r") == 0;