Skip to content

Commit e2376eb

Browse files
committed
Fix repo remove
1 parent c396dc6 commit e2376eb

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,11 @@ async fn repo_add(bot: Bot, msg: Message, name: String, url: String) -> Result<(
453453
let settings = {
454454
let mut locked = resources.settings.write().await;
455455
if let Some(info) = &github_info {
456-
let repository = octocrab::instance().repos(&info.owner, &info.repo)
457-
.get().await.map_err(|e| Error::Octocrab(Box::new(e)))?;
456+
let repository = octocrab::instance()
457+
.repos(&info.owner, &info.repo)
458+
.get()
459+
.await
460+
.map_err(|e| Error::Octocrab(Box::new(e)))?;
458461
if let Some(default_branch) = repository.default_branch {
459462
let default_regex_str = format!("^{}$", regex::escape(&default_branch));
460463
let default_regex = Regex::new(&default_regex_str).map_err(Error::from)?;

src/repo/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ pub async fn create(name: &str, url: &str) -> Result<Output, Error> {
6868
}
6969

7070
pub async fn remove(name: &str) -> Result<(), Error> {
71+
let resource = resources(name).await?;
72+
drop(resource);
7173
RESOURCES_MAP
72-
.remove(&name.to_string(), async |r: Arc<RepoResources>| {
74+
.remove(&name.to_string(), async |r: RepoResources| {
7375
log::info!("try remove repository outer directory: {:?}", r.paths.outer);
7476
remove_dir_all(&r.paths.outer).await?;
75-
log::info!("repository outer directory removed: {:?}", &r.paths.outer);
77+
log::info!("repository outer directory removed: {:?}", r.paths.outer);
7678
Ok(())
7779
})
7880
.await?;

src/resources.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ impl<I, R> ResourcesMap<I, R> {
4646
pub async fn remove<C, F>(&self, index: &I, cleanup: C) -> Result<(), Error>
4747
where
4848
I: Ord + Clone + fmt::Display + fmt::Debug,
49-
C: FnOnce(Arc<R>) -> F,
49+
C: FnOnce(R) -> F,
5050
F: Future<Output = Result<(), Error>>,
5151
{
5252
let mut map = self.map.lock().await;
5353
if let Some(arc) = map.remove(index) {
54-
wait_for_resources_drop(index, arc.clone()).await;
55-
cleanup(arc).await?; // run before the map unlock
54+
let resource = wait_for_resources_drop(index, arc).await;
55+
cleanup(resource).await?;
5656
Ok(())
5757
} else {
5858
Err(Error::UnknownResource(format!("{index}")))
@@ -65,22 +65,22 @@ impl<I, R> ResourcesMap<I, R> {
6565
{
6666
let mut map = self.map.lock().await;
6767
while let Some((task, resources)) = map.pop_first() {
68-
wait_for_resources_drop(&task, resources).await;
68+
let _resource = wait_for_resources_drop(&task, resources).await;
6969
}
7070
Ok(())
7171
}
7272
}
7373

74-
pub async fn wait_for_resources_drop<I, R>(index: &I, mut arc: Arc<R>)
74+
pub async fn wait_for_resources_drop<I, R>(index: &I, mut arc: Arc<R>) -> R
7575
where
7676
I: fmt::Display,
7777
{
7878
loop {
7979
match Arc::try_unwrap(arc) {
80-
Ok(_resource) => {
80+
Ok(resource) => {
8181
// do nothing
8282
// just drop
83-
break;
83+
return resource;
8484
}
8585
Err(a) => {
8686
arc = a;

0 commit comments

Comments
 (0)