Skip to content

Commit

Permalink
fix: fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jul 15, 2024
1 parent a4847f4 commit f18c318
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 50 deletions.
40 changes: 20 additions & 20 deletions src/ic_oss_bucket/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Bucket {
now_sec: u64,
) -> Result<Policies, (u16, String)> {
if self.status != 0 {
Err((403, "bucket is not writeable".to_string()))?;
Err((403, "bucket is not writable".to_string()))?;
}

if self.managers.contains(caller) {
Expand Down Expand Up @@ -454,7 +454,7 @@ impl FoldersTree {
.ok_or_else(|| format!("parent folder not found: {}", metadata.parent))?;

if parent.status != 0 {
Err("parent folder is not writeable".to_string())?;
Err("parent folder is not writable".to_string())?;
}

if parent.folders.len() + parent.files.len() >= max_children {
Expand All @@ -471,7 +471,7 @@ impl FoldersTree {
.ok_or_else(|| format!("parent folder not found: {}", parent))?;

if folder.status != 0 {
Err("parent folder is not writeable".to_string())?;
Err("parent folder is not writable".to_string())?;
}

Ok(folder)
Expand All @@ -487,7 +487,7 @@ impl FoldersTree {
.ok_or_else(|| format!("parent folder not found: {}", parent))?;

if folder.status != 0 {
Err("parent folder is not writeable".to_string())?;
Err("parent folder is not writable".to_string())?;
}

if folder.folders.len() + folder.files.len() >= max_children {
Expand Down Expand Up @@ -521,21 +521,21 @@ impl FoldersTree {
Err(format!("folder {} is not in folder {}", id, from))?;
}
if folder.status != 0 {
Err(format!("folder {} is not writeable", id))?;
Err(format!("folder {} is not writable", id))?;
}

let from_folder = self
.get(&from)
.ok_or_else(|| format!("folder not found: {}", from))?;
if from_folder.status != 0 {
Err(format!("folder {} is not writeable", from))?;
Err(format!("folder {} is not writable", from))?;
}

let to_folder = self
.get(&to)
.ok_or_else(|| format!("folder not found: {}", to))?;
if to_folder.status != 0 {
Err(format!("folder {} is not writeable", to))?;
Err(format!("folder {} is not writable", to))?;
}

if to_folder.folders.len() + to_folder.files.len() >= max_children {
Expand Down Expand Up @@ -578,14 +578,14 @@ impl FoldersTree {
.get(&from)
.ok_or_else(|| format!("folder not found: {}", from))?;
if from_folder.status != 0 {
Err(format!("folder {} is not writeable", from))?;
Err(format!("folder {} is not writable", from))?;
}

let to_folder = self
.get(&to)
.ok_or_else(|| format!("folder not found: {}", to))?;
if to_folder.status != 0 {
Err(format!("folder {} is not writeable", to))?;
Err(format!("folder {} is not writable", to))?;
}

if to_folder.folders.len() + to_folder.files.len() >= max_children {
Expand Down Expand Up @@ -635,7 +635,7 @@ impl FoldersTree {
.ok_or_else(|| format!("parent folder not found: {}", parent_id))?;

if parent.status != 0 {
Err("parent folder is not writeable".to_string())?;
Err("parent folder is not writable".to_string())?;
}

if parent.folders.remove(&id) {
Expand Down Expand Up @@ -932,7 +932,7 @@ pub mod fs {
.ok_or_else(|| format!("file not found: {}", id))?;

if file.status != 0 {
Err(format!("file {} is not writeable", id))?;
Err(format!("file {} is not writable", id))?;
}

if file.parent != from {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ pub mod fs {
None => Err(format!("file not found: {}", file_id)),
Some(mut file) => {
if file.status != 0 {
Err(format!("file {} is not writeable", file_id))?;
Err(format!("file {} is not writable", file_id))?;
}

checker(&file)?;
Expand Down Expand Up @@ -1722,7 +1722,7 @@ mod test {
)
.err()
.unwrap()
.contains("parent folder is not writeable"));
.contains("parent folder is not writable"));
tree.get_mut(&0).unwrap().status = 0;
assert!(tree
.add_folder(
Expand Down Expand Up @@ -1751,7 +1751,7 @@ mod test {
.parent_to_add_file(0, 2)
.err()
.unwrap()
.contains("parent folder is not writeable"));
.contains("parent folder is not writable"));
tree.get_mut(&0).unwrap().status = 0;
assert!(tree.parent_to_add_file(0, 2).is_ok());
}
Expand Down Expand Up @@ -1795,15 +1795,15 @@ mod test {
.check_moving_folder(1, 0, 2, 10, 100)
.err()
.unwrap()
.contains("is not writeable"));
.contains("is not writable"));

tree.get_mut(&1).unwrap().status = 0;
tree.get_mut(&0).unwrap().status = 1;
assert!(tree
.check_moving_folder(1, 0, 2, 10, 100)
.err()
.unwrap()
.contains("is not writeable"));
.contains("is not writable"));
tree.get_mut(&0).unwrap().status = 0;
assert!(tree
.check_moving_folder(1, 0, 2, 10, 100)
Expand All @@ -1827,7 +1827,7 @@ mod test {
.check_moving_folder(1, 0, 2, 10, 100)
.err()
.unwrap()
.contains("is not writeable"));
.contains("is not writable"));
tree.get_mut(&2).unwrap().status = 0;
assert!(tree
.check_moving_folder(1, 0, 2, 10, 0)
Expand Down Expand Up @@ -1870,7 +1870,7 @@ mod test {
.check_moving_file(0, 1, 100)
.err()
.unwrap()
.contains("is not writeable"));
.contains("is not writable"));
tree.get_mut(&0).unwrap().status = 0;
assert!(tree
.check_moving_file(0, 1, 100)
Expand All @@ -1893,7 +1893,7 @@ mod test {
.check_moving_file(0, 1, 100)
.err()
.unwrap()
.contains("is not writeable"));
.contains("is not writable"));
tree.get_mut(&1).unwrap().status = 0;
assert!(tree
.check_moving_file(0, 1, 0)
Expand Down Expand Up @@ -1947,7 +1947,7 @@ mod test {
.delete_folder(1, 99, |_| Ok(()))
.err()
.unwrap()
.contains("parent folder is not writeable"));
.contains("parent folder is not writable"));
tree.get_mut(&0).unwrap().status = 0;
assert!(tree.delete_folder(1, 99, |_| Ok(())).unwrap());
assert_eq!(tree.len(), 1);
Expand Down
43 changes: 13 additions & 30 deletions src/ic_oss_can/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,11 @@ macro_rules! ic_oss_fs {
_access_token: Option<ByteBuf>,
) -> Result<Vec<FileInfo>, String> {
let caller = ic_cdk::api::caller();

let max_prev = fs::with(|r| {
if r.visibility == 0 && !r.managers.contains(&caller) {
Err("permission denied".to_string())?;
}
Ok::<u32, String>(r.file_id.saturating_add(1))
Ok::<u32, String>(r.file_id)
})?;
let prev = prev.unwrap_or(max_prev).min(max_prev);
let take = take.unwrap_or(10).min(100);
Expand All @@ -282,13 +281,9 @@ macro_rules! ic_oss_fs {
) -> Result<CreateFileOutput, String> {
input.validate()?;
let caller = ic_cdk::api::caller();

fs::with(|r| {
if !r.managers.contains(&caller) {
Err("permission denied".to_string())?;
}
Ok::<(), String>(())
})?;
if !fs::is_manager(&caller) {
Err("permission denied".to_string())?;
}

let size = input.size.unwrap_or(0);
let now_ms = ic_cdk::api::time() / MILLISECONDS;
Expand Down Expand Up @@ -351,13 +346,9 @@ macro_rules! ic_oss_fs {
) -> Result<UpdateFileOutput, String> {
input.validate()?;
let caller = ic_cdk::api::caller();

fs::with(|r| {
if !r.managers.contains(&caller) {
Err("permission denied".to_string())?;
}
Ok::<(), String>(())
})?;
if !fs::is_manager(&caller) {
Err("permission denied".to_string())?;
}

let now_ms = ic_cdk::api::time() / MILLISECONDS;
fs::update_file(input, now_ms)?;
Expand All @@ -375,13 +366,9 @@ macro_rules! ic_oss_fs {
}
}
let caller = ic_cdk::api::caller();

fs::with(|r| {
if !r.managers.contains(&caller) {
Err("permission denied".to_string())?;
}
Ok::<(), String>(())
})?;
if !fs::is_manager(&caller) {
Err("permission denied".to_string())?;
}

let now_ms = ic_cdk::api::time() / MILLISECONDS;
let filled = fs::update_chunk(
Expand All @@ -400,13 +387,9 @@ macro_rules! ic_oss_fs {
#[ic_cdk::update]
fn delete_file(id: u32, _access_token: Option<ByteBuf>) -> Result<bool, String> {
let caller = ic_cdk::api::caller();

fs::with(|r| {
if !r.managers.contains(&caller) {
Err("permission denied".to_string())?;
}
Ok::<(), String>(())
})?;
if !fs::is_manager(&caller) {
Err("permission denied".to_string())?;
}

fs::delete_file(id)
}
Expand Down

0 comments on commit f18c318

Please sign in to comment.