diff --git a/test/mavsdk_tests/process_helper.py b/test/mavsdk_tests/process_helper.py index 587cc7f9ec..513abbb726 100644 --- a/test/mavsdk_tests/process_helper.py +++ b/test/mavsdk_tests/process_helper.py @@ -176,15 +176,24 @@ class Px4Runner(Runner): def clear_rootfs(self) -> None: rootfs_path = self.cwd if self.verbose: - print("Deleting rootfs: {}".format(rootfs_path)) - if os.path.isdir(rootfs_path): - shutil.rmtree(rootfs_path) + print("Clearing rootfs (except logs): {}".format(rootfs_path)) + for item in os.listdir(rootfs_path): + if item == 'log': + continue + path = os.path.join(rootfs_path, item) + if os.path.isfile(path) or os.path.islink(path): + os.remove(path) + else: + shutil.rmtree(path) def create_rootfs(self) -> None: rootfs_path = self.cwd if self.verbose: print("Creating rootfs: {}".format(rootfs_path)) - os.makedirs(rootfs_path) + try: + os.makedirs(rootfs_path) + except FileExistsError: + pass class GzserverRunner(Runner):