From 1791447cc8c1532e2fd81ee60f55f9a333183b99 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 14 Jan 2019 13:07:18 -0400 Subject: [PATCH] avoid creating work tree files in subdirectories in an edge case A keyName could contain "/", though this is unlikely and certianly only ever could happen with WORM keys. The change to addunused to escape that is no problem at all. The change to VariantFile to escape it means that different versions of git-annex could resolve a merge conflict differently in this case, which is unfortunate. There would be different .variant files used, so the two resolutions would themselves merge together without additional conflicts, but the user would have to clean up the extra .variant files. --- Annex/VariantFile.hs | 10 ++++++---- CHANGELOG | 2 ++ Command/AddUnused.hs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Annex/VariantFile.hs b/Annex/VariantFile.hs index 7eee545ec7..acab1e8281 100644 --- a/Annex/VariantFile.hs +++ b/Annex/VariantFile.hs @@ -10,6 +10,8 @@ module Annex.VariantFile where import Annex.Common import Utility.Hash +import qualified Data.ByteString.Lazy as L + variantMarker :: String variantMarker = ".variant-" @@ -34,10 +36,10 @@ mkVariant file variant = takeDirectory file -} variantFile :: FilePath -> Key -> FilePath variantFile file key - | doubleconflict = mkVariant file (serializeKey key) - | otherwise = mkVariant file (shortHash $ serializeKey key) + | doubleconflict = mkVariant file (keyFile key) + | otherwise = mkVariant file (shortHash $ serializeKey' key) where doubleconflict = variantMarker `isInfixOf` file -shortHash :: String -> String -shortHash = take 4 . show . md5 . encodeBL +shortHash :: L.ByteString -> String +shortHash = take 4 . show . md5 diff --git a/CHANGELOG b/CHANGELOG index 21c7d5c4e2..e44ee49d0d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,8 @@ git-annex (7.20181212) UNRELEASED; urgency=medium * Improve uuid.log parser to preserve whitespace in repo descriptions. * Improve activity.log parser to not remove unknown values, allowing for future expansion. + * addunused, merge, assistant: Avoid creating work tree files in + subdirectories in an edge case where the key contains "/". -- Joey Hess Tue, 18 Dec 2018 12:24:52 -0400 diff --git a/Command/AddUnused.hs b/Command/AddUnused.hs index 0ac2316122..b07d2ba20f 100644 --- a/Command/AddUnused.hs +++ b/Command/AddUnused.hs @@ -32,7 +32,7 @@ perform key = next $ do addLink file key Nothing return True where - file = "unused." ++ serializeKey key + file = "unused." ++ keyFile key {- The content is not in the annex, but in another directory, and - it seems better to error out, rather than moving bad/tmp content into