Skip to content

Commit

Permalink
fix all bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kingwingfly committed Jun 4, 2024
1 parent 8327f4d commit 9cd3d99
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 56 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

## [0.2.19] - 2024-06-04
### [0.2.20] - 2024-06-05


## [0.2.19] - 2024-06-05

- better documente for `fav_core`
- fix bugs in batch ops
Expand All @@ -19,6 +22,9 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
- (un)track: show hint after (un)track
- pull: id not found hint improve
- cli version: remove git timestamp
- fix: `batch_pull` and `pull` handle SIGINT together, leading multi info log.
- refactor all commands
- fix: cache not clear if failed or cancelled

## [0.2.18] - 2024-06-04

Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace.package]
version = "0.2.20"
version = "0.2.19"
authors = ["Louis <836250617@qq.com>"]
description = "Back up your favorite online resources with CLI."
license = "MIT"
Expand All @@ -14,10 +14,10 @@ repository = "https://github.com/kingwingfly/fav"
documentation = ""

[workspace.dependencies]
fav_core = { path = "fav_core", version = "0.0.12" }
fav_core = { path = "fav_core", version = "0.0.13" }
fav_derive = { path = "fav_derive", version = "0.0.1" }
fav_utils = { path = "fav_utils", version = "0.0.7" }
fav_cli = { path = "fav_cli", version = "0.2.20" }
fav_utils = { path = "fav_utils", version = "0.0.8" }
fav_cli = { path = "fav_cli", version = "0.2.19" }

[profile.release]
lto = "fat"
Expand Down
56 changes: 29 additions & 27 deletions fav_cli/src/bili/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ pub(super) fn status(sets: &mut BiliSets, id: String) -> FavCoreResult<()> {
for set in sets.iter_mut() {
if set.id() == id {
set.table();
return Ok(());
} else if let Some(res) = set.iter().find(|r| r.id() == id) {
res.table();
} else {
error!(
"{}",
FavCoreError::IdNotUsable {
id: id.to_string(),
msg: "ID not found".to_string(),
}
);
return Ok(());
}
}

error!(
"{}",
FavCoreError::IdNotUsable {
id: id.to_string(),
msg: "ID not found".to_string(),
}
);
Ok(())
}

Expand Down Expand Up @@ -93,50 +93,52 @@ pub(super) async fn fetch(sets: &mut BiliSets) -> FavCoreResult<()> {
}

pub(super) fn track(sets: &mut BiliSets, ids: Vec<String>) -> FavCoreResult<()> {
for id in ids.iter().map(Id::from) {
'a: for id in ids.iter().map(Id::from) {
for set in sets.iter_mut() {
if set.id() == id {
set.on_status(StatusFlags::TRACK);
set.on_res_status(StatusFlags::TRACK);
info!("Tracked set ID: {id}");
continue 'a;
} else if let Some(res) = set.iter_mut().find(|r| r.id() == id) {
res.on_status(StatusFlags::TRACK);
info!("Tracked resource ID: {id}");
} else {
error!(
"{}",
FavCoreError::IdNotUsable {
id: id.to_string(),
msg: "ID not found".to_string(),
}
);
continue 'a;
}
}
error!(
"{}",
FavCoreError::IdNotUsable {
id: id.to_string(),
msg: "ID not found".to_string(),
}
);
}

Ok(())
}

pub(super) fn untrack(sets: &mut BiliSets, ids: Vec<String>) -> FavCoreResult<()> {
for id in ids.iter().map(Id::from) {
'a: for id in ids.iter().map(Id::from) {
for set in sets.iter_mut() {
if set.id() == id {
set.off_status(StatusFlags::TRACK);
set.off_res_status(StatusFlags::TRACK);
info!("Untracked set ID: {id}");
continue 'a;
} else if let Some(res) = set.iter_mut().find(|r| r.id() == id) {
res.off_status(StatusFlags::TRACK);
info!("Untracked resource ID: {id}");
} else {
error!(
"{}",
FavCoreError::IdNotUsable {
id: id.to_string(),
msg: "ID not found".to_string(),
}
);
continue 'a;
}
}
error!(
"{}",
FavCoreError::IdNotUsable {
id: id.to_string(),
msg: "ID not found".to_string(),
}
);
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion fav_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_core"
version = "0.0.12"
version = "0.0.13"
authors.workspace = true
description = "Fav's core crate; A collection of traits."
license.workspace = true
Expand Down
8 changes: 5 additions & 3 deletions fav_core/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,14 @@ where
{
let mut stream = tokio_stream::iter(set.iter_mut())
.map(f)
.buffer_unordered(10);
.buffer_unordered(8);
loop {
tokio::select! {
res = stream.next() => {
match res {
None => break,
Some(Err(e)) => error!("{}", e),
Some(Err(FavCoreError::Cancel)) => return Err(FavCoreError::Cancel),
Some(Err(e)) => error!("{}", e),
_ => {}
}
}
Expand Down Expand Up @@ -311,12 +312,13 @@ where
{
let mut stream = tokio_stream::iter(set.iter_mut())
.map(f)
.buffer_unordered(10);
.buffer_unordered(8);
loop {
tokio::select! {
res = stream.next() => {
match res {
None => break,
Some(Err(FavCoreError::Cancel)) => return Err(FavCoreError::Cancel),
Some(Err(e)) => error!("{}", e),
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion fav_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_utils"
version = "0.0.7"
version = "0.0.8"
authors.workspace = true
description = "Fav's utils crate; A collection of utilities and data structures for the fav project"
license.workspace = true
Expand Down
34 changes: 19 additions & 15 deletions fav_utils/src/bili/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,27 @@ impl SaveLocal for Bili {
None => finish_a = true,
}
},
}
if finish_v && finish_a {
break;
_ = async {}, if finish_v && finish_a => {
file_v.flush().unwrap();
file_a.flush().unwrap();
pb.finish();
merge(
title,
&id,
file_v.into_inner().unwrap().path().to_str().unwrap(),
file_a.into_inner().unwrap().path().to_str().unwrap(),
)
.await?;
res.on_status(StatusFlags::SAVED);
return Ok(())
},
_ = tokio::signal::ctrl_c() => {
file_v.into_inner().unwrap().close()?;
file_a.into_inner().unwrap().close()?;
return Err(FavCoreError::Cancel)
}
}
}
file_v.flush().unwrap();
file_a.flush().unwrap();
pb.finish();
merge(
title,
&id,
file_v.into_inner().unwrap().path().to_str().unwrap(),
file_a.into_inner().unwrap().path().to_str().unwrap(),
)
.await?;
res.on_status(StatusFlags::SAVED);
Ok(())
}
}

Expand Down

0 comments on commit 9cd3d99

Please sign in to comment.