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

Open
#215 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
cli, tooling

Research direction

Start at handle_zip_package and inspect how zipfile.ZipFile.namelist() is used to determine package_folder_name, including the Windows path conversion. Reproduce the issue with pkgs --update and v2.5.0_for_rtthread.zip, then verify that extraction and database paths include the complete package contents rather than only .github/workflows/.

Written by the indexing model from the issue text.

Description

例如:
解压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
Dominant language
Python
Stars
79
Forks
64
Avg merge
4d 2h
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RT-Thread/env

All issues in RT-Thread/env

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.