From 010754c44758a62438cf091515f1e394a0edceb5 Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Thu, 28 Jan 2016 11:04:16 -0500 Subject: [PATCH 1/2] Handle the scenario where $VARLIB is a symlink If $VARLIB (typically /var/lib/freight) is a symlink to another directory, freight-cache generates an invalid $MANAGER value. This patch fixes that. I also verified that the behavior is unchanged when $VARLIB is not a symlink. --- bin/freight-cache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/freight-cache b/bin/freight-cache index 1a7d4da..52fb65f 100755 --- a/bin/freight-cache +++ b/bin/freight-cache @@ -88,7 +88,7 @@ cd "$VARLIB" if [ -z "$*" ] then DIRS="$( - find "$VARLIB" -mindepth 2 -maxdepth 2 -type d -printf "%P\n" | + find "$VARLIB"/ -mindepth 2 -maxdepth 2 -type d -printf "%P\n" | grep -v "^\\." | tr "\n" " " )" @@ -100,7 +100,7 @@ do # Parse the manager and distro out of the Freight library path. DIR="$(readlink -f "$DIR")" - DIR="${DIR##"$VARLIB/"}" + DIR="${DIR##"$(readlink -f "$VARLIB")/"}" MANAGER="$(dirname "$DIR")" DIST="$(basename "$DIR")" From 8b2b575e549922ee8561466cf94352d911c23bdd Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Fri, 25 Mar 2016 15:46:14 +0000 Subject: [PATCH 2/2] Add tests for VARLIB being a symlink --- test/apt_add.bats | 7 +++++++ test/apt_cache.bats | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/test/apt_add.bats b/test/apt_add.bats index 7ca10ff..b3fc7b1 100644 --- a/test/apt_add.bats +++ b/test/apt_add.bats @@ -52,3 +52,10 @@ setup() { assert_output "# [freight] added ${FIXTURES}/source_1.0.orig.tar.gz to apt/example" test -e ${FREIGHT_LIB}/apt/example/source_1.0.orig.tar.gz } + +@test "freight-add handles VARLIB being a symlink" { + mv $FREIGHT_LIB ${FREIGHT_LIB}_real + ln -s ${FREIGHT_LIB}_real $FREIGHT_LIB + freight_add ${FIXTURES}/test_1.0_all.deb apt/example/comp + test -e ${FREIGHT_LIB}_real/apt/example/comp/test_1.0_all.deb +} diff --git a/test/apt_cache.bats b/test/apt_cache.bats index a508766..7f8ef18 100644 --- a/test/apt_cache.bats +++ b/test/apt_cache.bats @@ -69,3 +69,11 @@ setup() { assert_output "" test -e ${FREIGHT_CACHE}/pool/example/main/t/test/test_1.0_all.deb } + +@test "freight-cache handles VARLIB being a symlink" { + mv $FREIGHT_LIB ${FREIGHT_LIB}_real + ln -s ${FREIGHT_LIB}_real $FREIGHT_LIB + freight_cache + test -e ${FREIGHT_CACHE}/pool/example/comp/t/test/test_1.0_all.deb + test -e ${FREIGHT_CACHE}/pool/example/main/t/test/test_1.0_all.deb +}