summaryrefslogtreecommitdiff
path: root/Command/Clean.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-04 13:39:14 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-04 13:39:14 -0400
commite364396efca11355befa2d0f3e6eb89304c3dac7 (patch)
tree4848c55b11141525ab98e2495200fa8555abec84 /Command/Clean.hs
parent13ae7961f9ff251ac4c0d92823ebb7cf6577ce33 (diff)
basic clean filter working
Diffstat (limited to 'Command/Clean.hs')
-rw-r--r--Command/Clean.hs39
1 files changed, 36 insertions, 3 deletions
diff --git a/Command/Clean.hs b/Command/Clean.hs
index 9af862fb0..0a8e438d1 100644
--- a/Command/Clean.hs
+++ b/Command/Clean.hs
@@ -10,8 +10,12 @@ module Command.Clean where
import Common.Annex
import Command
import Annex.Content
-import Annex.Link
-import Git.Types
+import Annex.MetaData
+import Types.KeySource
+import Types.Key
+import Backend
+
+import qualified Data.ByteString.Lazy as B
cmd :: Command
cmd = dontCheck repoExists $
@@ -24,6 +28,35 @@ seek = withWords start
start :: [String] -> CommandStart
start [file] = do
- error ("clean " ++ file)
+ ifM (shouldAnnex file)
+ ( do
+ k <- ingest file
+ liftIO $ putStrLn (key2file k)
+ , liftIO $ B.hGetContents stdin >>= B.hPut stdout -- cat file
+ )
+ stop
start [] = error "clean filter run without filename; upgrade git"
start _ = error "clean filter passed multiple filenames"
+
+shouldAnnex :: FilePath -> Annex Bool
+shouldAnnex _ = return True
+-- TODO check annex.largefiles
+
+ingest :: FilePath -> Annex Key
+ingest file = do
+ backend <- chooseBackend file
+ let source = KeySource
+ { keyFilename = file
+ , contentLocation = file
+ , inodeCache = Nothing
+ }
+ k <- fst . fromMaybe (error "failed to generate a key")
+ <$> genKey source backend
+ -- Hard link (or copy) file content to annex
+ -- to prevent it from being lost when git checks out
+ -- a branch not contaning this file.
+ unlessM (linkAnnex k file) $
+ error "Problem adding file to the annex"
+ genMetaData k file
+ =<< liftIO (getFileStatus file)
+ return k