import Types.TrustLevel
import Types.Difference
import Git
+import Git.FilePath
import Backend.Hash (genTestKey)
import Annex.UUID
import Annex.FileMatcher
import Annex.Startup
import Annex.Link
import Annex.Wanted
+import Annex.CatFile
import Logs.Group
import Logs.Trust
import Logs.PreferredContent
import qualified Annex
import qualified Remote
import qualified Git.Construct
+import qualified Git.LsFiles
import qualified Annex.Queue
import System.Random
Just connections' ->
applySimCommand' (CommandDisconnect connections') st' repobyname
applySimCommand' (CommandAddTree repo expr) st _ =
- checkKnownRepo repo st $ const $
- checkValidPreferredContentExpression expr $ Left $
- error "TODO" -- XXX
+ checkKnownRepo repo st $ \u ->
+ checkValidPreferredContentExpression expr $ Left $ do
+ matcher <- makematcher u
+ (l, cleanup) <- inRepo $ Git.LsFiles.inRepo [] []
+ st' <- go matcher u st l
+ liftIO $ void cleanup
+ return st'
+ where
+ go _ _ st' [] = return st'
+ go matcher u st' (f:fs) = catKeyFile f >>= \case
+ Just k -> do
+ afile <- AssociatedFile . Just . getTopFilePath
+ <$> inRepo (toTopFilePath f)
+ ifM (checkMatcher matcher (Just k) afile NoLiveUpdate mempty (pure False) (pure False))
+ ( let st'' = setPresentKey True u k u $ st'
+ { simFiles = M.insert f k (simFiles st')
+ }
+ in go matcher u st'' fs
+ , go matcher u st' fs
+ )
+ Nothing -> go matcher u st' fs
+ makematcher :: UUID -> Annex (FileMatcher Annex)
+ makematcher u = do
+ groupmap <- groupMap
+ configmap <- remoteConfigMap
+ gm <- groupPreferredContentMapRaw
+ case makeMatcher groupmap configmap gm u id preferredContentTokens parseerr expr of
+ Right matcher -> return
+ ( matcher
+ , MatcherDesc "provided preferred content expression"
+ )
+ Left err -> giveup err
+ parseerr = Left "preferred content expression parse error"
applySimCommand' (CommandAdd file sz repos) st _ =
let (k, st') = genSimKey sz st
in go k st' repos
stageannexedfile f k = do
let f' = annexedfilepath f
l <- calcRepo $ gitAnnexLink f' k
+ liftIO $ createDirectoryIfMissing True $
+ takeDirectory $ fromRawFilePath f'
addAnnexLink l f'
unstageannexedfile f = do
liftIO $ removeWhenExistsWith R.removeLink $
quantity of files that have the particular properties you are interested
in.
+ When run in a subdirectory of the repository, only files in that
+ subdirectory are considered for addition.
+
This can be used with the same files more than once, to make multiple
repositories in the simulation contain the same files.
- Note that adding a large number of files to the simulation can slow it
- down and make it use a lot of memory.
-
* `add filename size repo [repo ...]`
Create a simulated annexed file with the specified filename and size,