From 51338486dcf9ab86de426e41b1eb31af1d3a6c87 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Mar 2012 12:42:52 -0400 Subject: Fix a bug in symlink calculation code, that triggered in rare cases where an annexed file is in a subdirectory that nearly matched to the .git/annex/object/xx/yy subdirectories. This is a straight up pure-code stinker. The relative path calculation looked for common subdirectories in the two paths, but failed to stop after the paths diverged. When a later pair of subdirectories were the same, the resulting relative path was wrong. Added regression test for this. --- Utility/Path.hs | 11 ++++++++++- debian/changelog | 3 +++ test.hs | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Utility/Path.hs b/Utility/Path.hs index ed5e59cb5..eb530442b 100644 --- a/Utility/Path.hs +++ b/Utility/Path.hs @@ -82,7 +82,7 @@ relPathDirToFile from to = join s $ dotdots ++ uncommon s = [pathSeparator] pfrom = split s from pto = split s to - common = map fst $ filter same $ zip pfrom pto + common = map fst $ takeWhile same $ zip pfrom pto same (c,d) = c == d uncommon = drop numcommon pto dotdots = replicate (length pfrom - numcommon) ".." @@ -95,6 +95,15 @@ prop_relPathDirToFile_basics from to where r = relPathDirToFile from to +prop_relPathDirToFile_regressionTest :: Bool +prop_relPathDirToFile_regressionTest = same_dir_shortcurcuits_at_difference + where + {- Two paths have the same directory component at the same + - location, but it's not really the same directory. + - Code used to get this wrong. -} + same_dir_shortcurcuits_at_difference = + relPathDirToFile "/tmp/r/lll/xxx/yyy/18" "/tmp/r/.git/annex/objects/18/gk/SHA256-foo/SHA256-foo" == "../../../../.git/annex/objects/18/gk/SHA256-foo/SHA256-foo" + {- Given an original list of files, and an expanded list derived from it, - ensures that the original list's ordering is preserved. - diff --git a/debian/changelog b/debian/changelog index 8ac34487b..cbcb46e83 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,9 @@ git-annex (3.20120230) UNRELEASED; urgency=low * Add configurable hooks that are run when git-annex starts and stops using a remote: remote.name.annex-start-command and remote.name.annex-stop-command + * Fix a bug in symlink calculation code, that triggered in rare + cases where an annexed file is in a subdirectory that nearly + matched to the .git/annex/object/xx/yy subdirectories. -- Joey Hess Thu, 01 Mar 2012 22:34:27 -0400 diff --git a/test.hs b/test.hs index bbb8001d6..431517114 100644 --- a/test.hs +++ b/test.hs @@ -82,6 +82,7 @@ quickcheck = TestLabel "quickcheck" $ TestList , qctest "prop_parentDir_basics" Utility.Path.prop_parentDir_basics , qctest "prop_relPathDirToFile_basics" Utility.Path.prop_relPathDirToFile_basics + , qctest "prop_relPathDirToFile_regressionTest" Utility.Path.prop_relPathDirToFile_regressionTest , qctest "prop_cost_sane" Config.prop_cost_sane , qctest "prop_hmacWithCipher_sane" Crypto.prop_hmacWithCipher_sane , qctest "prop_TimeStamp_sane" Logs.UUIDBased.prop_TimeStamp_sane -- cgit v1.2.3