From 9f179ae8b93d113b5877cade3e5a336a5cb8d0c4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 22 Nov 2016 11:12:33 -0400 Subject: [PATCH] fix regression The file matcher needs to be run on the destination file not the tmp file, in order for filename matches to work properly. However, it also needs to be able to probe the file for size and mime type. This is a quick fix to a regression. The double rename is not pretty. It would be good to either have a way to run the largeFileMatcher such that it is matching on the final filename but looks at the temp file, or to make addAnnexedFile not need the temp file in a different location. --- Command/AddUrl.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 9b6ac28ea9..e49d2727c7 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -340,13 +340,18 @@ cleanup :: UUID -> URLString -> FilePath -> Key -> Maybe FilePath -> Annex () cleanup u url file key mtmp = case mtmp of Nothing -> go Just tmp -> do + -- Move to final location for large file check. + liftIO $ renameFile tmp file largematcher <- largeFilesMatcher - ifM (checkFileMatcher largematcher tmp) - ( go - , do - liftIO $ renameFile tmp file - void $ Command.Add.addSmall file - ) + large <- checkFileMatcher largematcher file + if large + then do + -- Move back to tmp because addAnnexedFile + -- needs the file in a different location + -- than the work tree file. + liftIO $ renameFile file tmp + go + else void $ Command.Add.addSmall file where go = do maybeShowJSON $ JSONChunk [("key", key2file key)]