Skip to content

Commit 5bda458

Browse files
committed
Fixes pull filename space issue
1 parent dc7059c commit 5bda458

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

ppadb/device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ def pull(self, src, dest):
8585
dest = Path(dest)
8686

8787
dir_string = "IS_DIR"
88-
res = self.shell(f"[ -d {src} ] && echo {dir_string}")
88+
res = self.shell(f"[ -d \"{src}\" ] && echo {dir_string}")
8989
if dir_string in res:
9090
# Get all files in the dir
9191
# Pull each
9292
dest.mkdir(exist_ok=True)
93-
cmd = f"ls -1a {src}"
93+
cmd = f"ls -1a \"{src}\""
9494
res = self.shell(cmd)
9595
contents_list = res.split("\n")
9696
contents_list = [
@@ -102,7 +102,7 @@ def pull(self, src, dest):
102102
self.pull(element_src, element_dest)
103103
else:
104104
file_string = "IS_FILE"
105-
res = self.shell(f"[ -f {src} ] && echo {file_string}")
105+
res = self.shell(f"[ -f \"{src}\" ] && echo {file_string}")
106106
if file_string not in res:
107107
raise FileNotFoundError(f"Cannot find {src} on device")
108108
self._pull(str(src), str(dest))

ppadb/device_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ async def pull(self, src, dest):
7070
dest = Path(dest)
7171

7272
dir_string = "IS_DIR"
73-
res = await self.shell(f"[ -d {src} ] && echo {dir_string}")
73+
res = await self.shell(f"[ -d \"{src}\" ] && echo {dir_string}")
7474
if dir_string in res:
7575
# Get all files in the dir
7676
# Pull each
7777
dest.mkdir(exist_ok=True)
78-
cmd = f"ls -1a {src}"
78+
cmd = f"ls -1a \"{src}\""
7979
res = await self.shell(cmd)
8080
contents_list = res.split("\n")
8181
contents_list = [
@@ -87,7 +87,7 @@ async def pull(self, src, dest):
8787
await self.pull(element_src, element_dest)
8888
else:
8989
file_string = "IS_FILE"
90-
res = await self.shell(f"[ -f {src} ] && echo {file_string}")
90+
res = await self.shell(f"[ -f \"{src}\" ] && echo {file_string}")
9191
if file_string not in res:
9292
raise FileNotFoundError(f"Cannot find {src} on device")
9393
await self._pull(str(src), str(dest))

test/test_device.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def test_filepaths():
192192
"toplevel/subdir1/test4.txt",
193193
"toplevel/subdir1/subdir2/test5.txt",
194194
"toplevel/subdir1/subdir2/test6.txt",
195+
"toplevel/subdir1/subdir2/file name.txt"
195196
]
196197
yield filepaths
197198

@@ -202,7 +203,7 @@ def populated_device(device, test_filepaths):
202203

203204
device.shell(f"mkdir -p /data/local/tmp/{dirpath}")
204205
for path in test_filepaths:
205-
device.shell(f"echo {path} > /data/local/tmp/{path}")
206+
device.shell(f"echo \"{path}\" > \"/data/local/tmp/{path}\"")
206207

207208
yield device
208209

@@ -214,7 +215,6 @@ def working_dir():
214215
with tempfile.TemporaryDirectory() as f:
215216
yield pathlib.Path(f)
216217

217-
218218
def test_pull_file(populated_device, working_dir):
219219
populated_device.pull(
220220
"/data/local/tmp/toplevel/test1.txt", working_dir / "test1.txt"
@@ -223,6 +223,13 @@ def test_pull_file(populated_device, working_dir):
223223
assert dest_path.is_file()
224224
assert dest_path.read_text() == "toplevel/test1.txt\n"
225225

226+
def test_pull_file_with_space(populated_device, working_dir):
227+
dest_path = working_dir / "file name.txt"
228+
populated_device.pull(
229+
"/data/local/tmp/toplevel/subdir1/subdir2/file name.txt", dest_path
230+
)
231+
assert dest_path.is_file()
232+
assert dest_path.read_text() == "toplevel/subdir1/subdir2/file name.txt"
226233

227234
def test_pull_dir(populated_device, working_dir):
228235
populated_device.pull(

0 commit comments

Comments
 (0)