Skip to content

Commit 67e8dac

Browse files
committed
【修改】:在 linux 环境下 env 下载 zip 软件包时出错的 Bug
1 parent b166a36 commit 67e8dac

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

archive.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,29 @@
2727
import zipfile
2828
import os
2929
import pkgsdb
30+
import platform
31+
import shutil
3032

3133

3234
def unpack(archive_fn, path, pkg, pkgs_name_in_json):
3335
pkg_ver = pkg['ver']
3436
flag = True
3537

38+
os_type = False
39+
40+
if platform.system() == "Windows":
41+
os_type = True
42+
3643
if ".tar.bz2" in archive_fn:
3744
arch = tarfile.open(archive_fn, "r:bz2")
3845
for tarinfo in arch:
3946
arch.extract(tarinfo, path)
4047
a = tarinfo.name
4148
if not os.path.isdir(os.path.join(path, a)):
42-
right_path = a.replace('/', '\\')
49+
if os_type:
50+
right_path = a.replace('/', '\\')
51+
else:
52+
right_path = a
4353
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
4454
pkgsdb.savetodb(a, archive_fn)
4555
arch.close()
@@ -50,7 +60,10 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
5060
arch.extract(tarinfo, path)
5161
a = tarinfo.name
5262
if not os.path.isdir(os.path.join(path, a)):
53-
right_path = a.replace('/', '\\')
63+
if os_type:
64+
right_path = a.replace('/', '\\')
65+
else:
66+
right_path = a
5467
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
5568
pkgsdb.savetodb(a, archive_fn)
5669
arch.close()
@@ -60,7 +73,11 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
6073
for item in arch.namelist():
6174
arch.extract(item, path)
6275
if not os.path.isdir(os.path.join(path, item)):
63-
right_path = item.replace('/', '\\')
76+
if os_type:
77+
right_path = item.replace('/', '\\')
78+
else:
79+
right_path = item
80+
6481
# Gets the folder name and change_dirname only once
6582
if flag:
6683
dir_name = os.path.split(right_path)[0]
@@ -72,12 +89,14 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
7289
arch.close()
7390

7491
# Change the folder name
75-
7692
change_dirname = pkgs_name_in_json + '-' + pkg_ver
7793

7894
if os.path.isdir(os.path.join(path, change_dirname)):
79-
cmd = 'rd /s /q ' + os.path.join(path, change_dirname)
80-
os.system(cmd)
95+
if os_type:
96+
cmd = 'rd /s /q ' + os.path.join(path, change_dirname)
97+
os.system(cmd)
98+
else:
99+
shutil.rmtree(os.path.join(path, change_dirname))
81100

82101
os.rename(os.path.join(path, dir_name),os.path.join(path, change_dirname))
83102

0 commit comments

Comments
 (0)