mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Avoid TOCTOU error by rather catching an exception than checking
beforehand
This commit is contained in:
		@@ -450,9 +450,9 @@ def delete_files(sender, instance, **kwargs):
 | 
				
			|||||||
    # Remove the document
 | 
					    # Remove the document
 | 
				
			||||||
    old_file = instance.filename_to_path(instance.filename)
 | 
					    old_file = instance.filename_to_path(instance.filename)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if os.path.isfile(old_file):
 | 
					    try:
 | 
				
			||||||
        os.remove(old_file)
 | 
					        os.remove(old_file)
 | 
				
			||||||
    else:
 | 
					    except FileNotFoundError:
 | 
				
			||||||
        logger = logging.getLogger(__name__)
 | 
					        logger = logging.getLogger(__name__)
 | 
				
			||||||
        logger.warning("Deleted document " + str(instance.id) + " but file " +
 | 
					        logger.warning("Deleted document " + str(instance.id) + " but file " +
 | 
				
			||||||
                       old_file + " was no longer present")
 | 
					                       old_file + " was no longer present")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user