Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

使用pkgs --update 下载解压zip文件是解析会出现错误

未关闭
#215 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
cli, tooling

调研方向

从 handle_zip_package 开始,检查如何使用 zipfile.ZipFile.namelist() 确定 package_folder_name,包括 Windows 路径转换。使用 pkgs --update 和 v2.5.0_for_rtthread.zip 重现该问题,然后验证解压路径和数据库路径包含完整的软件包内容,而不只是 .github/workflows/.

由索引模型根据 Issue 内容生成。

描述

例如:
解压v2.5.0_for_rtthread.zip 时找到的第一个文件是littlefs-refs-tags-v2.5.0_for_rtthread.github\workflows\下面的文件

def handle_zip_package 中
package_folder_name = os.path.split(right_path)[0]
package_folder_name 就成了littlefs-refs-tags-v2.5.0_for_rtthread.github\workflows
所以最终解压的内容经过cp就只有.github\workflows\ 下的文件

是否改成这样,找第一个item, 因为第一个itme永远是压缩包本身的文件夹
def handle_zip_package(archive_filename, bsp_package_path, package_name, package_info):
package_version = package_info['ver']
package_temp_path = os.path.join(bsp_package_path, "package_temp")

try:
    if remove_folder(package_temp_path):
        os.makedirs(package_temp_path)
except Exception as e:
    logging.warning('Error message : {0}'.format(e))

logging.info("BSP packages path {0}".format(bsp_package_path))
logging.info("BSP package temp path: {0}".format(package_temp_path))
logging.info("archive filename : {0}".format(archive_filename))

try:
    flag = True
    package_folder_name = ""
    package_name_with_version = ""
    arch = zipfile.ZipFile(archive_filename, "r")
    for item in arch.namelist():
        arch.extract(item, package_temp_path)
        if is_windows():
            right_path = item.replace('/', '\\')
        else:
            right_path = item
        # Gets the folder name and changed folder name only once
        if flag:
            package_folder_name = os.path.split(right_path)[0]
            package_name_with_version = package_name + '-' + package_version
            flag = False
        if not os.path.isdir(os.path.join(package_temp_path, item)):
            right_name_to_db = right_path.replace(package_folder_name, package_name_with_version, 1)
            right_path = os.path.join("package_temp", right_path)
            pkgsdb.save_to_database(right_name_to_db, archive_filename, right_path)
    arch.close()

    if not move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version,
                                        bsp_package_path):
        return False
except Exception as e:
    logging.warning('unpack error message : {0}'.format(e))
    logging.warning('unpack {0} failed'.format(os.path.basename(archive_filename)))
    # remove temp folder and archive file
    remove_folder(package_temp_path)
    os.remove(archive_filename)
    return False

return True
主要语言
Python
星标
78
派生
64
平均合并
1 天 6 小时
30 天内合并 PR
6

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

RT-Thread/env 的其他 Issue

查看 RT-Thread/env 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。