mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Replace ftruncate/ftruncate64 with a simple set_len() call (#1961)
This commit is contained in:
commit
5fb8b4764f
1 changed files with 2 additions and 19 deletions
|
@ -17,14 +17,8 @@ use memmap;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fs::{self, File, OpenOptions};
|
use std::fs::{self, File, OpenOptions};
|
||||||
use std::io::{self, BufRead, BufReader, BufWriter, ErrorKind, Read, Write};
|
use std::io::{self, BufRead, BufReader, BufWriter, ErrorKind, Read, Write};
|
||||||
use std::os::unix::io::AsRawFd;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
|
||||||
use libc::{ftruncate as ftruncate64, off_t as off64_t};
|
|
||||||
#[cfg(any(target_os = "linux"))]
|
|
||||||
use libc::{ftruncate64, off64_t};
|
|
||||||
|
|
||||||
use core::core::hash::Hash;
|
use core::core::hash::Hash;
|
||||||
use core::ser::{self, FixedLength};
|
use core::ser::{self, FixedLength};
|
||||||
|
|
||||||
|
@ -189,8 +183,8 @@ impl AppendOnlyFile {
|
||||||
/// written data accessible.
|
/// written data accessible.
|
||||||
pub fn flush(&mut self) -> io::Result<()> {
|
pub fn flush(&mut self) -> io::Result<()> {
|
||||||
if self.buffer_start_bak > 0 {
|
if self.buffer_start_bak > 0 {
|
||||||
// flushing a rewound state, we need to truncate before applying
|
// Flushing a rewound state, we need to truncate via set_len() before applying.
|
||||||
self.truncate(self.buffer_start)?;
|
self.file.set_len(self.buffer_start as u64)?;
|
||||||
self.buffer_start_bak = 0;
|
self.buffer_start_bak = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,17 +250,6 @@ impl AppendOnlyFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Truncates the underlying file to the provided offset
|
|
||||||
pub fn truncate(&self, offs: usize) -> io::Result<()> {
|
|
||||||
let fd = self.file.as_raw_fd();
|
|
||||||
let res = unsafe { ftruncate64(fd, offs as off64_t) };
|
|
||||||
if res == -1 {
|
|
||||||
Err(io::Error::last_os_error())
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Saves a copy of the current file content, skipping data at the provided
|
/// Saves a copy of the current file content, skipping data at the provided
|
||||||
/// prune indices. The prune Vec must be ordered.
|
/// prune indices. The prune Vec must be ordered.
|
||||||
pub fn save_prune<T>(
|
pub fn save_prune<T>(
|
||||||
|
|
Loading…
Reference in a new issue