修复从git仓库安装应用时无法完整复制应用目录结构的问题
This commit is contained in:
parent
51cfebd621
commit
fe44d0b334
@ -80,14 +80,23 @@ def analyze_package(temp_dir: str) -> Dict[str, Any]:
|
||||
if not root_items:
|
||||
return {'success': False, 'error': '目录为空'}
|
||||
|
||||
# 对于 git clone 的目录,跳过 .git,进入仓库名目录
|
||||
# 找到一个不是 .git 的目录作为 root_dir
|
||||
# 对于 git clone 的目录,跳过 .git,检查是否为应用根目录
|
||||
# 统计非 .git 的目录数量
|
||||
non_git_dirs = [item for item in root_items if os.path.isdir(os.path.join(temp_dir, item)) and item != '.git']
|
||||
|
||||
# 检查是否包含 .git 目录(说明是 Git 仓库)
|
||||
is_git_repo = '.git' in root_items
|
||||
|
||||
root_dir = temp_dir
|
||||
for item in root_items:
|
||||
item_path = os.path.join(temp_dir, item)
|
||||
if os.path.isdir(item_path) and item != '.git':
|
||||
root_dir = item_path
|
||||
break
|
||||
|
||||
# 如果只有一个目录且是 Git 仓库,通常是 Git 仓库克隆后的结构,需要进入
|
||||
# 如果有多个目录,说明已经是应用根目录
|
||||
if len(non_git_dirs) == 1 and is_git_repo:
|
||||
root_dir = os.path.join(temp_dir, non_git_dirs[0])
|
||||
# 如果多个目录但有 .git,说明 Git 仓库根目录就是应用根目录(典型开发结构)
|
||||
elif len(non_git_dirs) > 1 and is_git_repo:
|
||||
# 不进入子目录,直接使用 temp_dir 作为 root_dir
|
||||
root_dir = temp_dir
|
||||
|
||||
package_info = {
|
||||
'app_name': os.path.basename(root_dir),
|
||||
@ -101,7 +110,7 @@ def analyze_package(temp_dir: str) -> Dict[str, Any]:
|
||||
}
|
||||
|
||||
# 检查配置文件
|
||||
if os.path.exists(os.path.join(root_dir, 'setup.py')):
|
||||
if os.path.exists(os.path.join(root_dir, 'hooks.py')):
|
||||
package_info['has_backend'] = True
|
||||
|
||||
if os.path.exists(os.path.join(root_dir, 'package.json')):
|
||||
@ -167,9 +176,9 @@ def install_files(temp_dir: str, app_name: str, package_info: Dict[str, Any]) ->
|
||||
# 获取根目录(analyze_package 已经找到正确的根目录)
|
||||
root_dir = package_info.get('root_dir', temp_dir)
|
||||
|
||||
# 直接复制整个包结构(不检查内层目录,因为导出时就包含了完整结构)
|
||||
# 直接复制整个包结构(只跳过系统生成的文件)
|
||||
for item in os.listdir(root_dir):
|
||||
if item in ['__pycache__', '.git', '.DS_Store']:
|
||||
if item in ['__pycache__', '.DS_Store']:
|
||||
continue
|
||||
|
||||
src = os.path.join(root_dir, item)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user