From bac7288b5988a2e10c99fe33e575295b80bc5863 Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Thu, 9 Nov 2023 10:17:40 +0000 Subject: [PATCH] plugin: initrd: fix tests Signed-off-by: Ondrej Kubik --- snapcraft_legacy/plugins/v2/_initrd_build.py | 70 ++++++++++---------- tests/legacy/unit/plugins/v2/test_initrd.py | 68 +++++++++---------- 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/snapcraft_legacy/plugins/v2/_initrd_build.py b/snapcraft_legacy/plugins/v2/_initrd_build.py index d7e11655875..8b3f46c8ead 100644 --- a/snapcraft_legacy/plugins/v2/_initrd_build.py +++ b/snapcraft_legacy/plugins/v2/_initrd_build.py @@ -58,40 +58,40 @@ def _link_files_fnc_cmd() -> List[str]: # link files, accept wild cards # 1: reference dir, 2: file(s) including wild cards, 3: dst dir link_files() { - if [ "${2}" = "*" ]; then - for f in $(ls ${1}) - do - link_files "${1}" "${f}" "${3}" - done - return 0 - fi - if [ -d "${1}/${2}" ]; then - for f in $(ls ${1}/${2}) - do - link_files "${1}" "${2}/${f}" "${3}" - done - return 0 - fi - - local found="" - for f in $(ls ${1}/${2}) - do - if [[ -L "${f}" ]]; then - local rel_path=$( realpath --no-symlinks --relative-to=${1} ${f} ) - else - local rel_path=$( realpath -se --relative-to=${1} ${f} ) - fi - local dir_path=$(dirname ${rel_path}) - mkdir -p ${3}/${dir_path} - echo "installing ${f} to ${3}/${dir_path}" - ln -f ${f} ${3}/${dir_path} - found="yes" - done - if [ "yes" = "${found}" ]; then - return 0 - else - return 1 - fi + if [ "${2}" = "*" ]; then + for f in $(ls ${1}) + do + link_files "${1}" "${f}" "${3}" + done + return 0 + fi + if [ -d "${1}/${2}" ]; then + for f in $(ls ${1}/${2}) + do + link_files "${1}" "${2}/${f}" "${3}" + done + return 0 + fi + + local found="" + for f in $(ls ${1}/${2}) + do + if [[ -L "${f}" ]]; then + local rel_path=$( realpath --no-symlinks --relative-to=${1} ${f} ) + else + local rel_path=$( realpath -se --relative-to=${1} ${f} ) + fi + local dir_path=$(dirname ${rel_path}) + mkdir -p ${3}/${dir_path} + echo "installing ${f} to ${3}/${dir_path}" + ln -f ${f} ${3}/${dir_path} + found="yes" + done + if [ "yes" = "${found}" ]; then + return 0 + else + return 1 + fi } """ ) @@ -668,7 +668,7 @@ def _get_initrd_install_command( install_dir: str, stage_dir: str, ) -> List[str]: - + return [ 'echo "building initramfs..."', "", diff --git a/tests/legacy/unit/plugins/v2/test_initrd.py b/tests/legacy/unit/plugins/v2/test_initrd.py index 01d74b6629e..18a8f6b8c39 100755 --- a/tests/legacy/unit/plugins/v2/test_initrd.py +++ b/tests/legacy/unit/plugins/v2/test_initrd.py @@ -469,40 +469,40 @@ def _is_sub_array(array, sub_array): # link files, accept wild cards # 1: reference dir, 2: file(s) including wild cards, 3: dst dir link_files() { - if [ "${2}" = "*" ]; then - for f in $(ls ${1}) - do - link_files "${1}" "${f}" "${3}" - done - return 0 - fi - if [ -d "${1}/${2}" ]; then - for f in $(ls ${1}/${2}) - do - link_files "${1}" "${2}/${f}" "${3}" - done - return 0 - fi - - local found="" - for f in $(ls ${1}/${2}) - do - if [[ -L "${f}" ]]; then - local rel_path=$( realpath --no-symlinks --relative-to=${1} ${f} ) - else - local rel_path=$( realpath -se --relative-to=${1} ${f} ) - fi - local dir_path=$(dirname ${rel_path}) - mkdir -p ${3}/${dir_path} - echo "installing ${f} to ${3}/${dir_path}" - ln -f ${f} ${3}/${dir_path} - found="yes" - done - if [ "yes" = "${found}" ]; then - return 0 - else - return 1 - fi + if [ "${2}" = "*" ]; then + for f in $(ls ${1}) + do + link_files "${1}" "${f}" "${3}" + done + return 0 + fi + if [ -d "${1}/${2}" ]; then + for f in $(ls ${1}/${2}) + do + link_files "${1}" "${2}/${f}" "${3}" + done + return 0 + fi + + local found="" + for f in $(ls ${1}/${2}) + do + if [[ -L "${f}" ]]; then + local rel_path=$( realpath --no-symlinks --relative-to=${1} ${f} ) + else + local rel_path=$( realpath -se --relative-to=${1} ${f} ) + fi + local dir_path=$(dirname ${rel_path}) + mkdir -p ${3}/${dir_path} + echo "installing ${f} to ${3}/${dir_path}" + ln -f ${f} ${3}/${dir_path} + found="yes" + done + if [ "yes" = "${found}" ]; then + return 0 + else + return 1 + fi } """ )