sim: implement addtree
This commit is contained in:
		
					parent
					
						
							
								29d8429779
							
						
					
				
			
			
				commit
				
					
						f061ae92fb
					
				
			
		
					 3 changed files with 41 additions and 8 deletions
				
			
		
							
								
								
									
										41
									
								
								Annex/Sim.hs
									
										
									
									
									
								
							
							
						
						
									
										41
									
								
								Annex/Sim.hs
									
										
									
									
									
								
							|  | @ -17,6 +17,7 @@ import Types.StandardGroups | |||
| import Types.TrustLevel | ||||
| import Types.Difference | ||||
| import Git | ||||
| import Git.FilePath | ||||
| import Backend.Hash (genTestKey) | ||||
| import Annex.UUID | ||||
| import Annex.FileMatcher | ||||
|  | @ -24,6 +25,7 @@ import Annex.Init | |||
| import Annex.Startup | ||||
| import Annex.Link | ||||
| import Annex.Wanted | ||||
| import Annex.CatFile | ||||
| import Logs.Group | ||||
| import Logs.Trust | ||||
| import Logs.PreferredContent | ||||
|  | @ -36,6 +38,7 @@ import Logs.Location | |||
| import qualified Annex | ||||
| import qualified Remote | ||||
| import qualified Git.Construct | ||||
| import qualified Git.LsFiles | ||||
| import qualified Annex.Queue | ||||
| 
 | ||||
| import System.Random | ||||
|  | @ -311,9 +314,39 @@ applySimCommand' (CommandDisconnect connections) st repobyname = | |||
| 			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 | ||||
|  | @ -990,6 +1023,8 @@ updateSimRepoState newst sr = do | |||
| 	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 $ | ||||
|  |  | |||
|  | @ -137,12 +137,12 @@ as passed to "git annex sim" while a simulation is running. | |||
|   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, | ||||
|  |  | |||
|  | @ -30,8 +30,6 @@ Planned schedule of work: | |||
| 
 | ||||
| * Currently working in [[todo/proving_preferred_content_behavior]] | ||||
| 
 | ||||
| * sim: implement addtree | ||||
| 
 | ||||
| * sim: May need to use LiveUpdate to make size balanced preferred content | ||||
|   work | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Joey Hess
				Joey Hess