tighten file2key to not produce invalid keys with no keyName
A file named "foo-" or "foo-bar" was taken as a key's file, with a backend of "foo", and an empty keyName. This led to various problems, especially because converting that key back to a file did not yeild the same filename.
This commit is contained in:
		
					parent
					
						
							
								15597e5fff
							
						
					
				
			
			
				commit
				
					
						396e47b07e
					
				
			
		
					 4 changed files with 21 additions and 3 deletions
				
			
		|  | @ -346,7 +346,9 @@ fileKey file = file2key $ | ||||||
| 
 | 
 | ||||||
| {- for quickcheck -} | {- for quickcheck -} | ||||||
| prop_idempotent_fileKey :: String -> Bool | prop_idempotent_fileKey :: String -> Bool | ||||||
| prop_idempotent_fileKey s = Just k == fileKey (keyFile k) | prop_idempotent_fileKey s | ||||||
|  | 	| null s = True -- it's not legal for a key to have no keyName | ||||||
|  | 	| otherwise= Just k == fileKey (keyFile k) | ||||||
|   where |   where | ||||||
| 	k = stubKey { keyName = s, keyBackendName = "test" } | 	k = stubKey { keyName = s, keyBackendName = "test" } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								Test.hs
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								Test.hs
									
										
									
									
									
								
							|  | @ -119,6 +119,7 @@ quickcheck = | ||||||
| 	, check "prop_idempotent_deencode" Utility.Format.prop_idempotent_deencode | 	, check "prop_idempotent_deencode" Utility.Format.prop_idempotent_deencode | ||||||
| 	, check "prop_idempotent_fileKey" Locations.prop_idempotent_fileKey | 	, check "prop_idempotent_fileKey" Locations.prop_idempotent_fileKey | ||||||
| 	, check "prop_idempotent_key_encode" Types.Key.prop_idempotent_key_encode | 	, check "prop_idempotent_key_encode" Types.Key.prop_idempotent_key_encode | ||||||
|  | 	, check "prop_idempotent_key_decode" Types.Key.prop_idempotent_key_decode | ||||||
| 	, check "prop_idempotent_shellEscape" Utility.SafeCommand.prop_idempotent_shellEscape | 	, check "prop_idempotent_shellEscape" Utility.SafeCommand.prop_idempotent_shellEscape | ||||||
| 	, check "prop_idempotent_shellEscape_multiword" Utility.SafeCommand.prop_idempotent_shellEscape_multiword | 	, check "prop_idempotent_shellEscape_multiword" Utility.SafeCommand.prop_idempotent_shellEscape_multiword | ||||||
| 	, check "prop_logs_sane" Logs.prop_logs_sane | 	, check "prop_logs_sane" Logs.prop_logs_sane | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								Types/Key.hs
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								Types/Key.hs
									
										
									
									
									
								
							|  | @ -14,7 +14,8 @@ module Types.Key ( | ||||||
| 	key2file, | 	key2file, | ||||||
| 	file2key, | 	file2key, | ||||||
| 
 | 
 | ||||||
| 	prop_idempotent_key_encode | 	prop_idempotent_key_encode, | ||||||
|  | 	prop_idempotent_key_decode | ||||||
| ) where | ) where | ||||||
| 
 | 
 | ||||||
| import System.Posix.Types | import System.Posix.Types | ||||||
|  | @ -59,7 +60,7 @@ key2file Key { keyBackendName = b, keySize = s, keyMtime = m, keyName = n } = | ||||||
| 	_ ?: _ = "" | 	_ ?: _ = "" | ||||||
| 
 | 
 | ||||||
| file2key :: FilePath -> Maybe Key | file2key :: FilePath -> Maybe Key | ||||||
| file2key s = if key == Just stubKey then Nothing else key | file2key s = if key == Just stubKey || (keyName <$> key) == Just "" then Nothing else key | ||||||
|   where |   where | ||||||
| 	key = startbackend stubKey s | 	key = startbackend stubKey s | ||||||
| 
 | 
 | ||||||
|  | @ -88,3 +89,8 @@ instance Arbitrary Key where | ||||||
| 
 | 
 | ||||||
| prop_idempotent_key_encode :: Key -> Bool | prop_idempotent_key_encode :: Key -> Bool | ||||||
| prop_idempotent_key_encode k = Just k == (file2key . key2file) k | prop_idempotent_key_encode k = Just k == (file2key . key2file) k | ||||||
|  | 
 | ||||||
|  | prop_idempotent_key_decode :: FilePath -> Bool | ||||||
|  | prop_idempotent_key_decode f | ||||||
|  | 	| null f = True -- skip illegal empty filename | ||||||
|  | 	| otherwise = maybe True (\k -> key2file k == f) (file2key f) | ||||||
|  |  | ||||||
|  | @ -14,3 +14,12 @@ i get : | ||||||
| how could i fix this issue ? | how could i fix this issue ? | ||||||
| 
 | 
 | ||||||
| many thanks for help | many thanks for help | ||||||
|  | 
 | ||||||
|  | > [[done]]; I managed to reproduce this bug by making a temp file named | ||||||
|  | > ".git/annex/tmp/foo-", or indeed with any dash in it. This is enough | ||||||
|  | > to make git-annex think it's a key, but badly formed enough that | ||||||
|  | > it fails trying to use that key. Fixed to ignore such non-key files. | ||||||
|  | >  | ||||||
|  | > I'm unsure why `.git/annex/tmp` would have such files in it. | ||||||
|  | > Perhaps the assistant was running, but crashed while adding files? | ||||||
|  | > --[[Joey]] | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Joey Hess
				Joey Hess