rename key2file and file2key
What these generate is not really suitable to be used as a filename, which is why keyFile and fileKey further escape it. These are just serializing Keys. Also removed a quickcheck test that was very unlikely to test anything useful, since it relied on random chance creating something that looks like a serialized key. The other test is sufficient for testing what that was intended to test anyway.
This commit is contained in:
		
					parent
					
						
							
								ff0a2bee2d
							
						
					
				
			
			
				commit
				
					
						d3ab5e626b
					
				
			
		
					 40 changed files with 97 additions and 108 deletions
				
			
		| 
						 | 
					@ -65,14 +65,14 @@ hashDirs (HashLevels 1) sz s = addTrailingPathSeparator $ take sz s
 | 
				
			||||||
hashDirs _ sz s = addTrailingPathSeparator $ take sz s </> drop sz s
 | 
					hashDirs _ sz s = addTrailingPathSeparator $ take sz s </> drop sz s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hashDirLower :: HashLevels -> Hasher
 | 
					hashDirLower :: HashLevels -> Hasher
 | 
				
			||||||
hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $ key2file' $ nonChunkKey k
 | 
					hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $ serializeKey' $ nonChunkKey k
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- This was originally using Data.Hash.MD5 from MissingH. This new version
 | 
					{- This was originally using Data.Hash.MD5 from MissingH. This new version
 | 
				
			||||||
- is faster, but ugly as it has to replicate the 4 Word32's that produced. -}
 | 
					- is faster, but ugly as it has to replicate the 4 Word32's that produced. -}
 | 
				
			||||||
hashDirMixed :: HashLevels -> Hasher
 | 
					hashDirMixed :: HashLevels -> Hasher
 | 
				
			||||||
hashDirMixed n k = hashDirs n 2 $ take 4 $ concatMap display_32bits_as_dir $
 | 
					hashDirMixed n k = hashDirs n 2 $ take 4 $ concatMap display_32bits_as_dir $
 | 
				
			||||||
	encodeWord32 $ map fromIntegral $ Data.ByteArray.unpack $
 | 
						encodeWord32 $ map fromIntegral $ Data.ByteArray.unpack $
 | 
				
			||||||
		Utility.Hash.md5 $ key2file' $ nonChunkKey k
 | 
							Utility.Hash.md5 $ serializeKey' $ nonChunkKey k
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	encodeWord32 (b1:b2:b3:b4:rest) =
 | 
						encodeWord32 (b1:b2:b3:b4:rest) =
 | 
				
			||||||
		(shiftL b4 24 .|. shiftL b3 16 .|. shiftL b2 8 .|. b1)
 | 
							(shiftL b4 24 .|. shiftL b3 16 .|. shiftL b2 8 .|. b1)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -115,7 +115,7 @@ handleDropsFrom locs rs reason fromhere key afile preverified runner = do
 | 
				
			||||||
				liftIO $ debugM "drop" $ unwords
 | 
									liftIO $ debugM "drop" $ unwords
 | 
				
			||||||
					[ "dropped"
 | 
										[ "dropped"
 | 
				
			||||||
					, case afile of
 | 
										, case afile of
 | 
				
			||||||
						AssociatedFile Nothing -> key2file key
 | 
											AssociatedFile Nothing -> serializeKey key
 | 
				
			||||||
						AssociatedFile (Just af) -> af
 | 
											AssociatedFile (Just af) -> af
 | 
				
			||||||
					, "(from " ++ maybe "here" show u ++ ")"
 | 
										, "(from " ++ maybe "here" show u ++ ")"
 | 
				
			||||||
					, "(copies now " ++ show (fromNumCopies have - 1) ++ ")"
 | 
										, "(copies now " ++ show (fromNumCopies have - 1) ++ ")"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -506,7 +506,7 @@ reSanitizeKeyName = preSanitizeKeyName' True
 | 
				
			||||||
 - can cause existing objects to get lost.
 | 
					 - can cause existing objects to get lost.
 | 
				
			||||||
 -}
 | 
					 -}
 | 
				
			||||||
keyFile :: Key -> FilePath
 | 
					keyFile :: Key -> FilePath
 | 
				
			||||||
keyFile = concatMap esc . key2file
 | 
					keyFile = concatMap esc . serializeKey
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	esc '&' = "&a"
 | 
						esc '&' = "&a"
 | 
				
			||||||
	esc '%' = "&s"
 | 
						esc '%' = "&s"
 | 
				
			||||||
| 
						 | 
					@ -517,7 +517,7 @@ keyFile = concatMap esc . key2file
 | 
				
			||||||
{- Reverses keyFile, converting a filename fragment (ie, the basename of
 | 
					{- Reverses keyFile, converting a filename fragment (ie, the basename of
 | 
				
			||||||
 - the symlink target) into a key. -}
 | 
					 - the symlink target) into a key. -}
 | 
				
			||||||
fileKey :: FilePath -> Maybe Key
 | 
					fileKey :: FilePath -> Maybe Key
 | 
				
			||||||
fileKey = file2key . unesc [] 
 | 
					fileKey = deserializeKey . unesc [] 
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	unesc r [] = reverse r
 | 
						unesc r [] = reverse r
 | 
				
			||||||
	unesc r ('%':cs) = unesc ('/':r) cs
 | 
						unesc r ('%':cs) = unesc ('/':r) cs
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,8 +34,8 @@ mkVariant file variant = takeDirectory file
 | 
				
			||||||
 -}
 | 
					 -}
 | 
				
			||||||
variantFile :: FilePath -> Key -> FilePath
 | 
					variantFile :: FilePath -> Key -> FilePath
 | 
				
			||||||
variantFile file key
 | 
					variantFile file key
 | 
				
			||||||
	| doubleconflict = mkVariant file (key2file key)
 | 
						| doubleconflict = mkVariant file (serializeKey key)
 | 
				
			||||||
	| otherwise = mkVariant file (shortHash $ key2file key)
 | 
						| otherwise = mkVariant file (shortHash $ serializeKey key)
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	doubleconflict = variantMarker `isInfixOf` file
 | 
						doubleconflict = variantMarker `isInfixOf` file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,7 +74,7 @@ expireUnused duration = do
 | 
				
			||||||
	now <- liftIO getPOSIXTime
 | 
						now <- liftIO getPOSIXTime
 | 
				
			||||||
	let oldkeys = M.keys $ M.filter (tooold now) m
 | 
						let oldkeys = M.keys $ M.filter (tooold now) m
 | 
				
			||||||
	forM_ oldkeys $ \k -> do
 | 
						forM_ oldkeys $ \k -> do
 | 
				
			||||||
		debug ["removing old unused key", key2file k]
 | 
							debug ["removing old unused key", serializeKey k]
 | 
				
			||||||
		liftAnnex $ tryNonAsync $ do
 | 
							liftAnnex $ tryNonAsync $ do
 | 
				
			||||||
			lockContentForRemoval k removeAnnex
 | 
								lockContentForRemoval k removeAnnex
 | 
				
			||||||
			logStatus k InfoMissing
 | 
								logStatus k InfoMissing
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ transfersDisplay = do
 | 
				
			||||||
	isrunning info = not $
 | 
						isrunning info = not $
 | 
				
			||||||
		transferPaused info || isNothing (startedTime info)
 | 
							transferPaused info || isNothing (startedTime info)
 | 
				
			||||||
	desc transfer info = case associatedFile info of
 | 
						desc transfer info = case associatedFile info of
 | 
				
			||||||
		AssociatedFile Nothing -> key2file $ transferKey transfer
 | 
							AssociatedFile Nothing -> serializeKey $ transferKey transfer
 | 
				
			||||||
		AssociatedFile (Just af) -> af
 | 
							AssociatedFile (Just af) -> af
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- Simplifies a list of transfers, avoiding display of redundant
 | 
					{- Simplifies a list of transfers, avoiding display of redundant
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -150,7 +150,7 @@ perform file = do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cleanup :: Key -> Bool -> CommandCleanup
 | 
					cleanup :: Key -> Bool -> CommandCleanup
 | 
				
			||||||
cleanup key hascontent = do
 | 
					cleanup key hascontent = do
 | 
				
			||||||
	maybeShowJSON $ JSONChunk [("key", key2file key)]
 | 
						maybeShowJSON $ JSONChunk [("key", serializeKey key)]
 | 
				
			||||||
	when hascontent $
 | 
						when hascontent $
 | 
				
			||||||
		logStatus key InfoPresent
 | 
							logStatus key InfoPresent
 | 
				
			||||||
	return True
 | 
						return True
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ perform key = next $ do
 | 
				
			||||||
	addLink file key Nothing
 | 
						addLink file key Nothing
 | 
				
			||||||
	return True
 | 
						return True
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	file = "unused." ++ key2file key
 | 
						file = "unused." ++ serializeKey key
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- The content is not in the annex, but in another directory, and
 | 
					{- The content is not in the annex, but in another directory, and
 | 
				
			||||||
 - it seems better to error out, rather than moving bad/tmp content into
 | 
					 - it seems better to error out, rather than moving bad/tmp content into
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -400,7 +400,7 @@ addWorkTree u url file key mtmp = case mtmp of
 | 
				
			||||||
			else void $ Command.Add.addSmall file
 | 
								else void $ Command.Add.addSmall file
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	go = do
 | 
						go = do
 | 
				
			||||||
		maybeShowJSON $ JSONChunk [("key", key2file key)]
 | 
							maybeShowJSON $ JSONChunk [("key", serializeKey key)]
 | 
				
			||||||
		setUrlPresent key url
 | 
							setUrlPresent key url
 | 
				
			||||||
		logChange key u InfoPresent
 | 
							logChange key u InfoPresent
 | 
				
			||||||
		ifM (addAnnexedFile file key mtmp)
 | 
							ifM (addAnnexedFile file key mtmp)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,6 @@ cmd = noCommit $ noMessages $ dontCheck repoExists $
 | 
				
			||||||
run :: () -> String -> Annex Bool
 | 
					run :: () -> String -> Annex Bool
 | 
				
			||||||
run _ file = genKey (KeySource file file Nothing) Nothing >>= \case
 | 
					run _ file = genKey (KeySource file file Nothing) Nothing >>= \case
 | 
				
			||||||
	Just (k, _) -> do
 | 
						Just (k, _) -> do
 | 
				
			||||||
		liftIO $ putStrLn $ key2file k
 | 
							liftIO $ putStrLn $ serializeKey k
 | 
				
			||||||
		return True
 | 
							return True
 | 
				
			||||||
	Nothing -> return False
 | 
						Nothing -> return False
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,7 @@ seek (DeadKeys ks) = commandActions $ map startKey ks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
startKey :: Key -> CommandStart
 | 
					startKey :: Key -> CommandStart
 | 
				
			||||||
startKey key = do
 | 
					startKey key = do
 | 
				
			||||||
	showStart' "dead" (Just $ key2file key)
 | 
						showStart' "dead" (Just $ serializeKey key)
 | 
				
			||||||
	keyLocations key >>= \case
 | 
						keyLocations key >>= \case
 | 
				
			||||||
		[] -> next $ performKey key
 | 
							[] -> next $ performKey key
 | 
				
			||||||
		_ -> giveup "This key is still known to be present in some locations; not marking as dead."
 | 
							_ -> giveup "This key is still known to be present in some locations; not marking as dead."
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,6 @@ cmd = noCommit $ noMessages $ dontCheck repoExists $
 | 
				
			||||||
 | 
					
 | 
				
			||||||
run :: Maybe Utility.Format.Format -> String -> Annex Bool
 | 
					run :: Maybe Utility.Format.Format -> String -> Annex Bool
 | 
				
			||||||
run format p = do
 | 
					run format p = do
 | 
				
			||||||
	let k = fromMaybe (giveup "bad key") $ file2key p
 | 
						let k = fromMaybe (giveup "bad key") $ deserializeKey p
 | 
				
			||||||
	showFormatted format (key2file k) (keyVars k)
 | 
						showFormatted format (serializeKey k) (keyVars k)
 | 
				
			||||||
	return True
 | 
						return True
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ optParser _ = ExportOptions
 | 
				
			||||||
-- to a stable temporary name based on the key.
 | 
					-- to a stable temporary name based on the key.
 | 
				
			||||||
exportTempName :: ExportKey -> ExportLocation
 | 
					exportTempName :: ExportKey -> ExportLocation
 | 
				
			||||||
exportTempName ek = mkExportLocation $ 
 | 
					exportTempName ek = mkExportLocation $ 
 | 
				
			||||||
	".git-annex-tmp-content-" ++ key2file (asKey (ek))
 | 
						".git-annex-tmp-content-" ++ serializeKey (asKey (ek))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
seek :: ExportOptions -> CommandSeek
 | 
					seek :: ExportOptions -> CommandSeek
 | 
				
			||||||
seek o = do
 | 
					seek o = do
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,7 +88,7 @@ showFormatted format unformatted vars =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
keyVars :: Key -> [(String, String)]
 | 
					keyVars :: Key -> [(String, String)]
 | 
				
			||||||
keyVars key =
 | 
					keyVars key =
 | 
				
			||||||
	[ ("key", key2file key)
 | 
						[ ("key", serializeKey key)
 | 
				
			||||||
	, ("backend", decodeBS $ formatKeyVariety $ keyVariety key)
 | 
						, ("backend", decodeBS $ formatKeyVariety $ keyVariety key)
 | 
				
			||||||
	, ("bytesize", size show)
 | 
						, ("bytesize", size show)
 | 
				
			||||||
	, ("humansize", size $ roughSize storageUnits True)
 | 
						, ("humansize", size $ roughSize storageUnits True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -498,7 +498,7 @@ checkBackendOr' bad backend key file ai postcheck =
 | 
				
			||||||
checkKeyNumCopies :: Key -> AssociatedFile -> NumCopies -> Annex Bool
 | 
					checkKeyNumCopies :: Key -> AssociatedFile -> NumCopies -> Annex Bool
 | 
				
			||||||
checkKeyNumCopies key afile numcopies = do
 | 
					checkKeyNumCopies key afile numcopies = do
 | 
				
			||||||
	let (desc, hasafile) = case afile of
 | 
						let (desc, hasafile) = case afile of
 | 
				
			||||||
		AssociatedFile Nothing -> (key2file key, False)
 | 
							AssociatedFile Nothing -> (serializeKey key, False)
 | 
				
			||||||
		AssociatedFile (Just af) -> (af, True)
 | 
							AssociatedFile (Just af) -> (af, True)
 | 
				
			||||||
	locs <- loggedLocations key
 | 
						locs <- loggedLocations key
 | 
				
			||||||
	(untrustedlocations, otherlocations) <- trustPartition UnTrusted locs
 | 
						(untrustedlocations, otherlocations) <- trustPartition UnTrusted locs
 | 
				
			||||||
| 
						 | 
					@ -562,7 +562,7 @@ badContentDirect file key = do
 | 
				
			||||||
badContentRemote :: Remote -> FilePath -> Key -> Annex String
 | 
					badContentRemote :: Remote -> FilePath -> Key -> Annex String
 | 
				
			||||||
badContentRemote remote localcopy key = do
 | 
					badContentRemote remote localcopy key = do
 | 
				
			||||||
	bad <- fromRepo gitAnnexBadDir
 | 
						bad <- fromRepo gitAnnexBadDir
 | 
				
			||||||
	let destbad = bad </> key2file key
 | 
						let destbad = bad </> serializeKey key
 | 
				
			||||||
	movedbad <- ifM (inAnnex key <||> liftIO (doesFileExist destbad))
 | 
						movedbad <- ifM (inAnnex key <||> liftIO (doesFileExist destbad))
 | 
				
			||||||
		( return False
 | 
							( return False
 | 
				
			||||||
		, do
 | 
							, do
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -86,7 +86,7 @@ start largematcher mode (srcfile, destfile) =
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	deletedup k = do
 | 
						deletedup k = do
 | 
				
			||||||
		showNote $ "duplicate of " ++ key2file k
 | 
							showNote $ "duplicate of " ++ serializeKey k
 | 
				
			||||||
		verifyExisting k destfile
 | 
							verifyExisting k destfile
 | 
				
			||||||
			( do
 | 
								( do
 | 
				
			||||||
				liftIO $ removeFile srcfile
 | 
									liftIO $ removeFile srcfile
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -410,7 +410,7 @@ key_size :: Key -> Stat
 | 
				
			||||||
key_size k = simpleStat "size" $ showSizeKeys $ foldKeys [k]
 | 
					key_size k = simpleStat "size" $ showSizeKeys $ foldKeys [k]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
key_name :: Key -> Stat
 | 
					key_name :: Key -> Stat
 | 
				
			||||||
key_name k = simpleStat "key" $ pure $ key2file k
 | 
					key_name k = simpleStat "key" $ pure $ serializeKey k
 | 
				
			||||||
 | 
					
 | 
				
			||||||
content_present :: Key -> Stat
 | 
					content_present :: Key -> Stat
 | 
				
			||||||
content_present k = stat "present" $ json boolConfig $ lift $ inAnnex k
 | 
					content_present k = stat "present" $ json boolConfig $ lift $ inAnnex k
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -144,7 +144,7 @@ showLogIncremental outputter ps = do
 | 
				
			||||||
 - as showLogIncremental. -}
 | 
					 - as showLogIncremental. -}
 | 
				
			||||||
showLog :: (String -> Outputter) -> [RefChange] -> Annex ()
 | 
					showLog :: (String -> Outputter) -> [RefChange] -> Annex ()
 | 
				
			||||||
showLog outputter cs = forM_ cs $ \c -> do
 | 
					showLog outputter cs = forM_ cs $ \c -> do
 | 
				
			||||||
	let keyname = key2file (changekey c)
 | 
						let keyname = serializeKey (changekey c)
 | 
				
			||||||
	new <- S.fromList <$> loggedLocationsRef (newref c)
 | 
						new <- S.fromList <$> loggedLocationsRef (newref c)
 | 
				
			||||||
	old <- S.fromList <$> loggedLocationsRef (oldref c)
 | 
						old <- S.fromList <$> loggedLocationsRef (oldref c)
 | 
				
			||||||
	sequence_ $ compareChanges (outputter keyname)
 | 
						sequence_ $ compareChanges (outputter keyname)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,7 @@ run _ file = seekSingleGitFile file >>= \case
 | 
				
			||||||
	Nothing -> return False
 | 
						Nothing -> return False
 | 
				
			||||||
	Just file' -> catKeyFile file' >>= \case
 | 
						Just file' -> catKeyFile file' >>= \case
 | 
				
			||||||
		Just k  -> do
 | 
							Just k  -> do
 | 
				
			||||||
			liftIO $ putStrLn $ key2file k
 | 
								liftIO $ putStrLn $ serializeKey k
 | 
				
			||||||
			return True
 | 
								return True
 | 
				
			||||||
		Nothing -> return False
 | 
							Nothing -> return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -178,7 +178,7 @@ test st r k =
 | 
				
			||||||
		Nothing -> return True
 | 
							Nothing -> return True
 | 
				
			||||||
		Just b -> case Backend.verifyKeyContent b of
 | 
							Just b -> case Backend.verifyKeyContent b of
 | 
				
			||||||
			Nothing -> return True
 | 
								Nothing -> return True
 | 
				
			||||||
			Just verifier -> verifier k (key2file k)
 | 
								Just verifier -> verifier k (serializeKey k)
 | 
				
			||||||
	get = getViaTmp (Remote.retrievalSecurityPolicy r) (RemoteVerify r) k $ \dest ->
 | 
						get = getViaTmp (Remote.retrievalSecurityPolicy r) (RemoteVerify r) k $ \dest ->
 | 
				
			||||||
		Remote.retrieveKeyFile r k (AssociatedFile Nothing)
 | 
							Remote.retrieveKeyFile r k (AssociatedFile Nothing)
 | 
				
			||||||
			dest nullMeterUpdate
 | 
								dest nullMeterUpdate
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,5 +126,5 @@ instance TCSerialized RemoteName where
 | 
				
			||||||
	deserialize n = Just n
 | 
						deserialize n = Just n
 | 
				
			||||||
 | 
					
 | 
				
			||||||
instance TCSerialized Key where
 | 
					instance TCSerialized Key where
 | 
				
			||||||
	serialize = key2file
 | 
						serialize = serializeKey
 | 
				
			||||||
	deserialize = file2key
 | 
						deserialize = deserializeKey
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -118,7 +118,7 @@ number n (x:xs) = (n+1, x) : number (n+1) xs
 | 
				
			||||||
table :: [(Int, Key)] -> [String]
 | 
					table :: [(Int, Key)] -> [String]
 | 
				
			||||||
table l = "  NUMBER  KEY" : map cols l
 | 
					table l = "  NUMBER  KEY" : map cols l
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	cols (n,k) = "  " ++ pad 6 (show n) ++ "  " ++ key2file k
 | 
						cols (n,k) = "  " ++ pad 6 (show n) ++ "  " ++ serializeKey k
 | 
				
			||||||
	pad n s = s ++ replicate (n - length s) ' '
 | 
						pad n s = s ++ replicate (n - length s) ' '
 | 
				
			||||||
 | 
					
 | 
				
			||||||
staleTmpMsg :: [(Int, Key)] -> String
 | 
					staleTmpMsg :: [(Int, Key)] -> String
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -161,7 +161,7 @@ type EncKey = Key -> Key
 | 
				
			||||||
 - on content. It does need to be repeatable. -}
 | 
					 - on content. It does need to be repeatable. -}
 | 
				
			||||||
encryptKey :: Mac -> Cipher -> EncKey
 | 
					encryptKey :: Mac -> Cipher -> EncKey
 | 
				
			||||||
encryptKey mac c k = stubKey
 | 
					encryptKey mac c k = stubKey
 | 
				
			||||||
	{ keyName = encodeBS (macWithCipher mac c (key2file k))
 | 
						{ keyName = encodeBS (macWithCipher mac c (serializeKey k))
 | 
				
			||||||
	, keyVariety = OtherKey $
 | 
						, keyVariety = OtherKey $
 | 
				
			||||||
		encryptedBackendNamePrefix <> encodeBS (showMac mac)
 | 
							encryptedBackendNamePrefix <> encodeBS (showMac mac)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,10 +23,10 @@ newtype SKey = SKey String
 | 
				
			||||||
	deriving (Show, Read)
 | 
						deriving (Show, Read)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
toSKey :: Key -> SKey
 | 
					toSKey :: Key -> SKey
 | 
				
			||||||
toSKey = SKey . key2file
 | 
					toSKey = SKey . serializeKey
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fromSKey :: SKey -> Key
 | 
					fromSKey :: SKey -> Key
 | 
				
			||||||
fromSKey (SKey s) = fromMaybe (error $ "bad serialized Key " ++ s) (file2key s)
 | 
					fromSKey (SKey s) = fromMaybe (error $ "bad serialized Key " ++ s) (deserializeKey s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
derivePersistField "SKey"
 | 
					derivePersistField "SKey"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,10 +41,10 @@ instance Show IKey where
 | 
				
			||||||
	show (IKey s) = s
 | 
						show (IKey s) = s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
toIKey :: Key -> IKey
 | 
					toIKey :: Key -> IKey
 | 
				
			||||||
toIKey = IKey . key2file
 | 
					toIKey = IKey . serializeKey
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fromIKey :: IKey -> Key
 | 
					fromIKey :: IKey -> Key
 | 
				
			||||||
fromIKey (IKey s) = fromMaybe (error $ "bad serialized Key " ++ s) (file2key s)
 | 
					fromIKey (IKey s) = fromMaybe (error $ "bad serialized Key " ++ s) (deserializeKey s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
derivePersistField "IKey"
 | 
					derivePersistField "IKey"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										72
									
								
								Key.hs
									
										
									
									
									
								
							
							
						
						
									
										72
									
								
								Key.hs
									
										
									
									
									
								
							| 
						 | 
					@ -11,20 +11,19 @@ module Key (
 | 
				
			||||||
	Key(..),
 | 
						Key(..),
 | 
				
			||||||
	AssociatedFile(..),
 | 
						AssociatedFile(..),
 | 
				
			||||||
	stubKey,
 | 
						stubKey,
 | 
				
			||||||
	buildKeyFile,
 | 
						buildKey,
 | 
				
			||||||
	keyFileParser,
 | 
						keyParser,
 | 
				
			||||||
	file2key,
 | 
						serializeKey,
 | 
				
			||||||
	key2file,
 | 
						serializeKey,
 | 
				
			||||||
	file2key',
 | 
						deserializeKey',
 | 
				
			||||||
	key2file',
 | 
						deserializeKey',
 | 
				
			||||||
	nonChunkKey,
 | 
						nonChunkKey,
 | 
				
			||||||
	chunkKeyOffset,
 | 
						chunkKeyOffset,
 | 
				
			||||||
	isChunkKey,
 | 
						isChunkKey,
 | 
				
			||||||
	isKeyPrefix,
 | 
						isKeyPrefix,
 | 
				
			||||||
	splitKeyNameExtension,
 | 
						splitKeyNameExtension,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	prop_isomorphic_key_encode,
 | 
						prop_isomorphic_key_encode
 | 
				
			||||||
	prop_isomorphic_key_decode
 | 
					 | 
				
			||||||
) where
 | 
					) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import qualified Data.Text as T
 | 
					import qualified Data.Text as T
 | 
				
			||||||
| 
						 | 
					@ -77,11 +76,13 @@ isKeyPrefix s = [fieldSep, fieldSep] `isInfixOf` s
 | 
				
			||||||
fieldSep :: Char
 | 
					fieldSep :: Char
 | 
				
			||||||
fieldSep = '-'
 | 
					fieldSep = '-'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- Builds a ByteString that is suitable for use as a filename representing
 | 
					{- Builds a ByteString from a Key.
 | 
				
			||||||
 - a Key. The name field is always shown last, separated by doubled fieldSeps,
 | 
					 -
 | 
				
			||||||
 - and is the only field allowed to contain the fieldSep. -}
 | 
					 - The name field is always shown last, separated by doubled fieldSeps,
 | 
				
			||||||
buildKeyFile :: Key -> Builder
 | 
					 - and is the only field allowed to contain the fieldSep.
 | 
				
			||||||
buildKeyFile k = byteString (formatKeyVariety (keyVariety k))
 | 
					 -}
 | 
				
			||||||
 | 
					buildKey :: Key -> Builder
 | 
				
			||||||
 | 
					buildKey k = byteString (formatKeyVariety (keyVariety k))
 | 
				
			||||||
	<> 's' ?: (integerDec <$> keySize k)
 | 
						<> 's' ?: (integerDec <$> keySize k)
 | 
				
			||||||
	<> 'm' ?: (integerDec . (\(CTime t) -> fromIntegral t) <$> keyMtime k)
 | 
						<> 'm' ?: (integerDec . (\(CTime t) -> fromIntegral t) <$> keyMtime k)
 | 
				
			||||||
	<> 'S' ?: (integerDec <$> keyChunkSize k)
 | 
						<> 'S' ?: (integerDec <$> keyChunkSize k)
 | 
				
			||||||
| 
						 | 
					@ -92,11 +93,11 @@ buildKeyFile k = byteString (formatKeyVariety (keyVariety k))
 | 
				
			||||||
	c ?: (Just b) = sepbefore (char7 c <> b)
 | 
						c ?: (Just b) = sepbefore (char7 c <> b)
 | 
				
			||||||
	_ ?: Nothing = mempty
 | 
						_ ?: Nothing = mempty
 | 
				
			||||||
 | 
					
 | 
				
			||||||
key2file :: Key -> FilePath
 | 
					serializeKey :: Key -> String
 | 
				
			||||||
key2file = decodeBL' . key2file'
 | 
					serializeKey = decodeBL' . serializeKey'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
key2file' :: Key -> L.ByteString
 | 
					serializeKey' :: Key -> L.ByteString
 | 
				
			||||||
key2file' = toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty . buildKeyFile
 | 
					serializeKey' = toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty . buildKey
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- This is a strict parser for security reasons; a key
 | 
					{- This is a strict parser for security reasons; a key
 | 
				
			||||||
 - can contain only 4 fields, which all consist only of numbers.
 | 
					 - can contain only 4 fields, which all consist only of numbers.
 | 
				
			||||||
| 
						 | 
					@ -107,8 +108,8 @@ key2file' = toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty . bui
 | 
				
			||||||
 - embed data used in a SHA1 collision attack, which would be a
 | 
					 - embed data used in a SHA1 collision attack, which would be a
 | 
				
			||||||
 - problem since the keys are committed to git.
 | 
					 - problem since the keys are committed to git.
 | 
				
			||||||
 -}
 | 
					 -}
 | 
				
			||||||
keyFileParser :: A.Parser Key
 | 
					keyParser :: A.Parser Key
 | 
				
			||||||
keyFileParser = do
 | 
					keyParser = do
 | 
				
			||||||
	-- key variety cannot be empty
 | 
						-- key variety cannot be empty
 | 
				
			||||||
	v <- (parseKeyVariety <$> A8.takeWhile1 (/= fieldSep))
 | 
						v <- (parseKeyVariety <$> A8.takeWhile1 (/= fieldSep))
 | 
				
			||||||
	s <- parsesize
 | 
						s <- parsesize
 | 
				
			||||||
| 
						 | 
					@ -135,11 +136,11 @@ keyFileParser = do
 | 
				
			||||||
	parsechunksize = parseopt $ A8.char 'S' *> A8.decimal
 | 
						parsechunksize = parseopt $ A8.char 'S' *> A8.decimal
 | 
				
			||||||
	parsechunknum = parseopt $ A8.char 'C' *> A8.decimal
 | 
						parsechunknum = parseopt $ A8.char 'C' *> A8.decimal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
file2key :: FilePath -> Maybe Key
 | 
					deserializeKey :: String -> Maybe Key
 | 
				
			||||||
file2key = file2key' . encodeBS'
 | 
					deserializeKey = deserializeKey' . encodeBS'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
file2key' :: S.ByteString -> Maybe Key
 | 
					deserializeKey' :: S.ByteString -> Maybe Key
 | 
				
			||||||
file2key' b = eitherToMaybe $ A.parseOnly keyFileParser b
 | 
					deserializeKey' b = eitherToMaybe $ A.parseOnly keyParser b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- This splits any extension out of the keyName, returning the 
 | 
					{- This splits any extension out of the keyName, returning the 
 | 
				
			||||||
 - keyName minus extension, and the extension (including leading dot).
 | 
					 - keyName minus extension, and the extension (including leading dot).
 | 
				
			||||||
| 
						 | 
					@ -178,30 +179,19 @@ instance Arbitrary Key where
 | 
				
			||||||
		<*> ((succ . abs <$>) <$> arbitrary) -- chunknum cannot be 0 or negative
 | 
							<*> ((succ . abs <$>) <$> arbitrary) -- chunknum cannot be 0 or negative
 | 
				
			||||||
 | 
					
 | 
				
			||||||
instance Hashable Key where
 | 
					instance Hashable Key where
 | 
				
			||||||
	hashIO32 = hashIO32 . key2file'
 | 
						hashIO32 = hashIO32 . deserializeKey'
 | 
				
			||||||
	hashIO64 = hashIO64 . key2file'
 | 
						hashIO64 = hashIO64 . deserializeKey'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
instance ToJSON' Key where
 | 
					instance ToJSON' Key where
 | 
				
			||||||
	toJSON' = toJSON' . key2file
 | 
						toJSON' = toJSON' . serializeKey
 | 
				
			||||||
 | 
					
 | 
				
			||||||
instance FromJSON Key where
 | 
					instance FromJSON Key where
 | 
				
			||||||
	parseJSON (String t) = maybe mempty pure $ file2key $ T.unpack t
 | 
						parseJSON (String t) = maybe mempty pure $ deserializeKey $ T.unpack t
 | 
				
			||||||
	parseJSON _ = mempty
 | 
						parseJSON _ = mempty
 | 
				
			||||||
 | 
					
 | 
				
			||||||
instance Proto.Serializable Key where
 | 
					instance Proto.Serializable Key where
 | 
				
			||||||
	serialize = key2file
 | 
						serialize = serializeKey
 | 
				
			||||||
	deserialize = file2key
 | 
						deserialize = deserializeKey
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prop_isomorphic_key_encode :: Key -> Bool
 | 
					prop_isomorphic_key_encode :: Key -> Bool
 | 
				
			||||||
prop_isomorphic_key_encode k = Just k == (file2key . key2file) k
 | 
					prop_isomorphic_key_encode k = Just k == (deserializeKey . serializeKey) k
 | 
				
			||||||
 | 
					 | 
				
			||||||
prop_isomorphic_key_decode :: FilePath -> Bool
 | 
					 | 
				
			||||||
prop_isomorphic_key_decode f
 | 
					 | 
				
			||||||
	| normalfieldorder = maybe True (\k -> key2file k == f) (file2key f)
 | 
					 | 
				
			||||||
	| otherwise = True
 | 
					 | 
				
			||||||
  where
 | 
					 | 
				
			||||||
	-- file2key will accept the fields in any order, so don't
 | 
					 | 
				
			||||||
	-- try the test unless the fields are in the normal order
 | 
					 | 
				
			||||||
	normalfieldorder = fields `isPrefixOf` "smSC"
 | 
					 | 
				
			||||||
	fields = map (f !!) $ filter (< length f) $ map succ $
 | 
					 | 
				
			||||||
		elemIndices fieldSep f
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								Logs.hs
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Logs.hs
									
										
									
									
									
								
							| 
						 | 
					@ -124,7 +124,7 @@ urlLogFile config key = branchHashDir config key </> keyFile key ++ urlLogExt
 | 
				
			||||||
{- Old versions stored the urls elsewhere. -}
 | 
					{- Old versions stored the urls elsewhere. -}
 | 
				
			||||||
oldurlLogs :: GitConfig -> Key -> [FilePath]
 | 
					oldurlLogs :: GitConfig -> Key -> [FilePath]
 | 
				
			||||||
oldurlLogs config key =
 | 
					oldurlLogs config key =
 | 
				
			||||||
	[ "remote/web" </> hdir </> key2file key ++ ".log"
 | 
						[ "remote/web" </> hdir </> serializeKey key ++ ".log"
 | 
				
			||||||
	, "remote/web" </> hdir </> keyFile key ++ ".log"
 | 
						, "remote/web" </> hdir </> keyFile key ++ ".log"
 | 
				
			||||||
	]
 | 
						]
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@ smudgeLog :: Key -> TopFilePath -> Annex ()
 | 
				
			||||||
smudgeLog k f = do
 | 
					smudgeLog k f = do
 | 
				
			||||||
	logf <- fromRepo gitAnnexSmudgeLog
 | 
						logf <- fromRepo gitAnnexSmudgeLog
 | 
				
			||||||
	appendLogFile logf gitAnnexSmudgeLock $ 
 | 
						appendLogFile logf gitAnnexSmudgeLock $ 
 | 
				
			||||||
		key2file k ++ " " ++ getTopFilePath f
 | 
							serializeKey k ++ " " ++ getTopFilePath f
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Streams all smudged files, and then empties the log at the end.
 | 
					-- | Streams all smudged files, and then empties the log at the end.
 | 
				
			||||||
--
 | 
					--
 | 
				
			||||||
| 
						 | 
					@ -36,5 +36,5 @@ streamSmudged a = do
 | 
				
			||||||
	parse l = 
 | 
						parse l = 
 | 
				
			||||||
		let (ks, f) = separate (== ' ') l
 | 
							let (ks, f) = separate (== ' ') l
 | 
				
			||||||
		in do
 | 
							in do
 | 
				
			||||||
			k <- file2key ks
 | 
								k <- deserializeKey ks
 | 
				
			||||||
			return (k, asTopFilePath f)
 | 
								return (k, asTopFilePath f)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,8 +66,8 @@ writeUnusedLog prefix l = do
 | 
				
			||||||
	logfile <- fromRepo $ gitAnnexUnusedLog prefix
 | 
						logfile <- fromRepo $ gitAnnexUnusedLog prefix
 | 
				
			||||||
	writeLogFile logfile $ unlines $ map format $ M.toList l
 | 
						writeLogFile logfile $ unlines $ map format $ M.toList l
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	format (k, (i, Just t)) = show i ++ " " ++ key2file k ++ " " ++ show t
 | 
						format (k, (i, Just t)) = show i ++ " " ++ serializeKey k ++ " " ++ show t
 | 
				
			||||||
	format (k, (i, Nothing)) = show i ++ " " ++ key2file k
 | 
						format (k, (i, Nothing)) = show i ++ " " ++ serializeKey k
 | 
				
			||||||
 | 
					
 | 
				
			||||||
readUnusedLog :: FilePath -> Annex UnusedLog
 | 
					readUnusedLog :: FilePath -> Annex UnusedLog
 | 
				
			||||||
readUnusedLog prefix = do
 | 
					readUnusedLog prefix = do
 | 
				
			||||||
| 
						 | 
					@ -78,7 +78,7 @@ readUnusedLog prefix = do
 | 
				
			||||||
		, return M.empty
 | 
							, return M.empty
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	parse line = case (readish sint, file2key skey, parsePOSIXTime ts) of
 | 
						parse line = case (readish sint, deserializeKey skey, parsePOSIXTime ts) of
 | 
				
			||||||
		(Just int, Just key, mtimestamp) -> Just (key, (int, mtimestamp))
 | 
							(Just int, Just key, mtimestamp) -> Just (key, (int, mtimestamp))
 | 
				
			||||||
		_ -> Nothing
 | 
							_ -> Nothing
 | 
				
			||||||
	  where
 | 
						  where
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -186,7 +186,7 @@ checkKey' r serial aloc = do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
androidLocation :: AndroidPath -> Key -> AndroidPath
 | 
					androidLocation :: AndroidPath -> Key -> AndroidPath
 | 
				
			||||||
androidLocation adir k = AndroidPath $
 | 
					androidLocation adir k = AndroidPath $
 | 
				
			||||||
	fromAndroidPath (androidHashDir adir k) ++ key2file k
 | 
						fromAndroidPath (androidHashDir adir k) ++ serializeKey k
 | 
				
			||||||
 | 
					
 | 
				
			||||||
androidHashDir :: AndroidPath -> Key -> AndroidPath
 | 
					androidHashDir :: AndroidPath -> Key -> AndroidPath
 | 
				
			||||||
androidHashDir adir k = AndroidPath $ 
 | 
					androidHashDir adir k = AndroidPath $ 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -280,7 +280,7 @@ bupRef k
 | 
				
			||||||
	| Git.Ref.legal True shown = shown
 | 
						| Git.Ref.legal True shown = shown
 | 
				
			||||||
	| otherwise = "git-annex-" ++ show (sha2_256 (fromString shown))
 | 
						| otherwise = "git-annex-" ++ show (sha2_256 (fromString shown))
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	shown = key2file k
 | 
						shown = serializeKey k
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bupLocal :: BupRepo -> Bool
 | 
					bupLocal :: BupRepo -> Bool
 | 
				
			||||||
bupLocal = notElem ':'
 | 
					bupLocal = notElem ':'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,7 +110,7 @@ store ddarrepo = fileStorer $ \k src _p -> do
 | 
				
			||||||
	let params =
 | 
						let params =
 | 
				
			||||||
		[ Param "c"
 | 
							[ Param "c"
 | 
				
			||||||
		, Param "-N"
 | 
							, Param "-N"
 | 
				
			||||||
		, Param $ key2file k
 | 
							, Param $ serializeKey k
 | 
				
			||||||
		, Param $ ddarRepoLocation ddarrepo
 | 
							, Param $ ddarRepoLocation ddarrepo
 | 
				
			||||||
		, File src
 | 
							, File src
 | 
				
			||||||
		]
 | 
							]
 | 
				
			||||||
| 
						 | 
					@ -138,7 +138,7 @@ ddarRemoteCall cs ddarrepo cmd params
 | 
				
			||||||
{- Specialized ddarRemoteCall that includes extraction command and flags -}
 | 
					{- Specialized ddarRemoteCall that includes extraction command and flags -}
 | 
				
			||||||
ddarExtractRemoteCall :: ConsumeStdin -> DdarRepo -> Key -> Annex (String, [CommandParam])
 | 
					ddarExtractRemoteCall :: ConsumeStdin -> DdarRepo -> Key -> Annex (String, [CommandParam])
 | 
				
			||||||
ddarExtractRemoteCall cs ddarrepo k =
 | 
					ddarExtractRemoteCall cs ddarrepo k =
 | 
				
			||||||
	ddarRemoteCall cs ddarrepo 'x' [Param "--force-stdout", Param $ key2file k]
 | 
						ddarRemoteCall cs ddarrepo 'x' [Param "--force-stdout", Param $ serializeKey k]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
retrieve :: DdarRepo -> Retriever
 | 
					retrieve :: DdarRepo -> Retriever
 | 
				
			||||||
retrieve ddarrepo = byteRetriever $ \k sink -> do
 | 
					retrieve ddarrepo = byteRetriever $ \k sink -> do
 | 
				
			||||||
| 
						 | 
					@ -154,7 +154,7 @@ retrieveCheap _ _ _ = return False
 | 
				
			||||||
remove :: DdarRepo -> Remover
 | 
					remove :: DdarRepo -> Remover
 | 
				
			||||||
remove ddarrepo key = do
 | 
					remove ddarrepo key = do
 | 
				
			||||||
	(cmd, params) <- ddarRemoteCall NoConsumeStdin ddarrepo 'd'
 | 
						(cmd, params) <- ddarRemoteCall NoConsumeStdin ddarrepo 'd'
 | 
				
			||||||
		[Param $ key2file key]
 | 
							[Param $ serializeKey key]
 | 
				
			||||||
	liftIO $ boolSystem cmd params
 | 
						liftIO $ boolSystem cmd params
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ddarDirectoryExists :: DdarRepo -> Annex (Either String Bool)
 | 
					ddarDirectoryExists :: DdarRepo -> Annex (Either String Bool)
 | 
				
			||||||
| 
						 | 
					@ -188,7 +188,7 @@ inDdarManifest ddarrepo k = do
 | 
				
			||||||
		contents <- hGetContents h
 | 
							contents <- hGetContents h
 | 
				
			||||||
		return $ elem k' $ lines contents
 | 
							return $ elem k' $ lines contents
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	k' = key2file k
 | 
						k' = serializeKey k
 | 
				
			||||||
 | 
					
 | 
				
			||||||
checkKey :: DdarRepo -> CheckPresent
 | 
					checkKey :: DdarRepo -> CheckPresent
 | 
				
			||||||
checkKey ddarrepo key = do
 | 
					checkKey ddarrepo key = do
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -427,7 +427,7 @@ lockKey' repo r (State connpool duc _) key callback
 | 
				
			||||||
	fallback = do
 | 
						fallback = do
 | 
				
			||||||
		Just (cmd, params) <- Ssh.git_annex_shell ConsumeStdin
 | 
							Just (cmd, params) <- Ssh.git_annex_shell ConsumeStdin
 | 
				
			||||||
			repo "lockcontent"
 | 
								repo "lockcontent"
 | 
				
			||||||
			[Param $ key2file key] []
 | 
								[Param $ serializeKey key] []
 | 
				
			||||||
		(Just hin, Just hout, Nothing, p) <- liftIO $ 
 | 
							(Just hin, Just hout, Nothing, p) <- liftIO $ 
 | 
				
			||||||
			withFile devNull WriteMode $ \nullh ->
 | 
								withFile devNull WriteMode $ \nullh ->
 | 
				
			||||||
				createProcess $
 | 
									createProcess $
 | 
				
			||||||
| 
						 | 
					@ -530,7 +530,7 @@ copyFromRemote'' repo forcersync r (State connpool _ _) key file dest meterupdat
 | 
				
			||||||
			: maybe [] (\f -> [(Fields.associatedFile, f)]) afile
 | 
								: maybe [] (\f -> [(Fields.associatedFile, f)]) afile
 | 
				
			||||||
		Just (cmd, params) <- Ssh.git_annex_shell ConsumeStdin
 | 
							Just (cmd, params) <- Ssh.git_annex_shell ConsumeStdin
 | 
				
			||||||
			repo "transferinfo" 
 | 
								repo "transferinfo" 
 | 
				
			||||||
			[Param $ key2file key] fields
 | 
								[Param $ serializeKey key] fields
 | 
				
			||||||
		v <- liftIO (newEmptySV :: IO (MSampleVar Integer))
 | 
							v <- liftIO (newEmptySV :: IO (MSampleVar Integer))
 | 
				
			||||||
		pidv <- liftIO $ newEmptyMVar
 | 
							pidv <- liftIO $ newEmptyMVar
 | 
				
			||||||
		tid <- liftIO $ forkIO $ void $ tryIO $ do
 | 
							tid <- liftIO $ forkIO $ void $ tryIO $ do
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -197,7 +197,7 @@ checkKey r k = do
 | 
				
			||||||
		{- glacier checkpresent outputs the archive name to stdout if
 | 
							{- glacier checkpresent outputs the archive name to stdout if
 | 
				
			||||||
		 - it's present. -}
 | 
							 - it's present. -}
 | 
				
			||||||
		s <- liftIO $ readProcessEnv "glacier" (toCommand params) (Just e)
 | 
							s <- liftIO $ readProcessEnv "glacier" (toCommand params) (Just e)
 | 
				
			||||||
		let probablypresent = key2file k `elem` lines s
 | 
							let probablypresent = serializeKey k `elem` lines s
 | 
				
			||||||
		if probablypresent
 | 
							if probablypresent
 | 
				
			||||||
			then ifM (Annex.getFlag "trustglacier")
 | 
								then ifM (Annex.getFlag "trustglacier")
 | 
				
			||||||
				( return True, giveup untrusted )
 | 
									( return True, giveup untrusted )
 | 
				
			||||||
| 
						 | 
					@ -253,7 +253,7 @@ getVault = fromMaybe (giveup "Missing vault configuration")
 | 
				
			||||||
	. M.lookup "vault"
 | 
						. M.lookup "vault"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
archive :: Remote -> Key -> Archive
 | 
					archive :: Remote -> Key -> Archive
 | 
				
			||||||
archive r k = fileprefix ++ key2file k
 | 
					archive r k = fileprefix ++ serializeKey k
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	fileprefix = M.findWithDefault "" "fileprefix" $ config r
 | 
						fileprefix = M.findWithDefault "" "fileprefix" $ config r
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -306,7 +306,7 @@ jobList r keys = go =<< glacierEnv (config r) (gitconfig r) (uuid r)
 | 
				
			||||||
	parse c [] = c
 | 
						parse c [] = c
 | 
				
			||||||
	parse c@(succeeded, failed) ((status:_date:vault:key:[]):rest)
 | 
						parse c@(succeeded, failed) ((status:_date:vault:key:[]):rest)
 | 
				
			||||||
		| vault == myvault =
 | 
							| vault == myvault =
 | 
				
			||||||
			case file2key key of
 | 
								case deserializeKey key of
 | 
				
			||||||
				Nothing -> parse c rest
 | 
									Nothing -> parse c rest
 | 
				
			||||||
				Just k
 | 
									Just k
 | 
				
			||||||
					| "a/d" `isPrefixOf` status ->
 | 
										| "a/d" `isPrefixOf` status ->
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -98,7 +98,7 @@ onRemote cs r (with, errorval) command params fields = do
 | 
				
			||||||
inAnnex :: Git.Repo -> Key -> Annex Bool
 | 
					inAnnex :: Git.Repo -> Key -> Annex Bool
 | 
				
			||||||
inAnnex r k = do
 | 
					inAnnex r k = do
 | 
				
			||||||
	showChecking r
 | 
						showChecking r
 | 
				
			||||||
	onRemote NoConsumeStdin r (runcheck, cantCheck r) "inannex" [Param $ key2file k] []
 | 
						onRemote NoConsumeStdin r (runcheck, cantCheck r) "inannex" [Param $ serializeKey k] []
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	runcheck c p = dispatch =<< safeSystem c p
 | 
						runcheck c p = dispatch =<< safeSystem c p
 | 
				
			||||||
	dispatch ExitSuccess = return True
 | 
						dispatch ExitSuccess = return True
 | 
				
			||||||
| 
						 | 
					@ -109,7 +109,7 @@ inAnnex r k = do
 | 
				
			||||||
dropKey :: Git.Repo -> Key -> Annex Bool
 | 
					dropKey :: Git.Repo -> Key -> Annex Bool
 | 
				
			||||||
dropKey r key = onRemote NoConsumeStdin r (boolSystem, return False) "dropkey"
 | 
					dropKey r key = onRemote NoConsumeStdin r (boolSystem, return False) "dropkey"
 | 
				
			||||||
	[ Param "--quiet", Param "--force"
 | 
						[ Param "--quiet", Param "--force"
 | 
				
			||||||
	, Param $ key2file key
 | 
						, Param $ serializeKey key
 | 
				
			||||||
	]
 | 
						]
 | 
				
			||||||
	[]
 | 
						[]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,7 +141,7 @@ rsyncParamsRemote unlocked r direction key file (AssociatedFile afile) = do
 | 
				
			||||||
	repo <- getRepo r
 | 
						repo <- getRepo r
 | 
				
			||||||
	Just (shellcmd, shellparams) <- git_annex_shell ConsumeStdin repo
 | 
						Just (shellcmd, shellparams) <- git_annex_shell ConsumeStdin repo
 | 
				
			||||||
		(if direction == Download then "sendkey" else "recvkey")
 | 
							(if direction == Download then "sendkey" else "recvkey")
 | 
				
			||||||
		[ Param $ key2file key ]
 | 
							[ Param $ serializeKey key ]
 | 
				
			||||||
		fields
 | 
							fields
 | 
				
			||||||
	-- Convert the ssh command into rsync command line.
 | 
						-- Convert the ssh command into rsync command line.
 | 
				
			||||||
	let eparam = rsyncShell (Param shellcmd:shellparams)
 | 
						let eparam = rsyncShell (Param shellcmd:shellparams)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,7 +92,7 @@ hookEnv action k f = Just <$> mergeenv (fileenv f ++ keyenv)
 | 
				
			||||||
	mergeenv l = addEntries l <$> getEnvironment
 | 
						mergeenv l = addEntries l <$> getEnvironment
 | 
				
			||||||
	envvar s v = ("ANNEX_" ++ s, v)
 | 
						envvar s v = ("ANNEX_" ++ s, v)
 | 
				
			||||||
	keyenv = catMaybes
 | 
						keyenv = catMaybes
 | 
				
			||||||
		[ Just $ envvar "KEY" (key2file k)
 | 
							[ Just $ envvar "KEY" (serializeKey k)
 | 
				
			||||||
		, Just $ envvar "ACTION" action
 | 
							, Just $ envvar "ACTION" action
 | 
				
			||||||
		, envvar "HASH_1" <$> headMaybe hashbits
 | 
							, envvar "HASH_1" <$> headMaybe hashbits
 | 
				
			||||||
		, envvar "HASH_2" <$> headMaybe (drop 1 hashbits)
 | 
							, envvar "HASH_2" <$> headMaybe (drop 1 hashbits)
 | 
				
			||||||
| 
						 | 
					@ -151,7 +151,7 @@ checkKey r h k = do
 | 
				
			||||||
	liftIO $ check v
 | 
						liftIO $ check v
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	action = "checkpresent"
 | 
						action = "checkpresent"
 | 
				
			||||||
	findkey s = key2file k `elem` lines s
 | 
						findkey s = serializeKey k `elem` lines s
 | 
				
			||||||
	check Nothing = giveup $ action ++ " hook misconfigured"
 | 
						check Nothing = giveup $ action ++ " hook misconfigured"
 | 
				
			||||||
	check (Just hook) = do
 | 
						check (Just hook) = do
 | 
				
			||||||
		environ <- hookEnv action k Nothing
 | 
							environ <- hookEnv action k Nothing
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -653,7 +653,7 @@ getFilePrefix :: RemoteConfig -> String
 | 
				
			||||||
getFilePrefix = M.findWithDefault "" "fileprefix"
 | 
					getFilePrefix = M.findWithDefault "" "fileprefix"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
getBucketObject :: RemoteConfig -> Key -> BucketObject
 | 
					getBucketObject :: RemoteConfig -> Key -> BucketObject
 | 
				
			||||||
getBucketObject c = munge . key2file
 | 
					getBucketObject c = munge . serializeKey
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	munge s = case M.lookup "mungekeys" c of
 | 
						munge s = case M.lookup "mungekeys" c of
 | 
				
			||||||
		Just "ia" -> iaMunge $ getFilePrefix c ++ s
 | 
							Just "ia" -> iaMunge $ getFilePrefix c ++ s
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										11
									
								
								Test.hs
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								Test.hs
									
										
									
									
									
								
							| 
						 | 
					@ -160,7 +160,6 @@ properties = localOption (QuickCheckTests 1000) $ testGroup "QuickCheck"
 | 
				
			||||||
	[ testProperty "prop_encode_decode_roundtrip" Git.Filename.prop_encode_decode_roundtrip
 | 
						[ testProperty "prop_encode_decode_roundtrip" Git.Filename.prop_encode_decode_roundtrip
 | 
				
			||||||
	, testProperty "prop_encode_c_decode_c_roundtrip" Utility.Format.prop_encode_c_decode_c_roundtrip
 | 
						, testProperty "prop_encode_c_decode_c_roundtrip" Utility.Format.prop_encode_c_decode_c_roundtrip
 | 
				
			||||||
	, testProperty "prop_isomorphic_key_encode" Key.prop_isomorphic_key_encode
 | 
						, testProperty "prop_isomorphic_key_encode" Key.prop_isomorphic_key_encode
 | 
				
			||||||
	, testProperty "prop_isomorphic_key_decode" Key.prop_isomorphic_key_decode
 | 
					 | 
				
			||||||
	, testProperty "prop_isomorphic_shellEscape" Utility.SafeCommand.prop_isomorphic_shellEscape
 | 
						, testProperty "prop_isomorphic_shellEscape" Utility.SafeCommand.prop_isomorphic_shellEscape
 | 
				
			||||||
	, testProperty "prop_isomorphic_shellEscape_multiword" Utility.SafeCommand.prop_isomorphic_shellEscape_multiword
 | 
						, testProperty "prop_isomorphic_shellEscape_multiword" Utility.SafeCommand.prop_isomorphic_shellEscape_multiword
 | 
				
			||||||
	, testProperty "prop_isomorphic_configEscape" Logs.Remote.prop_isomorphic_configEscape
 | 
						, testProperty "prop_isomorphic_configEscape" Logs.Remote.prop_isomorphic_configEscape
 | 
				
			||||||
| 
						 | 
					@ -397,7 +396,7 @@ test_reinject = intmpclonerepoInDirect $ do
 | 
				
			||||||
	git_annex "drop" ["--force", sha1annexedfile] @? "drop failed"
 | 
						git_annex "drop" ["--force", sha1annexedfile] @? "drop failed"
 | 
				
			||||||
	annexed_notpresent sha1annexedfile
 | 
						annexed_notpresent sha1annexedfile
 | 
				
			||||||
	writecontent tmp $ content sha1annexedfile
 | 
						writecontent tmp $ content sha1annexedfile
 | 
				
			||||||
	key <- Key.key2file <$> getKey backendSHA1 tmp
 | 
						key <- Key.serializeKey <$> getKey backendSHA1 tmp
 | 
				
			||||||
	git_annex "reinject" [tmp, sha1annexedfile] @? "reinject failed"
 | 
						git_annex "reinject" [tmp, sha1annexedfile] @? "reinject failed"
 | 
				
			||||||
	annexed_present sha1annexedfile
 | 
						annexed_present sha1annexedfile
 | 
				
			||||||
	-- fromkey can't be used on a crippled filesystem, since it makes a
 | 
						-- fromkey can't be used on a crippled filesystem, since it makes a
 | 
				
			||||||
| 
						 | 
					@ -867,9 +866,9 @@ test_unused = intmpclonerepoInDirect $ do
 | 
				
			||||||
	checkunused [annexedfilekey, sha1annexedfilekey] "after rm sha1annexedfile"
 | 
						checkunused [annexedfilekey, sha1annexedfilekey] "after rm sha1annexedfile"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	-- good opportunity to test dropkey also
 | 
						-- good opportunity to test dropkey also
 | 
				
			||||||
	git_annex "dropkey" ["--force", Key.key2file annexedfilekey]
 | 
						git_annex "dropkey" ["--force", Key.serializeKey annexedfilekey]
 | 
				
			||||||
		@? "dropkey failed"
 | 
							@? "dropkey failed"
 | 
				
			||||||
	checkunused [sha1annexedfilekey] ("after dropkey --force " ++ Key.key2file annexedfilekey)
 | 
						checkunused [sha1annexedfilekey] ("after dropkey --force " ++ Key.serializeKey annexedfilekey)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	git_annex_shouldfail "dropunused" ["1"] @? "dropunused failed to fail without --force"
 | 
						git_annex_shouldfail "dropunused" ["1"] @? "dropunused failed to fail without --force"
 | 
				
			||||||
	git_annex "dropunused" ["--force", "1"] @? "dropunused failed"
 | 
						git_annex "dropunused" ["--force", "1"] @? "dropunused failed"
 | 
				
			||||||
| 
						 | 
					@ -1682,12 +1681,12 @@ test_crypto = do
 | 
				
			||||||
			let encparams = (mempty :: Types.Remote.RemoteConfig, dummycfg)
 | 
								let encparams = (mempty :: Types.Remote.RemoteConfig, dummycfg)
 | 
				
			||||||
			cipher <- Crypto.decryptCipher gpgcmd encparams cip
 | 
								cipher <- Crypto.decryptCipher gpgcmd encparams cip
 | 
				
			||||||
			files <- filterM doesFileExist $
 | 
								files <- filterM doesFileExist $
 | 
				
			||||||
				map ("dir" </>) $ concatMap (key2files cipher) keys
 | 
									map ("dir" </>) $ concatMap (serializeKeys cipher) keys
 | 
				
			||||||
			return (not $ null files) <&&> allM (checkFile mvariant) files
 | 
								return (not $ null files) <&&> allM (checkFile mvariant) files
 | 
				
			||||||
		checkFile mvariant filename =
 | 
							checkFile mvariant filename =
 | 
				
			||||||
			Utility.Gpg.checkEncryptionFile gpgcmd filename $
 | 
								Utility.Gpg.checkEncryptionFile gpgcmd filename $
 | 
				
			||||||
				if mvariant == Just Types.Crypto.PubKey then ks else Nothing
 | 
									if mvariant == Just Types.Crypto.PubKey then ks else Nothing
 | 
				
			||||||
		key2files cipher = Annex.Locations.keyPaths .
 | 
							serializeKeys cipher = Annex.Locations.keyPaths .
 | 
				
			||||||
			Crypto.encryptKey Types.Crypto.HmacSha1 cipher
 | 
								Crypto.encryptKey Types.Crypto.HmacSha1 cipher
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
test_crypto = putStrLn "gpg testing not implemented on Windows"
 | 
					test_crypto = putStrLn "gpg testing not implemented on Windows"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -341,7 +341,7 @@ checklocationlog f expected = do
 | 
				
			||||||
	case r of
 | 
						case r of
 | 
				
			||||||
		Just k -> do
 | 
							Just k -> do
 | 
				
			||||||
			uuids <- annexeval $ Remote.keyLocations k
 | 
								uuids <- annexeval $ Remote.keyLocations k
 | 
				
			||||||
			assertEqual ("bad content in location log for " ++ f ++ " key " ++ Key.key2file k ++ " uuid " ++ show thisuuid)
 | 
								assertEqual ("bad content in location log for " ++ f ++ " key " ++ Key.serializeKey k ++ " uuid " ++ show thisuuid)
 | 
				
			||||||
				expected (thisuuid `elem` uuids)
 | 
									expected (thisuuid `elem` uuids)
 | 
				
			||||||
		_ -> assertFailure $ f ++ " failed to look up key"
 | 
							_ -> assertFailure $ f ++ " failed to look up key"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,8 +36,8 @@ instance MkActionItem (Transfer, TransferInfo) where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
actionItemDesc :: ActionItem -> Key -> String
 | 
					actionItemDesc :: ActionItem -> Key -> String
 | 
				
			||||||
actionItemDesc (ActionItemAssociatedFile (AssociatedFile (Just f))) _ = f
 | 
					actionItemDesc (ActionItemAssociatedFile (AssociatedFile (Just f))) _ = f
 | 
				
			||||||
actionItemDesc (ActionItemAssociatedFile (AssociatedFile Nothing)) k = key2file k
 | 
					actionItemDesc (ActionItemAssociatedFile (AssociatedFile Nothing)) k = serializeKey k
 | 
				
			||||||
actionItemDesc ActionItemKey k = key2file k
 | 
					actionItemDesc ActionItemKey k = serializeKey k
 | 
				
			||||||
actionItemDesc (ActionItemBranchFilePath bfp) _ = descBranchFilePath bfp
 | 
					actionItemDesc (ActionItemBranchFilePath bfp) _ = descBranchFilePath bfp
 | 
				
			||||||
actionItemDesc (ActionItemFailedTransfer _ i) k =
 | 
					actionItemDesc (ActionItemFailedTransfer _ i) k =
 | 
				
			||||||
	actionItemDesc (ActionItemAssociatedFile (associatedFile i)) k
 | 
						actionItemDesc (ActionItemAssociatedFile (associatedFile i)) k
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ parseInfoFile s = case lines s of
 | 
				
			||||||
formatGitAnnexDistribution :: GitAnnexDistribution -> String
 | 
					formatGitAnnexDistribution :: GitAnnexDistribution -> String
 | 
				
			||||||
formatGitAnnexDistribution d = unlines
 | 
					formatGitAnnexDistribution d = unlines
 | 
				
			||||||
	[ distributionUrl d
 | 
						[ distributionUrl d
 | 
				
			||||||
	, key2file (distributionKey d)
 | 
						, serializeKey (distributionKey d)
 | 
				
			||||||
	, distributionVersion d
 | 
						, distributionVersion d
 | 
				
			||||||
	, show (distributionReleasedate d)
 | 
						, show (distributionReleasedate d)
 | 
				
			||||||
	, maybe "" show (distributionUrgentUpgrade d)
 | 
						, maybe "" show (distributionUrgentUpgrade d)
 | 
				
			||||||
| 
						 | 
					@ -56,7 +56,7 @@ parseGitAnnexDistribution :: String -> Maybe GitAnnexDistribution
 | 
				
			||||||
parseGitAnnexDistribution s = case lines s of
 | 
					parseGitAnnexDistribution s = case lines s of
 | 
				
			||||||
	(u:k:v:d:uu:_) -> GitAnnexDistribution
 | 
						(u:k:v:d:uu:_) -> GitAnnexDistribution
 | 
				
			||||||
		<$> pure u
 | 
							<$> pure u
 | 
				
			||||||
		<*> file2key k
 | 
							<*> deserializeKey k
 | 
				
			||||||
		<*> pure v
 | 
							<*> pure v
 | 
				
			||||||
		<*> readish d
 | 
							<*> readish d
 | 
				
			||||||
		<*> pure (readish uu)
 | 
							<*> pure (readish uu)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue