Skip to content

Commit 250839e

Browse files
authored
修复windows端下载apk出现PermissionError (#195)
1.tempfile.NamedTemporaryFile创建的文件对象在默认情况下,会保持文件句柄打开(直到对象被垃圾回收或显式关闭)。 2.在 Windows 系统中,一个文件如果被某进程的句柄占用,其他操作(包括同一进程的写入)会被阻塞,导致后续download_apk报PermissionError(提示 “被另一个进程占用”)。
1 parent 8d033f4 commit 250839e

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

adbutils/install.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ def dprint(msg):
9292

9393
if isinstance(path_or_url, str) and re.match(r"^https?://", path_or_url):
9494
tmpfile = tempfile.NamedTemporaryFile(suffix=".apk")
95+
tmpfile.close()
9596
self.download_apk(path_or_url, Path(tmpfile.name))
96-
tmpfile.flush()
97-
tmpfile.seek(0)
9897
src_path = Path(tmpfile.name)
9998
dprint(f"download apk to {src_path}")
10099
else:

0 commit comments

Comments
 (0)