mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-31 12:00:42 +00:00
fix: rename the written out file in Layer ctor
This commit is contained in:
@@ -561,12 +561,7 @@ impl DeltaLayerWriterInner {
|
||||
// fsync the file
|
||||
file.sync_all()?;
|
||||
|
||||
let layer = Layer::for_written(self.conf, timeline, desc)?;
|
||||
// Rename the file to its final name
|
||||
//
|
||||
// Note: This overwrites any existing file. There shouldn't be any.
|
||||
// FIXME: throw an error instead?
|
||||
std::fs::rename(self.path, layer.local_path())?;
|
||||
let layer = Layer::for_written_tempfile(self.conf, timeline, desc, &self.path)?;
|
||||
|
||||
trace!("created delta layer {}", layer.local_path().display());
|
||||
|
||||
|
||||
@@ -495,13 +495,7 @@ impl ImageLayerWriterInner {
|
||||
// fsync the file
|
||||
file.sync_all()?;
|
||||
|
||||
let layer = Layer::for_written(self.conf, timeline, desc)?;
|
||||
|
||||
// Rename the file to its final name
|
||||
//
|
||||
// Note: This overwrites any existing file. There shouldn't be any.
|
||||
// FIXME: throw an error instead?
|
||||
std::fs::rename(self.path, layer.local_path())?;
|
||||
let layer = Layer::for_written_tempfile(self.conf, timeline, desc, &self.path)?;
|
||||
|
||||
trace!("created image layer {}", layer.local_path().display());
|
||||
|
||||
|
||||
@@ -120,10 +120,13 @@ impl Layer {
|
||||
ResidentLayer { downloaded, owner }
|
||||
}
|
||||
|
||||
pub(crate) fn for_written(
|
||||
/// Creates a Layer value for freshly written out new layer file by renaming it from a
|
||||
/// temporary path.
|
||||
pub(crate) fn for_written_tempfile(
|
||||
conf: &'static PageServerConf,
|
||||
timeline: &Arc<Timeline>,
|
||||
desc: PersistentLayerDesc,
|
||||
temp_path: &Path,
|
||||
) -> anyhow::Result<ResidentLayer> {
|
||||
let mut resident = None;
|
||||
|
||||
@@ -143,7 +146,9 @@ impl Layer {
|
||||
|
||||
let downloaded = resident.expect("just initialized");
|
||||
|
||||
// FIXME: should we handle the rename?
|
||||
// if the rename works, the path is as expected
|
||||
std::fs::rename(temp_path, owner.local_path())
|
||||
.context("rename temporary file as correct path for {owner}")?;
|
||||
|
||||
Ok(ResidentLayer { downloaded, owner })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user