mirror of
				https://github.com/allenai/olmocr.git
				synced 2025-11-04 12:07:15 +00:00 
			
		
		
		
	Fixing one old bug to make update_static atomic
This commit is contained in:
		
							parent
							
								
									38dc5a2a0f
								
							
						
					
					
						commit
						4047258277
					
				@ -120,8 +120,19 @@ def update_state(folder_path: str, filename: str, **kwargs):
 | 
				
			|||||||
    all_state[filename]["last_checked"] = datetime.datetime.now()
 | 
					    all_state[filename]["last_checked"] = datetime.datetime.now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    state_file = os.path.join(folder_path, UPLOAD_STATE_FILENAME)
 | 
					    state_file = os.path.join(folder_path, UPLOAD_STATE_FILENAME)
 | 
				
			||||||
    with open(state_file, "w") as f:
 | 
					    temp_file = state_file + '.tmp'
 | 
				
			||||||
        return json.dump(all_state, f, default=_json_datetime_encoder)
 | 
					    
 | 
				
			||||||
 | 
					    # Write to temporary file first
 | 
				
			||||||
 | 
					    with open(temp_file, "w") as f:
 | 
				
			||||||
 | 
					        json.dump(all_state, f, default=_json_datetime_encoder)
 | 
				
			||||||
 | 
					        f.flush()
 | 
				
			||||||
 | 
					        os.fsync(f.fileno())
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    # Atomic rename of temporary file to target file
 | 
				
			||||||
 | 
					    os.replace(temp_file, state_file)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return all_state
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
def get_total_space_usage():
 | 
					def get_total_space_usage():
 | 
				
			||||||
    return sum(file.bytes for file in client.files.list())
 | 
					    return sum(file.bytes for file in client.files.list())
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user