From d88be65495a754186b0906f73f0ce25b5ae4f800 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 20 May 2013 16:28:33 -0400 Subject: [PATCH] didn't quite get removeDirect right before, this passes test suite --- Annex/Content/Direct.hs | 14 +++++++++++--- Annex/Direct.hs | 13 ++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs index 91073f687b..ef2573c344 100644 --- a/Annex/Content/Direct.hs +++ b/Annex/Content/Direct.hs @@ -8,6 +8,7 @@ module Annex.Content.Direct ( associatedFiles, removeAssociatedFile, + removeAssociatedFileUnchecked, addAssociatedFile, goodContent, recordedInodeCache, @@ -73,15 +74,22 @@ changeAssociatedFiles key transform = do hPutStr h content hClose h -{- Removes an associated file. Returns new associatedFiles value. -} +{- Removes an associated file. Returns new associatedFiles value. + - Checks if this was the last copy of the object, and updates location + - log. -} removeAssociatedFile :: Key -> FilePath -> Annex [FilePath] removeAssociatedFile key file = do - file' <- normaliseAssociatedFile file - fs <- changeAssociatedFiles key $ filter (/= file') + fs <- removeAssociatedFileUnchecked key file when (null fs) $ logStatus key InfoMissing return fs +{- Removes an associated file. Returns new associatedFiles value. -} +removeAssociatedFileUnchecked :: Key -> FilePath -> Annex [FilePath] +removeAssociatedFileUnchecked key file = do + file' <- normaliseAssociatedFile file + changeAssociatedFiles key $ filter (/= file') + {- Adds an associated file. Returns new associatedFiles value. -} addAssociatedFile :: Key -> FilePath -> Annex [FilePath] addAssociatedFile key file = do diff --git a/Annex/Direct.hs b/Annex/Direct.hs index 6d9f3e31db..962c7595c1 100644 --- a/Annex/Direct.hs +++ b/Annex/Direct.hs @@ -203,13 +203,16 @@ toDirectGen k f = do liftIO . void . copyFileExternal loc _ -> return Nothing -{- Removes a direct mode file, while retaining its content in the annex. -} +{- Removes a direct mode file, while retaining its content in the annex + - (unless its content has already been changed). -} removeDirect :: Key -> FilePath -> Annex () removeDirect k f = do - otherlocs <- removeAssociatedFile k f - unless (null otherlocs) $ - unlessM (inAnnex k) $ - moveAnnex k f + void $ removeAssociatedFileUnchecked k f + unlessM (inAnnex k) $ + ifM (goodContent k f) + ( moveAnnex k f + , logStatus k InfoMissing + ) liftIO $ do nukeFile f void $ tryIO $ removeDirectory $ parentDir f