From cfe27b9d1a2c872871b486209cc5c90afa028ca0 Mon Sep 17 00:00:00 2001 From: baiwupeng Date: Tue, 2 Sep 2025 10:49:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[=E6=96=B0=E9=9C=80=E6=B1=82]:=20module=5Fi?= =?UTF-8?q?nstall=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://gitee.com/openharmony/build/issues/ICVKKG Signed-off-by: 李熹晨 <2519294308@qq.com> --- ohos/packages/BUILD.gn | 2 + ohos/packages/modules_install.py | 34 ++++++++--- ohos_var.gni | 5 ++ scripts/util/file_utils.py | 97 ++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 8 deletions(-) diff --git a/ohos/packages/BUILD.gn b/ohos/packages/BUILD.gn index 0797f6dc8a..a4ab250879 100644 --- a/ohos/packages/BUILD.gn +++ b/ohos/packages/BUILD.gn @@ -322,6 +322,8 @@ foreach(_platform, target_platform_list) { rebase_path(_system_image_zipfile, root_build_dir), "--host-toolchain", _host_toolchain, + "--module-install-copy-type", + module_install_copy_type ] _additional_system_files = [] diff --git a/ohos/packages/modules_install.py b/ohos/packages/modules_install.py index dc67088639..b50c9131b9 100755 --- a/ohos/packages/modules_install.py +++ b/ohos/packages/modules_install.py @@ -21,7 +21,7 @@ import shutil sys.path.append( os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__))))) -from scripts.util.file_utils import read_json_file, write_json_file, write_file # noqa: E402 +from scripts.util.file_utils import read_json_file, write_json_file, write_file, link_copy, link_copy_tree # noqa: E402 from scripts.util import build_utils # noqa: E402 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "rules")) @@ -68,7 +68,8 @@ def _get_post_process_modules_info(post_process_modules_info_files: list, depfil def copy_modules(system_install_info: dict, install_modules_info_file: str, modules_info_file: str, module_list_file: str, post_process_modules_info_files: list, platform_installed_path: str, - host_toolchain, additional_system_files: dict, depfiles: list, categorized_libraries: dict): + host_toolchain, additional_system_files: dict, depfiles: list, categorized_libraries: dict, + use_hardlink: bool): output_result = [] dest_list = [] symlink_dest = [] @@ -94,7 +95,10 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, output_result.append(_module_info) for source, system_path in additional_system_files: - shutil.copy(source, os.path.join(platform_installed_path, system_path)) + if use_hardlink: + link_copy(source, os.path.join(platform_installed_path, system_path)) + else: + shutil.copy(source, os.path.join(platform_installed_path, system_path)) # copy modules for module_info in output_result: @@ -125,14 +129,25 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, if os.path.isdir(source): is_hvigor_hap = False for filename in os.listdir(source): - if filename.endswith('.hap') or filename.endswith('.hsp'): - is_hvigor_hap = True + if not filename.endswith('.hap') and not filename.endswith('.hsp'): + continue + is_hvigor_hap = True + if use_hardlink: + link_copy(os.path.join(source, filename), + os.path.join(platform_installed_path, dest, filename)) + else: shutil.copy2(os.path.join(source, filename), os.path.join(platform_installed_path, dest, filename)) if not is_hvigor_hap: - shutil.copytree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) + if use_hardlink: + link_copy_tree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) + else: + shutil.copytree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) else: - shutil.copy2(source, os.path.join(platform_installed_path, dest)) + if use_hardlink: + link_copy(source, os.path.join(platform_installed_path, dest)) + else: + shutil.copy2(source, os.path.join(platform_installed_path, dest)) # add symlink if 'symlink' in module_info: @@ -211,6 +226,7 @@ def main(): parser.add_argument('--system-image-zipfile', required=True) parser.add_argument('--host-toolchain', required=True) parser.add_argument('--categorized-libraries', required=False) + parser.add_argument('--module-install-copy-type', required=True) parser.add_argument( '--additional-system-files', action='append', @@ -222,6 +238,8 @@ def main(): default=[]) args = parser.parse_args() + use_hardlink = (args.module_install_copy_type == "hardlink") + additional_system_files = [] for tuples in args.additional_system_files or []: filepath, system_path = tuples.split(':') @@ -304,7 +322,7 @@ def main(): args.modules_info_file, args.modules_list_file, args.post_process_modules_info_files, args.platform_installed_path, args.host_toolchain, - additional_system_files, depfiles, categorized_libraries) + additional_system_files, depfiles, categorized_libraries, use_hardlink) if os.path.exists(args.system_image_zipfile): os.unlink(args.system_image_zipfile) diff --git a/ohos_var.gni b/ohos_var.gni index 1397afc71b..d1844505f5 100755 --- a/ohos_var.gni +++ b/ohos_var.gni @@ -14,6 +14,11 @@ import("//build/common.gni") import("//build/version.gni") +declare_args() { + # module install copy type: copy/hardlink + module_install_copy_type = "copy" +} + declare_args() { # build ohos version build_public_version = true diff --git a/scripts/util/file_utils.py b/scripts/util/file_utils.py index 65dcb4af9c..0ffcc77008 100755 --- a/scripts/util/file_utils.py +++ b/scripts/util/file_utils.py @@ -115,3 +115,100 @@ def write_file(output_file, content): cmd = [gn_exe, 'format'] cmd.append(output_file) subprocess.check_output(cmd) + + +def create_hardlink(target, link_path): + # Delete the existing target (if it is a file) + if os.path.lexists(link_path): + if os.path.isdir(link_path): + print("'{}' is a directory that cannot be replaced.".format(link_path)) + return + os.unlink(link_path) + + try: + os.link(target, link_path) + except OSError as e: + print("create hard link '{}' failed.".format(link_path)) + shutil.copy2(target, link_path) + + +def link_copy(src, dst, *, follow_symlinks=True): + # Processing Directory Targets + if os.path.isdir(dst): + dst = os.path.join(dst, os.path.basename(src)) + + # Working with symbolic follow_symlinks + if not follow_symlinks and os.path.islink(src): + link_src = os.readlink(src) + os.symlink(link_src, dst) + return dst + + # Obtain the actual source path (follow symbolic links) + real_src = os.path.realpath(src) if follow_symlinks else src + + # Create target directory structure + os.makedirs(os.path.dirname(dst), exist_ok=True) + + # Create hard link or copy + if os.path.isfile(real_src): + create_hardlink(real_src, dst) + else: + # Non-standard files (such as device files) use regular copying + link_copy_tree(real_src, dst, follow_symlinks=follow_symlinks, dirs_exist_ok=True) + + return dst + + +def link_copy_tree(src, dst, *, symlinks=False, ignore=None, copy_function=link_copy, dirs_exist_ok=False): + if not os.path.isdir(src): + raise Exception(f"The target path is not a directory: '{src}'") + + # Handling the existence of the target directory + if os.path.exists(dst): + if not dirs_exist_ok: + raise Exception(f"The target directory already exists: '{dst}'") + if not os.path.isdir(dst): + raise Exception(f"The target path is not a directory: '{dst}'") + else + os.makedirs(dst) + + # Handling the ignore list + ignored_list = ignore(src, os.listdir(src) if ignore else set() + + # Traverse the source directory + for item in os.listdir(src): + if item in ignored_list: + continue + + src_path = os.path.join(src, item) + dst_path = os.path.join(dst, item) + + try: + # Working with symbolic links + if os.path.islink(src_path): + link_target = os.readlink(src_path) + + if symlinks: + # Preserve symbolic links + os.symlinks(link_target, dst_path) + continue + else: + # Parse symbolic link target + resolved_path = os.path.join(os.path.dirname(src_path), link_target) + src_path = resolved_path + + # process directory + if os.path.isdir(src_path): + link_copy_tree(src_path, dst_path, symlinks=symlinks, ignore=ignore, + copy_function=copy_function, dirs_exist_ok=dirs_exist_ok) + else: + copy_function(src_path, dst_path, follow_symlinks=not symlinks) + + except: # noqa E722 + # Ignore links pointing to non-existent files + if not os.path.exist(src_path): + continue + print(f"Failed to copy '{src_path}' to '{dst_path}'") + raise + + return dst \ No newline at end of file -- Gitee From 630d19c77fef7d922bffd5f5087e13467dd0913c Mon Sep 17 00:00:00 2001 From: baiwupeng Date: Tue, 2 Sep 2025 10:49:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[=E6=96=B0=E9=9C=80=E6=B1=82]:=20module=5Fi?= =?UTF-8?q?nstall=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://gitee.com/openharmony/build/issues/ICVKKG Signed-off-by: 李熹晨 <2519294308@qq.com> --- ohos/packages/BUILD.gn | 2 + ohos/packages/modules_install.py | 34 ++++++++--- ohos_var.gni | 5 ++ scripts/util/file_utils.py | 98 ++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 8 deletions(-) diff --git a/ohos/packages/BUILD.gn b/ohos/packages/BUILD.gn index 0797f6dc8a..a4ab250879 100644 --- a/ohos/packages/BUILD.gn +++ b/ohos/packages/BUILD.gn @@ -322,6 +322,8 @@ foreach(_platform, target_platform_list) { rebase_path(_system_image_zipfile, root_build_dir), "--host-toolchain", _host_toolchain, + "--module-install-copy-type", + module_install_copy_type ] _additional_system_files = [] diff --git a/ohos/packages/modules_install.py b/ohos/packages/modules_install.py index dc67088639..b50c9131b9 100755 --- a/ohos/packages/modules_install.py +++ b/ohos/packages/modules_install.py @@ -21,7 +21,7 @@ import shutil sys.path.append( os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__))))) -from scripts.util.file_utils import read_json_file, write_json_file, write_file # noqa: E402 +from scripts.util.file_utils import read_json_file, write_json_file, write_file, link_copy, link_copy_tree # noqa: E402 from scripts.util import build_utils # noqa: E402 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "rules")) @@ -68,7 +68,8 @@ def _get_post_process_modules_info(post_process_modules_info_files: list, depfil def copy_modules(system_install_info: dict, install_modules_info_file: str, modules_info_file: str, module_list_file: str, post_process_modules_info_files: list, platform_installed_path: str, - host_toolchain, additional_system_files: dict, depfiles: list, categorized_libraries: dict): + host_toolchain, additional_system_files: dict, depfiles: list, categorized_libraries: dict, + use_hardlink: bool): output_result = [] dest_list = [] symlink_dest = [] @@ -94,7 +95,10 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, output_result.append(_module_info) for source, system_path in additional_system_files: - shutil.copy(source, os.path.join(platform_installed_path, system_path)) + if use_hardlink: + link_copy(source, os.path.join(platform_installed_path, system_path)) + else: + shutil.copy(source, os.path.join(platform_installed_path, system_path)) # copy modules for module_info in output_result: @@ -125,14 +129,25 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, if os.path.isdir(source): is_hvigor_hap = False for filename in os.listdir(source): - if filename.endswith('.hap') or filename.endswith('.hsp'): - is_hvigor_hap = True + if not filename.endswith('.hap') and not filename.endswith('.hsp'): + continue + is_hvigor_hap = True + if use_hardlink: + link_copy(os.path.join(source, filename), + os.path.join(platform_installed_path, dest, filename)) + else: shutil.copy2(os.path.join(source, filename), os.path.join(platform_installed_path, dest, filename)) if not is_hvigor_hap: - shutil.copytree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) + if use_hardlink: + link_copy_tree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) + else: + shutil.copytree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) else: - shutil.copy2(source, os.path.join(platform_installed_path, dest)) + if use_hardlink: + link_copy(source, os.path.join(platform_installed_path, dest)) + else: + shutil.copy2(source, os.path.join(platform_installed_path, dest)) # add symlink if 'symlink' in module_info: @@ -211,6 +226,7 @@ def main(): parser.add_argument('--system-image-zipfile', required=True) parser.add_argument('--host-toolchain', required=True) parser.add_argument('--categorized-libraries', required=False) + parser.add_argument('--module-install-copy-type', required=True) parser.add_argument( '--additional-system-files', action='append', @@ -222,6 +238,8 @@ def main(): default=[]) args = parser.parse_args() + use_hardlink = (args.module_install_copy_type == "hardlink") + additional_system_files = [] for tuples in args.additional_system_files or []: filepath, system_path = tuples.split(':') @@ -304,7 +322,7 @@ def main(): args.modules_info_file, args.modules_list_file, args.post_process_modules_info_files, args.platform_installed_path, args.host_toolchain, - additional_system_files, depfiles, categorized_libraries) + additional_system_files, depfiles, categorized_libraries, use_hardlink) if os.path.exists(args.system_image_zipfile): os.unlink(args.system_image_zipfile) diff --git a/ohos_var.gni b/ohos_var.gni index 1397afc71b..d1844505f5 100755 --- a/ohos_var.gni +++ b/ohos_var.gni @@ -14,6 +14,11 @@ import("//build/common.gni") import("//build/version.gni") +declare_args() { + # module install copy type: copy/hardlink + module_install_copy_type = "copy" +} + declare_args() { # build ohos version build_public_version = true diff --git a/scripts/util/file_utils.py b/scripts/util/file_utils.py index 65dcb4af9c..997789a428 100755 --- a/scripts/util/file_utils.py +++ b/scripts/util/file_utils.py @@ -15,6 +15,7 @@ import json import os +import shutil import subprocess import hashlib import platform @@ -115,3 +116,100 @@ def write_file(output_file, content): cmd = [gn_exe, 'format'] cmd.append(output_file) subprocess.check_output(cmd) + + +def create_hardlink(target, link_path): + # Delete the existing target (if it is a file) + if os.path.lexists(link_path): + if os.path.isdir(link_path): + print("'{}' is a directory that cannot be replaced.".format(link_path)) + return + os.unlink(link_path) + + try: + os.link(target, link_path) + except OSError as e: + print("create hard link '{}' failed.".format(link_path)) + shutil.copy2(target, link_path) + + +def link_copy(src, dst, *, follow_symlinks=True): + # Processing Directory Targets + if os.path.isdir(dst): + dst = os.path.join(dst, os.path.basename(src)) + + # Working with symbolic follow_symlinks + if not follow_symlinks and os.path.islink(src): + link_src = os.readlink(src) + os.symlink(link_src, dst) + return dst + + # Obtain the actual source path (follow symbolic links) + real_src = os.path.realpath(src) if follow_symlinks else src + + # Create target directory structure + os.makedirs(os.path.dirname(dst), exist_ok=True) + + # Create hard link or copy + if os.path.isfile(real_src): + create_hardlink(real_src, dst) + else: + # Non-standard files (such as device files) use regular copying + link_copy_tree(real_src, dst, follow_symlinks=follow_symlinks, dirs_exist_ok=True) + + return dst + + +def link_copy_tree(src, dst, *, symlinks=False, ignore=None, copy_function=link_copy, dirs_exist_ok=False): + if not os.path.isdir(src): + raise Exception(f"The target path is not a directory: '{src}'") + + # Handling the existence of the target directory + if os.path.exists(dst): + if not dirs_exist_ok: + raise Exception(f"The target directory already exists: '{dst}'") + if not os.path.isdir(dst): + raise Exception(f"The target path is not a directory: '{dst}'") + else: + os.makedirs(dst) + + # Handling the ignore list + ignored_list = ignore(src, os.listdir(src)) if ignore else set() + + # Traverse the source directory + for item in os.listdir(src): + if item in ignored_list: + continue + + src_path = os.path.join(src, item) + dst_path = os.path.join(dst, item) + + try: + # Working with symbolic links + if os.path.islink(src_path): + link_target = os.readlink(src_path) + + if symlinks: + # Preserve symbolic links + os.symlinks(link_target, dst_path) + continue + else: + # Parse symbolic link target + resolved_path = os.path.join(os.path.dirname(src_path), link_target) + src_path = resolved_path + + # process directory + if os.path.isdir(src_path): + link_copy_tree(src_path, dst_path, symlinks=symlinks, ignore=ignore, + copy_function=copy_function, dirs_exist_ok=dirs_exist_ok) + else: + copy_function(src_path, dst_path, follow_symlinks=not symlinks) + + except: # noqa E722 + # Ignore links pointing to non-existent files + if not os.path.exist(src_path): + continue + print(f"Failed to copy '{src_path}' to '{dst_path}'") + raise + + return dst \ No newline at end of file -- Gitee From 7d1c66be62fff260a240d72366367b5d2093f4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=86=B9=E6=99=A8?= <2519294308@qq.com> Date: Thu, 4 Sep 2025 10:14:14 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[=E6=96=B0=E9=9C=80=E6=B1=82]:=20module=5Fi?= =?UTF-8?q?nstall=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://gitee.com/openharmony/build/issues/ICVKKG Signed-off-by: 李熹晨 <2519294308@qq.com> --- ohos/packages/modules_install.py | 28 +++--------- scripts/util/file_utils.py | 74 +++++++------------------------- 2 files changed, 22 insertions(+), 80 deletions(-) diff --git a/ohos/packages/modules_install.py b/ohos/packages/modules_install.py index b50c9131b9..cb876f0160 100755 --- a/ohos/packages/modules_install.py +++ b/ohos/packages/modules_install.py @@ -21,7 +21,7 @@ import shutil sys.path.append( os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__))))) -from scripts.util.file_utils import read_json_file, write_json_file, write_file, link_copy, link_copy_tree # noqa: E402 +from scripts.util.file_utils import read_json_file, write_json_file, write_file, link_copy, link_copytree # noqa: E402 from scripts.util import build_utils # noqa: E402 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "rules")) @@ -95,10 +95,7 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, output_result.append(_module_info) for source, system_path in additional_system_files: - if use_hardlink: - link_copy(source, os.path.join(platform_installed_path, system_path)) - else: - shutil.copy(source, os.path.join(platform_installed_path, system_path)) + link_copy(source, os.path.join(platform_installed_path, system_path), "copy", use_hardlink) # copy modules for module_info in output_result: @@ -129,25 +126,14 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, if os.path.isdir(source): is_hvigor_hap = False for filename in os.listdir(source): - if not filename.endswith('.hap') and not filename.endswith('.hsp'): - continue - is_hvigor_hap = True - if use_hardlink: + if filename.endswith('.hap') or filename.endswith('.hsp'): + is_hvigor_hap = True link_copy(os.path.join(source, filename), - os.path.join(platform_installed_path, dest, filename)) - else: - shutil.copy2(os.path.join(source, filename), - os.path.join(platform_installed_path, dest, filename)) + os.path.join(platform_installed_path, dest, filename), "copy2", use_hardlink) if not is_hvigor_hap: - if use_hardlink: - link_copy_tree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) - else: - shutil.copytree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True) + link_copytree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True, use_hardlink) else: - if use_hardlink: - link_copy(source, os.path.join(platform_installed_path, dest)) - else: - shutil.copy2(source, os.path.join(platform_installed_path, dest)) + link_copy(source, os.path.join(platform_installed_path, dest), "copy2", use_hardlink) # add symlink if 'symlink' in module_info: diff --git a/scripts/util/file_utils.py b/scripts/util/file_utils.py index 997789a428..9f0760395d 100755 --- a/scripts/util/file_utils.py +++ b/scripts/util/file_utils.py @@ -133,19 +133,25 @@ def create_hardlink(target, link_path): shutil.copy2(target, link_path) -def link_copy(src, dst, *, follow_symlinks=True): +def link_copy(src, dst, copy_type:str, use_hardlink=False): + if not use_hardlink: + if copy_type == "copy": + shutil.copy(src, dst) + else: + shutil.copy2(src, dst) + return # Processing Directory Targets if os.path.isdir(dst): dst = os.path.join(dst, os.path.basename(src)) # Working with symbolic follow_symlinks - if not follow_symlinks and os.path.islink(src): + if os.path.islink(src): link_src = os.readlink(src) os.symlink(link_src, dst) return dst # Obtain the actual source path (follow symbolic links) - real_src = os.path.realpath(src) if follow_symlinks else src + real_src = os.path.realpath(src) # Create target directory structure os.makedirs(os.path.dirname(dst), exist_ok=True) @@ -154,62 +160,12 @@ def link_copy(src, dst, *, follow_symlinks=True): if os.path.isfile(real_src): create_hardlink(real_src, dst) else: - # Non-standard files (such as device files) use regular copying - link_copy_tree(real_src, dst, follow_symlinks=follow_symlinks, dirs_exist_ok=True) + # Non-standard files + raise Exception(f"The target path is not a standard file: '{real_src}'") - return dst - -def link_copy_tree(src, dst, *, symlinks=False, ignore=None, copy_function=link_copy, dirs_exist_ok=False): - if not os.path.isdir(src): - raise Exception(f"The target path is not a directory: '{src}'") - - # Handling the existence of the target directory - if os.path.exists(dst): - if not dirs_exist_ok: - raise Exception(f"The target directory already exists: '{dst}'") - if not os.path.isdir(dst): - raise Exception(f"The target path is not a directory: '{dst}'") +def link_copytree(src, dst, dirs_exist_ok=False, use_hardlink=False): + if not use_hardlink: + shutil.copytree(src, dst, dirs_exist_ok=dirs_exist_ok) else: - os.makedirs(dst) - - # Handling the ignore list - ignored_list = ignore(src, os.listdir(src)) if ignore else set() - - # Traverse the source directory - for item in os.listdir(src): - if item in ignored_list: - continue - - src_path = os.path.join(src, item) - dst_path = os.path.join(dst, item) - - try: - # Working with symbolic links - if os.path.islink(src_path): - link_target = os.readlink(src_path) - - if symlinks: - # Preserve symbolic links - os.symlinks(link_target, dst_path) - continue - else: - # Parse symbolic link target - resolved_path = os.path.join(os.path.dirname(src_path), link_target) - src_path = resolved_path - - # process directory - if os.path.isdir(src_path): - link_copy_tree(src_path, dst_path, symlinks=symlinks, ignore=ignore, - copy_function=copy_function, dirs_exist_ok=dirs_exist_ok) - else: - copy_function(src_path, dst_path, follow_symlinks=not symlinks) - - except: # noqa E722 - # Ignore links pointing to non-existent files - if not os.path.exist(src_path): - continue - print(f"Failed to copy '{src_path}' to '{dst_path}'") - raise - - return dst \ No newline at end of file + shutil.copytree(src, dst, copy_function=create_hardlink, dirs_exist_ok=dirs_exist_ok) \ No newline at end of file -- Gitee From dded977c2ff2b998378c2668df4526e18c7cef7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=86=B9=E6=99=A8?= <2519294308@qq.com> Date: Thu, 4 Sep 2025 10:37:56 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[=E6=96=B0=E9=9C=80=E6=B1=82]:=20module=5Fi?= =?UTF-8?q?nstall=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://gitee.com/openharmony/build/issues/ICVKKG Signed-off-by: 李熹晨 <2519294308@qq.com> --- ohos/packages/modules_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos/packages/modules_install.py b/ohos/packages/modules_install.py index cb876f0160..0a5e945273 100755 --- a/ohos/packages/modules_install.py +++ b/ohos/packages/modules_install.py @@ -131,7 +131,7 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, link_copy(os.path.join(source, filename), os.path.join(platform_installed_path, dest, filename), "copy2", use_hardlink) if not is_hvigor_hap: - link_copytree(source, os.path.join(platform_installed_path, dest), dirs_exist_ok=True, use_hardlink) + link_copytree(source, os.path.join(platform_installed_path, dest), True, use_hardlink) else: link_copy(source, os.path.join(platform_installed_path, dest), "copy2", use_hardlink) -- Gitee From 48809b532f201bef4e0ae6aa20c89f1f65b8acb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=86=B9=E6=99=A8?= <2519294308@qq.com> Date: Thu, 4 Sep 2025 14:41:22 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[=E6=96=B0=E9=9C=80=E6=B1=82]:=20module=5Fi?= =?UTF-8?q?nstall=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://gitee.com/openharmony/build/issues/ICVKKG Signed-off-by: 李熹晨 <2519294308@qq.com> --- ohos/packages/modules_install.py | 10 +++++----- scripts/util/file_utils.py | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ohos/packages/modules_install.py b/ohos/packages/modules_install.py index 0a5e945273..33b3e67c27 100755 --- a/ohos/packages/modules_install.py +++ b/ohos/packages/modules_install.py @@ -21,7 +21,7 @@ import shutil sys.path.append( os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__))))) -from scripts.util.file_utils import read_json_file, write_json_file, write_file, link_copy, link_copytree # noqa: E402 +from scripts.util.file_utils import read_json_file, write_json_file, write_file, custom_copy, custom_copytree # noqa: E402 from scripts.util import build_utils # noqa: E402 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "rules")) @@ -95,7 +95,7 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, output_result.append(_module_info) for source, system_path in additional_system_files: - link_copy(source, os.path.join(platform_installed_path, system_path), "copy", use_hardlink) + custom_copy(source, os.path.join(platform_installed_path, system_path), "copy", use_hardlink) # copy modules for module_info in output_result: @@ -128,12 +128,12 @@ def copy_modules(system_install_info: dict, install_modules_info_file: str, for filename in os.listdir(source): if filename.endswith('.hap') or filename.endswith('.hsp'): is_hvigor_hap = True - link_copy(os.path.join(source, filename), + custom_copy(os.path.join(source, filename), os.path.join(platform_installed_path, dest, filename), "copy2", use_hardlink) if not is_hvigor_hap: - link_copytree(source, os.path.join(platform_installed_path, dest), True, use_hardlink) + custom_copytree(source, os.path.join(platform_installed_path, dest), True, use_hardlink) else: - link_copy(source, os.path.join(platform_installed_path, dest), "copy2", use_hardlink) + custom_copy(source, os.path.join(platform_installed_path, dest), "copy2", use_hardlink) # add symlink if 'symlink' in module_info: diff --git a/scripts/util/file_utils.py b/scripts/util/file_utils.py index 9f0760395d..1d03b60106 100755 --- a/scripts/util/file_utils.py +++ b/scripts/util/file_utils.py @@ -129,11 +129,10 @@ def create_hardlink(target, link_path): try: os.link(target, link_path) except OSError as e: - print("create hard link '{}' failed.".format(link_path)) shutil.copy2(target, link_path) -def link_copy(src, dst, copy_type:str, use_hardlink=False): +def custom_copy(src, dst, copy_type:str, use_hardlink=False): if not use_hardlink: if copy_type == "copy": shutil.copy(src, dst) @@ -164,7 +163,7 @@ def link_copy(src, dst, copy_type:str, use_hardlink=False): raise Exception(f"The target path is not a standard file: '{real_src}'") -def link_copytree(src, dst, dirs_exist_ok=False, use_hardlink=False): +def custom_copytree(src, dst, dirs_exist_ok=False, use_hardlink=False): if not use_hardlink: shutil.copytree(src, dst, dirs_exist_ok=dirs_exist_ok) else: -- Gitee