Merged
refactor: 重构异构安装逻辑,提取handle_multi_arch_install函数 #1614
refactor: 重构异构安装逻辑,提取handle_multi_arch_install函数 #1614
Merged
liulinxiangAdd on Mar 12
Total: 1 files changed+32-15
@@ -491,6 +491,36 @@ mkdir_install_path() {
491 fi491 fi
492}492}
493 493 
494+handle_multi_arch_install() {
495+ local target_dir="$1"
496+ local so_file="$2"
497+ local lib_dir
498+ lib_dir=$(dirname "${target_dir}")
499+ local need_restore_lib_w="n"
500+ local need_restore_target_w="n"
501+ 
502+ if [ -d "${lib_dir}" ]; then
503+ if [ ! -w "${lib_dir}" ]; then
504+ need_restore_lib_w="y"
505+ chmod u+w "${lib_dir}"
506+ fi
507+ else
508+ mkdir -p "${lib_dir}"
509+ fi
510+ if [ -d "${target_dir}" ]; then
511+ if [ ! -w "${target_dir}" ]; then
512+ need_restore_target_w="y"
513+ chmod u+w "${target_dir}"
514+ fi
515+ else
516+ mkdir -p "${target_dir}"
517+ fi
518+ cp -f "${so_file}" "${target_dir}"
L
LllimwangMar 12

问题: 重构后缺失对so文件设置可执行权限

原代码在异构安装时会执行 chmod 755 ${graph_so_dir_path}/* 来确保 .so 文件具有可执行权限。新的 handle_multi_arch_install 函数虽然成功重构了目录创建、权限处理和文件拷贝逻辑,但遗漏了对拷贝后 so 文件设置可执行权限的步骤。

建议: 在 cp -f "${so_file}" "${target_dir}" 后添加对拷贝文件的权限设置,例如:

chmod 755 "${target_dir}"/*

或针对特定文件:

chmod 755 "${target_dir}/$(basename "${so_file}")"
likedislike
liulinxiang
Mar 12 Comments:
519+ chmod 755 "${target_dir}"/*
520+ [ "${need_restore_target_w}" = "y" ] && chmod u-w "${target_dir}"
521+ [ "${need_restore_lib_w}" = "y" ] && chmod u-w "${lib_dir}"
522+}
523+ 
494install_package() {524install_package() {
495 if [ "${IS_INSTALL}" = "n" ] && [ "${IS_UPGRADE}" = "n" ]; then525 if [ "${IS_INSTALL}" = "n" ] && [ "${IS_UPGRADE}" = "n" ]; then
496 return526 return
@@ -505,21 +535,8 @@ install_package() {
505 # check platform535 # check platform
506 if [ "${architecture}" != "${ARCH_INFO}" ]; then536 if [ "${architecture}" != "${ARCH_INFO}" ]; then
507 logandprint "[INFO]: the architecture of the run package is inconsistent with that of the current environment. "537 logandprint "[INFO]: the architecture of the run package is inconsistent with that of the current environment. "
508- # 异构安装场景,拷贝so到指定目录538+ handle_multi_arch_install "${graph_so_dir_path}" "${GRAPH_SO_PATH}"
509- if [ -d "${TARGET_VERSION_DIR}/opp/built-in/op_graph/lib/linux" ]; then539+ handle_multi_arch_install "${host_so_dir_path}" "${HOST_SO_PATH}"
510- chmod u+w ${TARGET_VERSION_DIR}/opp/built-in/op_graph/lib/linux
511- fi
512- if [ -d "${TARGET_VERSION_DIR}/opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux" ]; then
513- chmod u+w ${TARGET_VERSION_DIR}/opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux
514- fi
515- mkdir -p ${graph_so_dir_path}
516- mkdir -p ${host_so_dir_path}
517- cp ${GRAPH_SO_PATH} ${graph_so_dir_path}
518- cp ${HOST_SO_PATH} ${host_so_dir_path}
519- chmod 755 ${graph_so_dir_path}/*
520- chmod 755 ${host_so_dir_path}/*
521- chmod u-w ${TARGET_VERSION_DIR}/opp/built-in/op_graph/lib/linux
522- chmod u-w ${TARGET_VERSION_DIR}/opp/built-in/op_impl/ai_core/tbe/op_host/lib/linux
523 exit 0540 exit 0
524 fi541 fi
525 # use uninstall to clean the install folder542 # use uninstall to clean the install folder