diff options
author | Junichi Uekawa <dancer@netfort.gr.jp> | 2011-12-04 22:17:32 +0900 |
---|---|---|
committer | Junichi Uekawa <dancer@netfort.gr.jp> | 2011-12-04 22:17:32 +0900 |
commit | 36b02fd98cdfefb9a6ec1fd4cf006c7eaf484506 (patch) | |
tree | 229ccf873a2631e0121596152b732e62aae69a15 | |
parent | 57a6a286b437ef6715ec7ac608898a0dabc32444 (diff) | |
download | pbuilder-36b02fd98cdfefb9a6ec1fd4cf006c7eaf484506.tar pbuilder-36b02fd98cdfefb9a6ec1fd4cf006c7eaf484506.tar.gz |
factor out the file copy test part and add a test.
Use 'PWD' like other parts of the codebase.
Coding style uses $() not ``.
-rw-r--r-- | pbuilder-modules | 19 | ||||
-rw-r--r-- | pdebuild | 9 | ||||
-rwxr-xr-x | test_pbuilder-modules | 22 |
3 files changed, 43 insertions, 7 deletions
diff --git a/pbuilder-modules b/pbuilder-modules index b596d5d..22eaafe 100644 --- a/pbuilder-modules +++ b/pbuilder-modules @@ -561,6 +561,25 @@ function umountproc_trap () { exit 1 } +# copy to .. if target directory is not .. +function conditional_cp_a() { + local source_file="$1" + # NOTE: target_dir must not end with /, which is usually the case + # with 'readlink -f' result, which BUILDRESULT usually is. + local target_dir="$2" + # For testability, make cp overridable. + local cp="${3:-cp}" + + # $PWD should end with non-'/', so dirname should give us the parent dir. + local parent_dir=$(dirname "$PWD") + + if [ "${parent_dir}" != "${target_dir}" ]; then + "$cp" -a "$source_file" "$target_dir" + else + echo "I: file ${source_file} is already in target, not copying." + fi +} + #Setting environmental variables that are really required: #required for some packages to install... export LANG=C @@ -46,15 +46,10 @@ export BUILDRESULTGID=$(id -g) if [ "${USE_PDEBUILD_INTERNAL}" = 'yes' ]; then ${PBUILDERROOTCMD} ${PDEBUILD_PBUILDER} --execute ${EXTRA_CONFIGFILE[@]/#/--configfile } --bindmounts $(readlink -f ..) "$@" -- /usr/lib/pbuilder/pdebuild-internal ${PWD} --debbuildopts "" --debbuildopts "${DEBBUILDOPTS}" --uid "${BUILDRESULTUID}" --gid "${BUILDRESULTGID}" --pbuildersatisfydepends "$PBUILDERSATISFYDEPENDSCMD" if [ -d "${BUILDRESULT}" ]; then - PARENT_DIR=`dirname $(pwd)` for files in $(sed -rn '/^Files:/,${s/^ .* ([^ ]+)$/\1/p}' ../${CHANGES}); do - if [ "${PARENT_DIR}" != "${BUILDRESULT}" ]; then - cp -a ../"$files" "${BUILDRESULT}" - fi + conditional_cp_a ../"$files" "${BUILDRESULT}" done - if [ "${PARENT_DIR}" != "${BUILDRESULT}" ]; then - cp -a ../${CHANGES} "${BUILDRESULT}" - fi + conditional_cp_a ../${CHANGES} "${BUILDRESULT}" else log "E: BUILDRESULT=[$BUILDRESULT] is not a directory." exit 1 diff --git a/test_pbuilder-modules b/test_pbuilder-modules index bec24e1..ffd8b3e 100755 --- a/test_pbuilder-modules +++ b/test_pbuilder-modules @@ -22,4 +22,26 @@ expect_output "I: test W: warning E: error" test_information +# test the non-copy case +function test_conditional_cp_a() { + ( + TEMPDIR=$(mktemp -d) + cd "${TEMPDIR}" + touch "hoge" + outdir=$(readlink -f "${TEMPDIR}/..") + conditional_cp_a "hoge" "${outdir}" echo + ) +} +expect_output "" test_conditional_cp_a + +# test the copy case. +function test_conditional_cp_a_copy() { + ( + cd /tmp + outdir=/something-else + conditional_cp_a "hoge" "${outdir}" echo + ) +} +expect_output "-a hoge /something-else" test_conditional_cp_a_copy + testlib_summary |