From e86e288151ba3fa883d850a56900889a9fe87667 Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Fri, 4 Aug 2023 21:37:05 +0800 Subject: [PATCH] feat(adb): allow `rm` to delete folders --- libraries/adb/src/adb.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/libraries/adb/src/adb.ts b/libraries/adb/src/adb.ts index c390f8f40..40b0b3a95 100644 --- a/libraries/adb/src/adb.ts +++ b/libraries/adb/src/adb.ts @@ -106,13 +106,27 @@ export class Adb implements Closeable { return stdout.trim(); } - async rm(...filenames: string[]): Promise { + async rm( + filenames: string | string[], + options?: { recursive?: boolean; force?: boolean }, + ): Promise { + const args = ["rm"]; + if (options?.recursive) { + args.push("-r"); + } + if (options?.force) { + args.push("-f"); + } + if (Array.isArray(filenames)) { + for (const filename of filenames) { + args.push(escapeArg(filename)); + } + } else { + args.push(escapeArg(filenames)); + } // https://android.googlesource.com/platform/packages/modules/adb/+/1a0fb8846d4e6b671c8aa7f137a8c21d7b248716/client/adb_install.cpp#984 - const stdout = await this.subprocess.spawnAndWaitLegacy([ - "rm", - ...filenames.map((arg) => escapeArg(arg)), - "