修复从git仓库安装应用时无法完整复制应用目录结构的问题

This commit is contained in:
jingrow 2025-10-29 05:40:20 +08:00
parent 51cfebd621
commit 4209f45229
3 changed files with 25 additions and 10 deletions

View File

@ -504,6 +504,11 @@
"Feather": "Feather",
"App Name": "应用名称",
"Product Design": "产品设计",
"Git Branch": "Git 分支",
"Export Package": "导出安装包",
"cannot be exported": "不允许导出",
"App package exported successfully: {0}": "应用安装包导出成功:{0}",
"Failed to export app package": "导出应用安装包失败",
"Search": "搜索",
"Search...": "搜索...",

View File

@ -567,6 +567,7 @@ async def install_from_git(repo_url: str = Form(...)):
# 安装文件(完整复制整个包结构)
install_result = install_files(str(clone_dir), app_name, package_info['data'])
if not install_result.get('success'):
shutil.rmtree(clone_dir, ignore_errors=True)
raise HTTPException(status_code=400, detail=install_result.get('error'))
# 清理临时文件

View File

@ -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)