fix error on deletion or upload of plaintext blocks to node that does not support it
This commit is contained in:
		
							parent
							
								
									da57dc373f
								
							
						
					
					
						commit
						503bf65cbe
					
				
					 2 changed files with 6 additions and 23 deletions
				
			
		|  | @ -202,33 +202,10 @@ class Block: | |||
|         except Exception as e: | ||||
|             logger.warn('Failed to parse block %s' % self.getHash(), error = e, timestamp = False) | ||||
| 
 | ||||
|             # if block can't be parsed, it's a waste of precious space. Throw it away. | ||||
|             if not self.delete(): | ||||
|                 logger.warn('Failed to delete invalid block %s.' % self.getHash(), error = e) | ||||
|             else: | ||||
|                 logger.debug('Deleted invalid block %s.' % self.getHash(), timestamp = False) | ||||
| 
 | ||||
|         self.valid = False | ||||
|         return False | ||||
| 
 | ||||
|     def delete(self): | ||||
|         """ | ||||
|             Deletes the block's file and records, if they exist | ||||
| 
 | ||||
|             Outputs: | ||||
|             - (bool): whether or not the operation was successful | ||||
|         """ | ||||
| 
 | ||||
|         if self.exists(): | ||||
|             try: | ||||
|                 os.remove(self.getBlockFile()) | ||||
|             except TypeError: | ||||
|                 pass | ||||
|             b_hash = self.getHash() | ||||
|             onionrstorage.deleteBlock(b_hash) | ||||
|             removeblock.remove_block(b_hash) | ||||
|             return True | ||||
|         return False | ||||
| 
 | ||||
|     def save(self, sign = False, recreate = True): | ||||
|         """ | ||||
|  |  | |||
|  | @ -97,6 +97,12 @@ def validate_metadata(metadata, block_data) -> bool: | |||
|             # make sure we do not have another block with the same data content (prevent data duplication and replay attacks) | ||||
| 
 | ||||
|             # Make sure time is set (validity was checked above if it is) | ||||
|             if not config.get('general.store_plaintext_blocks', True): | ||||
|                 try: | ||||
|                     if not metadata['encryptType']: | ||||
|                         raise onionrexceptions.DataExists | ||||
|                 except KeyError: | ||||
|                     raise onionrexceptions.DataExists | ||||
|             try: | ||||
|                 metadata['time'] | ||||
|             except KeyError: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue