From f1e51105f413082e3d9136330360a54f7cf3c248 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 11 Dec 2015 15:13:36 -0400 Subject: finish v6 git-annex lock This was a doozy! --- Annex/Content.hs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Annex') diff --git a/Annex/Content.hs b/Annex/Content.hs index 756c801ad..f0c8e25cd 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -27,6 +27,7 @@ module Annex.Content ( linkAnnex, linkAnnex', LinkAnnexResult(..), + checkedCopyFile, sendAnnex, prepSendAnnex, removeAnnex, @@ -549,16 +550,25 @@ data LinkAnnexResult = LinkAnnexOk | LinkAnnexFailed | LinkAnnexNoop linkAnnex'' :: Key -> FilePath -> FilePath -> Annex Bool linkAnnex'' key src dest = catchBoolIO $ do s <- liftIO $ getFileStatus src + let copy = checkedCopyFile' key src dest s #ifndef mingw32_HOST_OS if linkCount s > 1 - then copy s + then copy else liftIO (createLink src dest >> return True) - `catchIO` const (copy s) + `catchIO` const copy #else - copy s + copy #endif - where - copy s = ifM (checkDiskSpace' (fromIntegral $ fileSize s) (Just $ takeDirectory dest) key 0 True) + +{- Checks disk space before copying. -} +checkedCopyFile :: Key -> FilePath -> FilePath -> Annex Bool +checkedCopyFile key src dest = catchBoolIO $ + checkedCopyFile' key src dest + =<< liftIO (getFileStatus src) + +checkedCopyFile' :: Key -> FilePath -> FilePath -> FileStatus -> Annex Bool +checkedCopyFile' key src dest s = catchBoolIO $ + ifM (checkDiskSpace' (fromIntegral $ fileSize s) (Just $ takeDirectory dest) key 0 True) ( liftIO $ copyFileExternal CopyAllMetaData src dest , return False ) -- cgit v1.2.3