diff --git a/Annex/WorkTree.hs b/Annex/WorkTree.hs index fc01daef1f..6dcd75f66e 100644 --- a/Annex/WorkTree.hs +++ b/Annex/WorkTree.hs @@ -1,6 +1,6 @@ {- git-annex worktree files - - - Copyright 2013-2018 Joey Hess + - Copyright 2013-2019 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -36,13 +36,28 @@ import qualified Database.Keys.SQL - pointer to a key in the original branch. -} lookupFile :: FilePath -> Annex (Maybe Key) -lookupFile file = isAnnexLink file >>= \case - Just key -> return (Just key) - Nothing -> ifM (versionSupportsUnlockedPointers <||> isDirect) - ( ifM (liftIO $ doesFileExist file) +lookupFile = lookupFile' catkeyfile + where + catkeyfile file = + ifM (liftIO $ doesFileExist file) ( catKeyFile file , catKeyFileHidden file =<< getCurrentBranch ) + +lookupFileNotHidden :: FilePath -> Annex (Maybe Key) +lookupFileNotHidden = lookupFile' catkeyfile + where + catkeyfile file = + ifM (liftIO $ doesFileExist file) + ( catKeyFile file + , return Nothing + ) + +lookupFile' :: (FilePath -> Annex (Maybe Key)) -> FilePath -> Annex (Maybe Key) +lookupFile' catkeyfile file = isAnnexLink file >>= \case + Just key -> return (Just key) + Nothing -> ifM (versionSupportsUnlockedPointers <||> isDirect) + ( catkeyfile file , return Nothing ) diff --git a/CHANGELOG b/CHANGELOG index 3e691dfd36..fa68ca2f15 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ git-annex (7.20190130) UNRELEASED; urgency=medium * Display progress bar when getting files from export remotes. * Fix race in cleanup of othertmp directory that could result in a failure attempting to access it. + * fromkey: Made idempotent. -- Joey Hess Wed, 30 Jan 2019 12:30:22 -0400 diff --git a/Command/FromKey.hs b/Command/FromKey.hs index 4e1bc4fcae..401ae9225b 100644 --- a/Command/FromKey.hs +++ b/Command/FromKey.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2010-2018 Joey Hess + - Copyright 2010-2019 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -12,6 +12,7 @@ module Command.FromKey where import Command import qualified Annex.Queue import Annex.Content +import Annex.WorkTree import qualified Annex import qualified Backend.URL @@ -89,9 +90,13 @@ perform key file = do next $ return ok perform' :: Key -> FilePath -> Annex Bool -perform' key file = do - link <- calcRepo $ gitAnnexLink file key - liftIO $ createDirectoryIfMissing True (parentDir file) - liftIO $ createSymbolicLink link file - Annex.Queue.addCommand "add" [Param "--"] [file] - return True +perform' key file = lookupFileNotHidden file >>= \case + Nothing -> do + link <- calcRepo $ gitAnnexLink file key + liftIO $ createDirectoryIfMissing True (parentDir file) + liftIO $ createSymbolicLink link file + Annex.Queue.addCommand "add" [Param "--"] [file] + return True + Just k + | k == key -> return True + | otherwise -> giveup $ file ++ " already exists with different content" diff --git a/doc/todo/git-annex-fromkey_behavior_when_target_file_exists.mdwn b/doc/todo/git-annex-fromkey_behavior_when_target_file_exists.mdwn index 743c027cf9..17414993b9 100644 --- a/doc/todo/git-annex-fromkey_behavior_when_target_file_exists.mdwn +++ b/doc/todo/git-annex-fromkey_behavior_when_target_file_exists.mdwn @@ -1 +1,3 @@ Currently, git-annex-fromkey errors if the target file exists. It would help if, when the target file is the same symlink that would be created by the command (i.e. to the same key), this wasn't considered an error. Together with [[todo/batch_command_result_status]] this would make the command a more robust building block for higher-level operations. + +> idempotency is good, [[done]] --[[Joey]]