open: optimise truncate

serial
Avril 3 years ago
parent 8ee5617d13
commit 6c0f9e53f3
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -47,6 +47,7 @@ fn work(arg::Operation{output, inputs}: arg::Operation) -> Result<(), Box<dyn st
// - Read the completion stream receiver until all file jobs have been signaled as completed
// - wait on all worker threads to complete.
// - ensure all data was written.
// - truncate the output file to the correct size (sum of all the input sizes) if needed (we do not truncate before fallocate()ing it, so if a previous larger file existed there, it will have trailing garbage)
Ok(())
}

@ -63,6 +63,7 @@ impl MemoryMapMut
.create(true)
.truncate(true)
.write(true)
.read(true)
.open(from)?;
Ok(Self{

@ -34,7 +34,7 @@ impl Output
fallocate(&mut file, to)?;
map::MemoryMapMut::map(file)
.map_err(OutputError::Map)
.and_then(|map| if map.len() != to {
.and_then(|map| if map.len() < to {
Err(OutputError::Size{expected: to, got: map.len()})
} else {
Ok(map)
@ -48,7 +48,10 @@ impl Output
fs::OpenOptions::new()
.create(true)
.write(true)
.read(true)
//.truncate(true) //TODO: Remove this, and truncate any excess space that may exist from a clobbered previous file at the end
.open(path)
.map(Output)
.map_err(OutputError::Open)
}
@ -93,7 +96,7 @@ impl fmt::Display for OutputError
Self::Open(io) => write!(f, "Failed to open file: {}", io),
Self::Allocate(errno) => write!(f, "fallocate() failed with error {}: {}", errno, errno_str(*errno)),
Self::Map(io) => write!(f, "mmap() failed: {}", io),
Self::Size{expected, got} => write!(f, "mapped file size mismatch: expected {}, got {}", expected, got),
Self::Size{expected, got} => write!(f, "mapped file size mismatch: expected at least {}, got {}", expected, got),
}
}
}

Loading…
Cancel
Save