Skip to content

Commit

Permalink
feat(core): make a repository dir for each network
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
vincenzopalazzo committed Feb 7, 2024
1 parent 560da0a commit 472d9f6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ impl PluginManager for CoffeeManager {
if self.repos.contains_key(name) {
return Err(error!("repository with name: {name} already exists"));
}
let url = URL::new(&self.config.root_path, url, name);
let local_path = format!("{}/{}", self.config.root_path, self.config.network);
let url = URL::new(&local_path, url, name);
log::debug!("remote adding: {} {}", name, &url.url_string);
let mut repo = Github::new(name, &url);
repo.init().await?;
Expand Down
6 changes: 4 additions & 2 deletions coffee_core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use std::env;

use crate::CoffeeOperation;
use coffee_lib::utils::check_dir_or_make_if_missing;
use coffee_lib::utils::{check_dir_or_make_if_missing, move_dir_if_exist};
use coffee_lib::{errors::CoffeeError, plugin::Plugin};

use crate::CoffeeArgs;
Expand Down Expand Up @@ -65,7 +65,9 @@ impl CoffeeConf {

check_dir_or_make_if_missing(format!("{def_path}/{}", coffee.network)).await?;
check_dir_or_make_if_missing(format!("{def_path}/{}/plugins", coffee.network)).await?;
check_dir_or_make_if_missing(format!("{def_path}/repositories")).await?;
let repo_dir = format!("{def_path}/{}/repositories", coffee.network);
move_dir_if_exist(&format!("{def_path}/repositories"), &repo_dir).await?;
check_dir_or_make_if_missing(repo_dir).await?;
// after we know all the information regarding
// the configuration we try to see if there is
// something stored already to the disk.
Expand Down
9 changes: 9 additions & 0 deletions coffee_lib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::macros::error;
use std::path::Path;

use tokio::fs::create_dir;
use tokio::fs::rename;

use crate::errors::CoffeeError;

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

pub async fn move_dir_if_exist(origin: &str, destination: &str) -> Result<(), CoffeeError> {
if Path::exists(Path::new(&origin)) {
rename(origin, destination).await?;
log::debug!("move dir from {origin} to {destination}");
}
Ok(())
}

#[cfg(test)]
mod tests {
use std::fs::create_dir_all;
Expand Down
32 changes: 32 additions & 0 deletions git-bugreport-2024-02-07-1353.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

What did you expect to happen? (Expected behavior)

What happened instead? (Actual behavior)

What's different between what you expected and what actually happened?

Anything else you want to add:

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.43.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 6.6.15-2-lts #1 SMP PREEMPT_DYNAMIC Fri, 02 Feb 2024 17:04:24 +0000 x86_64
compiler info: gnuc: 13.2
libc info: glibc: 2.39
$SHELL (typically, interactive shell): /usr/bin/zsh


[Enabled Hooks]

0 comments on commit 472d9f6

Please sign in to comment.