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.
This commit is contained in:
Joey Hess 2015-02-08 14:43:42 -04:00
parent 102458e8f3
commit 27ad41b355
2 changed files with 17 additions and 20 deletions

View file

@ -67,14 +67,8 @@ start :: DuplicateMode -> (FilePath, FilePath) -> CommandStart
start mode (srcfile, destfile) = start mode (srcfile, destfile) =
ifM (liftIO $ isRegularFile <$> getSymbolicLinkStatus srcfile) ifM (liftIO $ isRegularFile <$> getSymbolicLinkStatus srcfile)
( do ( do
isdup <- do ma <- pickaction
backend <- chooseBackend destfile case ma of
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
Nothing -> stop Nothing -> stop
Just a -> do Just a -> do
showStart "import" destfile showStart "import" destfile
@ -101,15 +95,16 @@ start mode (srcfile, destfile) =
, notoverwriting "(use --force to override)" , notoverwriting "(use --force to override)"
) )
notoverwriting why = error $ "not overwriting existing " ++ destfile ++ " " ++ why notoverwriting why = error $ "not overwriting existing " ++ destfile ++ " " ++ why
pickaction isdup = case mode of checkdup dupa notdupa = do
DeDuplicate backend <- chooseBackend destfile
| isdup -> Just deletedup let ks = KeySource srcfile srcfile Nothing
| otherwise -> Just importfile v <- genKey ks backend
CleanDuplicates isdup <- case v of
| isdup -> Just deletedup Just (k, _) -> not . null <$> keyLocations k
| otherwise -> Nothing _ -> return False
SkipDuplicates return $ if isdup then dupa else notdupa
| isdup -> Nothing pickaction = case mode of
| otherwise -> Just importfile DeDuplicate -> checkdup (Just deletedup) (Just importfile)
_ -> Just importfile CleanDuplicates -> checkdup (Just deletedup) Nothing
SkipDuplicates -> checkdup Nothing (Just importfile)
_ -> return (Just importfile)

2
debian/changelog vendored
View file

@ -10,6 +10,8 @@ git-annex (5.20150206) UNRELEASED; urgency=medium
--smallerthan, --largerthan --smallerthan, --largerthan
* The file matching options are now only accepted by commands that * The file matching options are now only accepted by commands that
can actually use them, instead of by all commands. can actually use them, instead of by all commands.
* import: Avoid checksumming file twice when run in the default
or --duplicate mode.
-- Joey Hess <id@joeyh.name> Fri, 06 Feb 2015 13:57:08 -0400 -- Joey Hess <id@joeyh.name> Fri, 06 Feb 2015 13:57:08 -0400