diff options
author | Joey Hess <joey@kitenet.net> | 2013-04-11 13:35:52 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-04-11 13:35:52 -0400 |
commit | e15223eba22e27f934c366b17a62c80f676360e8 (patch) | |
tree | b0a86335757bf247b6ae956db3ca902086ba7997 /Command | |
parent | 321bae61104bd64126aedb3b03093ff6e4daf35a (diff) |
addurl: Bugfix: Did not properly add file in direct mode.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Add.hs | 37 | ||||
-rw-r--r-- | Command/AddUnused.hs | 6 | ||||
-rw-r--r-- | Command/AddUrl.hs | 28 | ||||
-rw-r--r-- | Command/ReKey.hs | 5 |
4 files changed, 45 insertions, 31 deletions
diff --git a/Command/Add.hs b/Command/Add.hs index a5dfc1d1c..2453e6842 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -188,19 +188,29 @@ link file key hascontent = handle (undo file key) $ do return l -{- Note: Several other commands call this, and expect it to - - create the link and add it. - - - - In direct mode, when we have the content of the file, it's left as-is, - - and we just stage a symlink to git. - - - - Otherwise, as long as the filesystem supports symlinks, we use +{- Creates the symlink to the annexed content, and stages it in git. + - + - As long as the filesystem supports symlinks, we use - git add, rather than directly staging the symlink to git. - Using git add is best because it allows the queuing to work - and is faster (staging the symlink runs hash-object commands each time). - Also, using git add allows it to skip gitignored files, unless forced - to include them. -} +addLink :: FilePath -> Key -> Bool -> Annex () +addLink file key hascontent = ifM (coreSymlinks <$> Annex.getGitConfig) + ( do + _ <- link file key hascontent + params <- ifM (Annex.getState Annex.force) + ( return [Param "-f"] + , return [] + ) + Annex.Queue.addCommand "add" (params++[Param "--"]) [file] + , do + l <- link file key hascontent + addAnnexLink l file + ) + cleanup :: FilePath -> Key -> Bool -> CommandCleanup cleanup file key hascontent = do when hascontent $ @@ -209,17 +219,6 @@ cleanup file key hascontent = do ( do l <- inRepo $ gitAnnexLink file key stageSymlink file =<< hashSymlink l - , ifM (coreSymlinks <$> Annex.getGitConfig) - ( do - _ <- link file key hascontent - params <- ifM (Annex.getState Annex.force) - ( return [Param "-f"] - , return [] - ) - Annex.Queue.addCommand "add" (params++[Param "--"]) [file] - , do - l <- link file key hascontent - addAnnexLink l file - ) + , addLink file key hascontent ) return True diff --git a/Command/AddUnused.hs b/Command/AddUnused.hs index c352d87d0..33acc4487 100644 --- a/Command/AddUnused.hs +++ b/Command/AddUnused.hs @@ -9,6 +9,7 @@ module Command.AddUnused where import Common.Annex import Logs.Unused +import Logs.Location import Command import qualified Command.Add import Types.Key @@ -26,7 +27,10 @@ start = startUnused "addunused" perform (performOther "tmp") perform :: Key -> CommandPerform -perform key = next $ Command.Add.cleanup file key True +perform key = next $ do + logStatus key InfoPresent + Command.Add.addLink file key False + return True where file = "unused." ++ key2file key diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 7c235922d..a8e3588d8 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -14,6 +14,7 @@ import Command import Backend import qualified Command.Add import qualified Annex +import qualified Annex.Queue import qualified Backend.URL import qualified Utility.Url as Url import Annex.Content @@ -23,6 +24,7 @@ import Types.Key import Types.KeySource import Config import Annex.Content.Direct +import Logs.Location def :: [Command] def = [notBareRepo $ withOptions [fileOption, pathdepthOption, relaxedOption] $ @@ -92,12 +94,21 @@ download url file = do k <- genKey source backend case k of Nothing -> stop - Just (key, _) -> do - whenM isDirect $ - void $ addAssociatedFile key file - moveAnnex key tmp - setUrlPresent key url - next $ Command.Add.cleanup file key True + Just (key, _) -> next $ cleanup url file key (Just tmp) + +cleanup :: String -> FilePath -> Key -> Maybe FilePath -> CommandCleanup +cleanup url file key mtmp = do + when (isJust mtmp) $ + logStatus key InfoPresent + setUrlPresent key url + Command.Add.addLink file key False + whenM isDirect $ do + void $ addAssociatedFile key file + {- For moveAnnex to work in direct mode, the symlink + - must already exist, so flush the queue. -} + Annex.Queue.flush + maybe noop (moveAnnex key) mtmp + return True nodownload :: Bool -> String -> FilePath -> CommandPerform nodownload relaxed url file = do @@ -108,10 +119,7 @@ nodownload relaxed url file = do if exists then do let key = Backend.URL.fromUrl url size - whenM isDirect $ - void $ addAssociatedFile key file - setUrlPresent key url - next $ Command.Add.cleanup file key False + next $ cleanup url file key Nothing else do warning $ "unable to access url: " ++ url stop diff --git a/Command/ReKey.hs b/Command/ReKey.hs index d14edb06d..bc4a9fac9 100644 --- a/Command/ReKey.hs +++ b/Command/ReKey.hs @@ -14,6 +14,7 @@ import Types.Key import Annex.Content import qualified Command.Add import Logs.Web +import Logs.Location import Config import Utility.CopyFile @@ -70,4 +71,6 @@ cleanup file oldkey newkey = do -- Update symlink to use the new key. liftIO $ removeFile file - Command.Add.cleanup file newkey True + Command.Add.addLink file newkey True + logStatus newkey InfoPresent + return True |