diff options
author | Joey Hess <joey@kitenet.net> | 2012-03-05 12:42:52 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-03-05 12:42:52 -0400 |
commit | 51338486dcf9ab86de426e41b1eb31af1d3a6c87 (patch) | |
tree | af9c9edd522daf933082a40d135c24bc154d2700 /Utility/Path.hs | |
parent | 52e88f3ebf974c3802e951e17593ce5768c04b92 (diff) |
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.
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r-- | Utility/Path.hs | 11 |
1 files changed, 10 insertions, 1 deletions
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. - |