diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-03-15 14:07:43 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-03-15 14:07:43 -0400 |
commit | 96af58d9e0f73ad78f09651e855b20cc27f9113a (patch) | |
tree | 2a939a600e11870caf511cf592819282f0d25c63 /Command | |
parent | 5f7979ffe85e036451bb869e29ca161ad3aa0272 (diff) |
fromkey: Add stdin mode.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/FromKey.hs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/Command/FromKey.hs b/Command/FromKey.hs index 7176d97a5..d18fa16cc 100644 --- a/Command/FromKey.hs +++ b/Command/FromKey.hs @@ -5,6 +5,8 @@ - Licensed under the GNU GPL version 3 or higher. -} +{-# LANGUAGE BangPatterns #-} + module Command.FromKey where import Common.Annex @@ -33,16 +35,31 @@ start force (keyname:file:[]) = do "key ("++ keyname ++") is not present in backend (use --force to override this sanity check)" showStart "fromkey" file next $ perform key file +start _ [] = do + showStart "fromkey" "stdin" + next massAdd start _ _ = error "specify a key and a dest file" +massAdd :: CommandPerform +massAdd = go True =<< map words . lines <$> liftIO getContents + where + go status [] = next $ return status + go status ([keyname,f]:rest) = do + let key = fromMaybe (error $ "bad key " ++ keyname) $ file2key keyname + ok <- perform' key f + let !status' = status && ok + go status' rest + go status (_:rest) = error "Expected pairs of key and file on stdin, but got something else." + perform :: Key -> FilePath -> CommandPerform perform key file = do + ok <- perform' key file + 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 - next $ cleanup file - -cleanup :: FilePath -> CommandCleanup -cleanup file = do Annex.Queue.addCommand "add" [Param "--"] [file] return True |