diff --git a/object_store/src/local.rs b/object_store/src/local.rs index 20eb3c63ccbd..410d2676f55b 100644 --- a/object_store/src/local.rs +++ b/object_store/src/local.rs @@ -277,13 +277,15 @@ impl ObjectStore for LocalFileSystem { let staging_path = staged_upload_path(&path, &suffix); file.write_all(&bytes) .context(UnableToCopyDataToFileSnafu) - .and_then(|_| { - std::fs::rename(&staging_path, &path).context(UnableToRenameFileSnafu) - }) - .map_err(|e| { - let _ = std::fs::remove_file(&staging_path); // Attempt to cleanup - e.into() - }) + .unwrap(); + + std::mem::drop(file); + + std::fs::rename(&staging_path, &path) + .context(UnableToRenameFileSnafu) + .expect(&format!("path: {staging_path:?}")); + + Ok(()) }) .await } @@ -673,7 +675,11 @@ fn new_staged_upload(base: &std::path::Path) -> Result<(File, String)> { let path = staged_upload_path(base, &suffix); let mut options = OpenOptions::new(); match options.read(true).write(true).create_new(true).open(&path) { - Ok(f) => return Ok((f, suffix)), + Ok(f) => { + f.sync_all() + .map_err(|e| Error::UnableToOpenFile { source: e, path })?; + return Ok((f, suffix)); + } Err(source) => match source.kind() { ErrorKind::AlreadyExists => multipart_id += 1, ErrorKind::NotFound => create_parent_dirs(&path, source)?,