Use os.sync where possible.
Check st_size to prevent reading existing file unless it has the same size as the old file in build_file_from_blob.