Skip to content

Commit d7af8e1

Browse files
authored
sos-vfs: Use Arc<RwLock> for root dir, fix rename() bug, add test spec. (#763)
* Use Arc<RwLock> for root dir, fix rename() bug, add test spec. * Fix clippy warnings. * Formatting. * Clippy fixes. * Bump version. * Bump version for sos-vfs. * Update crossbeam-channel for advisory. * Update tokio for advisory.
1 parent 7e73062 commit d7af8e1

File tree

10 files changed

+162
-122
lines changed

10 files changed

+162
-122
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ sos-preferences = { version = "0.17", path = "crates/preferences" }
8282
sos-signer = { version = "0.17", path = "crates/signer" }
8383
sos-sync = { version = "0.17", path = "crates/sync" }
8484
sos-sdk = { version = "0.17", path = "crates/sdk" }
85-
sos-vfs = { version = "0.2", path = "crates/vfs" }
85+
sos-vfs = { version = "0.3", path = "crates/vfs" }
8686
sos-web = { version = "0.17", path = "crates/web" }
8787
sos-vault = { version = "0.17", path = "crates/vault" }
8888

crates/vfs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sos-vfs"
3-
version = "0.2.6"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "Virtual file system same as tokio::fs."
66
homepage = "https://saveoursecrets.com"

crates/vfs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::len_without_is_empty)]
12
//! Virtual file system.
23
//!
34
//! The API is designed to match the `tokio::fs` module which in

crates/vfs/src/memory/dir_builder.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77

88
use super::fs::{
9-
has_parent, resolve, resolve_parent, root_fs_mut, MemoryFd, Parent,
9+
has_parent, resolve, resolve_parent, root_fs, MemoryFd, Parent,
1010
PathTarget,
1111
};
1212

@@ -53,7 +53,7 @@ impl DirBuilder {
5353
/// * Other I/O error occurred.
5454
pub async fn create(&self, path: impl AsRef<Path>) -> Result<()> {
5555
if self.recursive {
56-
let mut current = Parent::Root(root_fs_mut());
56+
let mut current = Parent::Root(root_fs());
5757
let mut buf = PathBuf::new();
5858
#[allow(unused_assignments)]
5959
let mut file_name: Option<OsString> = None;
@@ -137,9 +137,7 @@ impl DirBuilder {
137137
Err(ErrorKind::NotFound.into())
138138
}
139139
} else {
140-
Parent::Root(root_fs_mut())
141-
.mkdir(file_name.to_owned())
142-
.await?;
140+
Parent::Root(root_fs()).mkdir(file_name.to_owned()).await?;
143141
Ok(())
144142
}
145143
}

crates/vfs/src/memory/file.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ enum Operation {
9898
impl File {
9999
/// Attempts to open a file in read-only mode.
100100
pub async fn open(path: impl AsRef<Path>) -> io::Result<File> {
101-
Ok(OpenOptions::new().read(true).open(path).await?)
101+
OpenOptions::new().read(true).open(path).await
102102
}
103103

104104
/// Opens a file in write-only mode.
105105
pub async fn create(path: impl AsRef<Path>) -> io::Result<File> {
106-
Ok(OpenOptions::new()
106+
OpenOptions::new()
107107
.write(true)
108108
.create(true)
109109
.truncate(true)
110110
.open(path)
111-
.await?)
111+
.await
112112
}
113113

114114
/// Attempts to sync all OS-internal metadata to disk.
@@ -167,13 +167,12 @@ impl File {
167167
};
168168

169169
let res = if let Some(seek) = seek {
170-
std.seek(seek).and_then(|_| {
170+
std.seek(seek).map(|_| {
171171
if let Some(zero) = extension {
172172
std.get_mut().extend(zero.iter());
173173
} else {
174174
std.get_mut().truncate(size as usize);
175175
}
176-
Ok(())
177176
})
178177
} else {
179178
if let Some(zero) = extension {

0 commit comments

Comments
 (0)