Enabling opening files for writing

This commit is contained in:
Olivier 'reivilibre' 2022-01-24 20:21:48 +00:00
parent 58ae7a58ba
commit 0c893c02d4
3 changed files with 18 additions and 14 deletions

View File

@ -329,12 +329,10 @@ impl Filesystem for OliveFilesystem {
};
if open_mode.write || open_mode.append {
debug!(
"[Not Implemented (because of writing)] open(ino: {:#x?}, flags: {:?})",
warn!(
"[DANGER: Writing is unstable!] open(ino: {:#x?}, flags: {:?})",
ino, flags
);
reply.error(ENOSYS);
return;
}
self.spawn_with_error_handler(
@ -356,15 +354,19 @@ impl Filesystem for OliveFilesystem {
// and caching up to that point.
// We might wind up wanting to do our own buffering...
if let Some(config) = streaming_reader_opts {
requester
.start_streaming_reader(file_handle, config)
.await?;
debug!(
"open(ino: {:#x?}) = fh {:?} (streaming reader: yes)",
ino, file_handle
);
if open_mode.read && !open_mode.write && !open_mode.append {
// Only enable streaming readers in read-only use
if let Some(config) = streaming_reader_opts {
requester
.start_streaming_reader(file_handle, config)
.await?;
debug!(
"open(ino: {:#x?}) = fh {:?} (streaming reader: yes)",
ino, file_handle
);
}
}
debug!(
"open(ino: {:#x?}) = fh {:?} (streaming reader: no)",
ino, file_handle

View File

@ -28,7 +28,7 @@ impl HelloMessage {
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub struct OpenMode {
pub read: bool,
pub write: bool,

View File

@ -14,6 +14,7 @@ use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::{Duration, Instant};
use log::{error, warn};
use tokio::fs::{OpenOptions, ReadDir};
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
use tokio::sync::RwLock;
@ -413,10 +414,11 @@ impl FileAccess {
}
if mode.write {
open_options.write(true);
todo!();
warn!("DANGER: file opened with write mode");
}
if mode.append {
open_options.append(true);
error!("UNSUPPORTED: file opened with append mode");
todo!();
}
// TODO truncate?