Fix the issue about fsync on hostfs's dir
There are no sync methods about untrusted dir, so we do nothing.
This commit is contained in:
parent
016ef88535
commit
1dc2b517fc
@ -125,16 +125,24 @@ impl INode for HNode {
|
||||
}
|
||||
|
||||
fn sync_all(&self) -> Result<()> {
|
||||
let mut guard = self.open_file()?;
|
||||
let file = guard.as_mut().unwrap();
|
||||
try_std!(file.sync_all());
|
||||
if self.path.is_file() {
|
||||
let mut guard = self.open_file()?;
|
||||
let file = guard.as_mut().unwrap();
|
||||
try_std!(file.sync_all());
|
||||
} else {
|
||||
warn!("no sync_all method about dir, do nothing");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sync_data(&self) -> Result<()> {
|
||||
let mut guard = self.open_file()?;
|
||||
let file = guard.as_mut().unwrap();
|
||||
try_std!(file.sync_data());
|
||||
if self.path.is_file() {
|
||||
let mut guard = self.open_file()?;
|
||||
let file = guard.as_mut().unwrap();
|
||||
try_std!(file.sync_data());
|
||||
} else {
|
||||
warn!("no sync_data method about dir, do nothing");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -213,6 +213,7 @@ static int test_truncate() {
|
||||
static int test_mkdir_then_rmdir() {
|
||||
const char *dir_path = "/host/hostfs_dir";
|
||||
struct stat stat_buf;
|
||||
int dir_fd;
|
||||
|
||||
if (mkdir(dir_path, 00775) < 0) {
|
||||
THROW_ERROR("failed to create the dir");
|
||||
@ -224,6 +225,16 @@ static int test_mkdir_then_rmdir() {
|
||||
THROW_ERROR("failed to check if it is dir");
|
||||
}
|
||||
|
||||
dir_fd = open(dir_path, O_RDONLY | O_DIRECTORY);
|
||||
if (dir_fd < 0) {
|
||||
THROW_ERROR("failed to open dir");
|
||||
}
|
||||
|
||||
if (fsync(dir_fd) < 0) {
|
||||
THROW_ERROR("failed to fsync dir");
|
||||
}
|
||||
close(dir_fd);
|
||||
|
||||
if (rmdir(dir_path) < 0) {
|
||||
THROW_ERROR("failed to remove the created dir");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user