Skip to content

Commit 472d9f6

Browse files
feat(core): make a repository dir for each network
This is the more sane thing to do because each network can have a different repository version. Link: #234 Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 560da0a commit 472d9f6

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

coffee_core/src/coffee.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ impl PluginManager for CoffeeManager {
383383
if self.repos.contains_key(name) {
384384
return Err(error!("repository with name: {name} already exists"));
385385
}
386-
let url = URL::new(&self.config.root_path, url, name);
386+
let local_path = format!("{}/{}", self.config.root_path, self.config.network);
387+
let url = URL::new(&local_path, url, name);
387388
log::debug!("remote adding: {} {}", name, &url.url_string);
388389
let mut repo = Github::new(name, &url);
389390
repo.init().await?;

coffee_core/src/config.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44
use std::env;
55

66
use crate::CoffeeOperation;
7-
use coffee_lib::utils::check_dir_or_make_if_missing;
7+
use coffee_lib::utils::{check_dir_or_make_if_missing, move_dir_if_exist};
88
use coffee_lib::{errors::CoffeeError, plugin::Plugin};
99

1010
use crate::CoffeeArgs;
@@ -65,7 +65,9 @@ impl CoffeeConf {
6565

6666
check_dir_or_make_if_missing(format!("{def_path}/{}", coffee.network)).await?;
6767
check_dir_or_make_if_missing(format!("{def_path}/{}/plugins", coffee.network)).await?;
68-
check_dir_or_make_if_missing(format!("{def_path}/repositories")).await?;
68+
let repo_dir = format!("{def_path}/{}/repositories", coffee.network);
69+
move_dir_if_exist(&format!("{def_path}/repositories"), &repo_dir).await?;
70+
check_dir_or_make_if_missing(repo_dir).await?;
6971
// after we know all the information regarding
7072
// the configuration we try to see if there is
7173
// something stored already to the disk.

coffee_lib/src/utils.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::macros::error;
22
use std::path::Path;
33

44
use tokio::fs::create_dir;
5+
use tokio::fs::rename;
56

67
use crate::errors::CoffeeError;
78

@@ -28,6 +29,14 @@ pub async fn check_dir_or_make_if_missing(path: String) -> Result<(), CoffeeErro
2829
Ok(())
2930
}
3031

32+
pub async fn move_dir_if_exist(origin: &str, destination: &str) -> Result<(), CoffeeError> {
33+
if Path::exists(Path::new(&origin)) {
34+
rename(origin, destination).await?;
35+
log::debug!("move dir from {origin} to {destination}");
36+
}
37+
Ok(())
38+
}
39+
3140
#[cfg(test)]
3241
mod tests {
3342
use std::fs::create_dir_all;

git-bugreport-2024-02-07-1353.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Thank you for filling out a Git bug report!
2+
Please answer the following questions to help us understand your issue.
3+
4+
What did you do before the bug happened? (Steps to reproduce your issue)
5+
6+
What did you expect to happen? (Expected behavior)
7+
8+
What happened instead? (Actual behavior)
9+
10+
What's different between what you expected and what actually happened?
11+
12+
Anything else you want to add:
13+
14+
Please review the rest of the bug report below.
15+
You can delete any lines you don't wish to share.
16+
17+
18+
[System Info]
19+
git version:
20+
git version 2.43.0
21+
cpu: x86_64
22+
no commit associated with this build
23+
sizeof-long: 8
24+
sizeof-size_t: 8
25+
shell-path: /bin/sh
26+
uname: Linux 6.6.15-2-lts #1 SMP PREEMPT_DYNAMIC Fri, 02 Feb 2024 17:04:24 +0000 x86_64
27+
compiler info: gnuc: 13.2
28+
libc info: glibc: 2.39
29+
$SHELL (typically, interactive shell): /usr/bin/zsh
30+
31+
32+
[Enabled Hooks]

0 commit comments

Comments
 (0)