xref: /aosp_15_r20/external/skia/infra/bots/recipe_modules/flavor/resources/remove_file_on_device.py (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1# Copyright 2024 Google LLC
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import subprocess
7import sys
8
9# Remove the path.
10adb = sys.argv[1]
11path = sys.argv[2]
12print('Removing %s' % path)
13cmd = [adb, 'shell', 'rm', '-rf', path]
14print(' '.join(cmd))
15subprocess.check_call(cmd)
16
17# Verify that the path was deleted.
18print('Checking for existence of %s' % path)
19cmd = [adb, 'shell', 'ls', path]
20print(' '.join(cmd))
21try:
22    output = subprocess.check_output(
23        cmd, stderr=subprocess.STDOUT).decode('utf-8')
24except subprocess.CalledProcessError as e:
25    output = e.output.decode('utf-8')
26print('Output was:')
27print('======')
28print(output)
29print('======')
30if 'No such file or directory' not in output:
31    raise Exception('%s exists despite being deleted' % path)
32