async detectOrRemoveOldArtifacts()

in src/util/adb.js [166:204]


  async detectOrRemoveOldArtifacts(deviceId, removeArtifactDirs = false) {
    const { adbClient } = this;

    log.debug('Checking adb device for existing web-ext artifacts dirs');

    return wrapADBCall(async () => {
      const files = await adbClient
        .getDevice(deviceId)
        .readdir(DEVICE_DIR_BASE);
      let found = false;

      for (const file of files) {
        if (
          !file.isDirectory() ||
          !file.name.startsWith(ARTIFACTS_DIR_PREFIX)
        ) {
          continue;
        }

        // Return earlier if we only need to warn the user that some
        // existing artifacts dirs have been found on the adb device.
        if (!removeArtifactDirs) {
          return true;
        }

        found = true;

        const artifactsDir = `${DEVICE_DIR_BASE}${file.name}`;

        log.debug(
          `Removing artifacts directory ${artifactsDir} from device ${deviceId}`,
        );

        await this.runShellCommand(deviceId, ['rm', '-rf', artifactsDir]);
      }

      return found;
    });
  }