Skip to content

Commit

Permalink
Use full path in tmp cache directory name to reduce likelihood of a c…
Browse files Browse the repository at this point in the history
…onflict.

PiperOrigin-RevId: 676472711
  • Loading branch information
The android_world Authors committed Sep 19, 2024
1 parent 3d88d09 commit d86f52d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion android_world/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import datetime
import os
import random
import re
import shutil
import string
from typing import Iterator
Expand Down Expand Up @@ -302,7 +303,7 @@ def tmp_directory_from_device(
FileNotFoundError: If the remote directory does not exist.
RuntimeError: If there is an adb communication error.
"""
directory_name = os.path.split(device_path)[-1]
directory_name = re.sub(r"\W", "", device_path)
tmp_directory = os.path.join(TMP_LOCAL_LOCATION, directory_name)
logging.info(
"Copying %s directory to local tmp %s", device_path, tmp_directory
Expand Down
6 changes: 3 additions & 3 deletions android_world/utils/file_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ def test_tmp_directory_from_device(
),
)

tmp_local_directory = os.path.join(file_utils.TMP_LOCAL_LOCATION, 'dir')
tmp_local_directory = f'{file_utils.TMP_LOCAL_LOCATION}/remotedir'
with file_utils.tmp_directory_from_device(
'/remote/dir', self.mock_env
'/remotedir', self.mock_env
) as tmp_directory:
self.assertEqual(tmp_local_directory, tmp_directory)
self.mock_env.execute_adb_call.assert_has_calls([
mock.call(
adb_pb2.AdbRequest(
pull=adb_pb2.AdbRequest.Pull(
path=os.path.join('/remote/dir/', file_name)
path=os.path.join('/remotedir/', file_name)
),
timeout_sec=None,
)
Expand Down

0 comments on commit d86f52d

Please sign in to comment.