uncloud filescanner os.path.getsize expects str given Path instead
This commit is contained in:
		
					parent
					
						
							
								6847a0d323
							
						
					
				
			
			
				commit
				
					
						7fff280c79
					
				
			
		
					 1 changed files with 5 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -43,7 +43,7 @@ def sha512sum(file: str):
 | 
			
		|||
 | 
			
		||||
def track_file(file, base_dir):
 | 
			
		||||
    file_path = file.relative_to(base_dir)
 | 
			
		||||
 | 
			
		||||
    file_str = str(file)
 | 
			
		||||
    # Get Username
 | 
			
		||||
    try:
 | 
			
		||||
        owner = file_path.parts[0]
 | 
			
		||||
| 
						 | 
				
			
			@ -51,18 +51,18 @@ def track_file(file, base_dir):
 | 
			
		|||
        pass
 | 
			
		||||
    else:
 | 
			
		||||
        file_path = file_path.relative_to(owner)
 | 
			
		||||
        creation_date = time.ctime(os.stat(file).st_ctime)
 | 
			
		||||
        creation_date = time.ctime(os.stat(file_str).st_ctime)
 | 
			
		||||
 | 
			
		||||
        entry_key = os.path.join(settings['etcd']['file_prefix'], str(uuid4()))
 | 
			
		||||
        entry_value = {
 | 
			
		||||
            'filename': str(file_path),
 | 
			
		||||
            'owner': owner,
 | 
			
		||||
            'sha512sum': sha512sum(str(file)),
 | 
			
		||||
            'sha512sum': sha512sum(file_str),
 | 
			
		||||
            'creation_date': creation_date,
 | 
			
		||||
            'size': str(bitmath.Byte(os.path.getsize(str(file))).to_MB()),
 | 
			
		||||
            'size': str(bitmath.Byte(os.path.getsize(file_str)).to_MB()),
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.info('Tracking %s', file)
 | 
			
		||||
        logger.info('Tracking %s', file_str)
 | 
			
		||||
 | 
			
		||||
        shared.etcd_client.put(entry_key, entry_value, value_in_json=True)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue