mirror of
https://github.com/uqbar-dao/nectar.git
synced 2025-01-05 00:10:23 +03:00
Merge pull request #141 from uqbar-dao/bp/vfs-pos-fix
vfs: hotfix cursor position addzip
This commit is contained in:
commit
9f72709fb0
27
src/vfs.rs
27
src/vfs.rs
@ -193,10 +193,7 @@ async fn handle_request(
|
|||||||
error: "blob needs to exist for Write".into(),
|
error: "blob needs to exist for Write".into(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
open_files.remove(&path);
|
fs::write(path, &blob.bytes).await?;
|
||||||
let file = open_file(open_files.clone(), path, true, true).await?;
|
|
||||||
let mut file = file.lock().await;
|
|
||||||
file.write_all(&blob.bytes).await?;
|
|
||||||
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
|
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
|
||||||
}
|
}
|
||||||
VfsAction::Append => {
|
VfsAction::Append => {
|
||||||
@ -219,12 +216,7 @@ async fn handle_request(
|
|||||||
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
|
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
|
||||||
}
|
}
|
||||||
VfsAction::Read => {
|
VfsAction::Read => {
|
||||||
let file = open_file(open_files.clone(), path.clone(), false, false).await?;
|
let contents = fs::read(&path).await?;
|
||||||
let mut file = file.lock().await;
|
|
||||||
let mut contents = Vec::new();
|
|
||||||
file.seek(SeekFrom::Start(0)).await?;
|
|
||||||
file.read_to_end(&mut contents).await?;
|
|
||||||
|
|
||||||
(
|
(
|
||||||
serde_json::to_vec(&VfsResponse::Read).unwrap(),
|
serde_json::to_vec(&VfsResponse::Read).unwrap(),
|
||||||
Some(contents),
|
Some(contents),
|
||||||
@ -403,15 +395,8 @@ async fn handle_request(
|
|||||||
(is_file, is_dir, local_path, file_contents)
|
(is_file, is_dir, local_path, file_contents)
|
||||||
};
|
};
|
||||||
if is_file {
|
if is_file {
|
||||||
open_files.remove(&local_path);
|
fs::write(&local_path, &file_contents).await?;
|
||||||
let file = open_file(open_files.clone(), local_path, true, true).await?;
|
|
||||||
let mut file = file.lock().await;
|
|
||||||
|
|
||||||
file.seek(SeekFrom::Start(0)).await?;
|
|
||||||
file.write_all(&file_contents).await?;
|
|
||||||
file.set_len(file_contents.len() as u64).await?;
|
|
||||||
} else if is_dir {
|
} else if is_dir {
|
||||||
// If it's a directory, create it
|
|
||||||
fs::create_dir_all(local_path).await?;
|
fs::create_dir_all(local_path).await?;
|
||||||
} else {
|
} else {
|
||||||
println!("vfs: zip with non-file non-dir");
|
println!("vfs: zip with non-file non-dir");
|
||||||
@ -509,7 +494,11 @@ async fn open_file<P: AsRef<Path>>(
|
|||||||
) -> Result<Arc<Mutex<fs::File>>, VfsError> {
|
) -> Result<Arc<Mutex<fs::File>>, VfsError> {
|
||||||
let path = path.as_ref().to_path_buf();
|
let path = path.as_ref().to_path_buf();
|
||||||
Ok(match open_files.get(&path) {
|
Ok(match open_files.get(&path) {
|
||||||
Some(file) => Arc::clone(file.value()),
|
Some(file) => {
|
||||||
|
let mut file_lock = file.lock().await;
|
||||||
|
file_lock.seek(SeekFrom::Start(0)).await?;
|
||||||
|
Arc::clone(file.value())
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
let file = Arc::new(Mutex::new(
|
let file = Arc::new(Mutex::new(
|
||||||
OpenOptions::new()
|
OpenOptions::new()
|
||||||
|
Loading…
Reference in New Issue
Block a user