diff options
author | Joey Hess <joey@kitenet.net> | 2012-12-10 15:02:44 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-12-10 15:02:44 -0400 |
commit | 95ae655c5ecad7d753539c60d3e16b47cd17346b (patch) | |
tree | 3e5421042d7b58bf4b0bdcd221dc54d6dffceaec /Annex/Content | |
parent | d66a0265a239b52a0f82dbf648f6dfccfe2eed9c (diff) |
update
Diffstat (limited to 'Annex/Content')
-rw-r--r-- | Annex/Content/Direct.hs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs index 9f4026ed6..99b54f7e0 100644 --- a/Annex/Content/Direct.hs +++ b/Annex/Content/Direct.hs @@ -32,8 +32,7 @@ import qualified Data.ByteString.Lazy as L - When no known associated files exist, returns the gitAnnexLocation. -} associatedFiles :: Key -> Annex [FilePath] associatedFiles key = do - mapping <- inRepo $ gitAnnexMapping key - files <- liftIO $ catchDefaultIO [] $ lines <$> readFile mapping + files <- associatedFilesList key if null files then do l <- inRepo $ gitAnnexLocation key @@ -42,16 +41,21 @@ associatedFiles key = do top <- fromRepo Git.repoPath return $ map (top </>) files +{- Raw list of files in the tree that are associated with a key. -} +associatedFilesList :: Key -> Annex [FilePath] +associatedFilesList key = do + mapping <- inRepo $ gitAnnexMapping key + liftIO $ catchDefaultIO [] $ lines <$> readFile mapping + {- Changes the associated files information for a key, applying a - transformation to the list. -} changeAssociatedFiles :: Key -> ([FilePath] -> [FilePath]) -> Annex () changeAssociatedFiles key transform = do mapping <- inRepo $ gitAnnexMapping key - liftIO $ do - files <- catchDefaultIO [] $ lines <$> readFile mapping - let files' = transform files - when (files /= files') $ - viaTmp writeFile mapping $ unlines files' + files <- associatedFilesList key + let files' = transform files + when (files /= files') $ + liftIO $ viaTmp writeFile mapping $ unlines files' removeAssociatedFile :: Key -> FilePath -> Annex () removeAssociatedFile key file = changeAssociatedFiles key $ filter (/= file) @@ -63,7 +67,7 @@ addAssociatedFile key file = changeAssociatedFiles key $ \files -> else file:files {- Uses git diff-tree to find files changed between two tree Shas, and - - updates the associated file mappings, efficiently -} + - updates the associated file mappings, efficiently. -} updateAssociatedFiles :: Git.Sha -> Git.Sha -> Annex () updateAssociatedFiles oldsha newsha = do (items, cleanup) <- inRepo $ DiffTree.diffTree oldsha newsha |