aboutsummaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-02-08 14:43:42 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-02-08 14:43:42 -0400
commit072b440e4dddd32c590726ec9610bb6796314a71 (patch)
tree60a7416e9d6f9a37e6d98169c7f3994fe48b5c7f /Command
parentf695762716d81c2cc6303cc75c4e2c9ecfbf43e2 (diff)
import: Avoid checksumming file twice when run in the default or --duplicate mode.
--deduplicate, --skip-duplicates, and --clean-duplicates still checksum the file twice, the first time to determine if it's a duplicate. This cannot be easily merged with the checksumming done to add the file, since the file needs to be locked down before that second checksum is taken.
Diffstat (limited to 'Command')
-rw-r--r--Command/Import.hs35
1 files changed, 15 insertions, 20 deletions
diff --git a/Command/Import.hs b/Command/Import.hs
index 196f27738..305396c7f 100644
--- a/Command/Import.hs
+++ b/Command/Import.hs
@@ -67,14 +67,8 @@ start :: DuplicateMode -> (FilePath, FilePath) -> CommandStart
start mode (srcfile, destfile) =
ifM (liftIO $ isRegularFile <$> getSymbolicLinkStatus srcfile)
( do
- isdup <- do
- backend <- chooseBackend destfile
- let ks = KeySource srcfile srcfile Nothing
- v <- genKey ks backend
- case v of
- Just (k, _) -> not . null <$> keyLocations k
- _ -> return False
- case pickaction isdup of
+ ma <- pickaction
+ case ma of
Nothing -> stop
Just a -> do
showStart "import" destfile
@@ -101,15 +95,16 @@ start mode (srcfile, destfile) =
, notoverwriting "(use --force to override)"
)
notoverwriting why = error $ "not overwriting existing " ++ destfile ++ " " ++ why
- pickaction isdup = case mode of
- DeDuplicate
- | isdup -> Just deletedup
- | otherwise -> Just importfile
- CleanDuplicates
- | isdup -> Just deletedup
- | otherwise -> Nothing
- SkipDuplicates
- | isdup -> Nothing
- | otherwise -> Just importfile
- _ -> Just importfile
-
+ checkdup dupa notdupa = do
+ backend <- chooseBackend destfile
+ let ks = KeySource srcfile srcfile Nothing
+ v <- genKey ks backend
+ isdup <- case v of
+ Just (k, _) -> not . null <$> keyLocations k
+ _ -> return False
+ return $ if isdup then dupa else notdupa
+ pickaction = case mode of
+ DeDuplicate -> checkdup (Just deletedup) (Just importfile)
+ CleanDuplicates -> checkdup (Just deletedup) Nothing
+ SkipDuplicates -> checkdup Nothing (Just importfile)
+ _ -> return (Just importfile)