Commit

Author:

Hash:

Timestamp:

+18 -16 +/-8 browse

Kevin Schoon [me@kevinschoon.com]

135e7876f2f6b28b8415f14e905b5eaf4b665452

Thu, 17 Jul 2025 15:52:31 +0000 (4 months ago)

fixup ayllu_git::Scanner
1diff --git a/ayllu/src/config.rs b/ayllu/src/config.rs
2index 0bba471..5e15b88 100644
3--- a/ayllu/src/config.rs
4+++ b/ayllu/src/config.rs
5 @@ -87,7 +87,7 @@ pub struct Highlighting {
6 pub struct Collection {
7 pub name: String,
8 pub description: Option<String>,
9- pub path: String,
10+ pub path: PathBuf,
11 pub hidden: Option<bool>,
12 }
13
14 diff --git a/ayllu/src/main.rs b/ayllu/src/main.rs
15index ada90a4..8488636 100644
16--- a/ayllu/src/main.rs
17+++ b/ayllu/src/main.rs
18 @@ -78,7 +78,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
19 cfg.collections.push(Collection {
20 name: String::from("Default"),
21 description: Some(format!("Collection @ {}", path.to_string_lossy())),
22- path: path.to_string_lossy().to_string(),
23+ path: path,
24 ..Default::default()
25 })
26 }
27 diff --git a/ayllu/src/web2/middleware/repository.rs b/ayllu/src/web2/middleware/repository.rs
28index b8f086e..9bb229e 100644
29--- a/ayllu/src/web2/middleware/repository.rs
30+++ b/ayllu/src/web2/middleware/repository.rs
31 @@ -56,8 +56,8 @@ impl Preamble {
32 .find(|collection| collection.name == collection_name)
33 {
34 Some(collection) => (
35- PathBuf::from(collection.path.clone()),
36- PathBuf::from(format!("{}/{}", collection.path, repo_name)),
37+ collection.path.clone(),
38+ collection.path.join(std::path::Path::new(&repo_name)),
39 collection.hidden.is_some_and(|hidden| hidden),
40 ),
41 None => {
42 diff --git a/ayllu/src/web2/routes/finger.rs b/ayllu/src/web2/routes/finger.rs
43index 6e79724..30c2157 100644
44--- a/ayllu/src/web2/routes/finger.rs
45+++ b/ayllu/src/web2/routes/finger.rs
46 @@ -28,7 +28,7 @@ fn get_all(collections: &[Collection]) -> Result<Vec<Pair>, ayllu_git::Error> {
47 collection.hidden.is_none() || collection.hidden.is_some_and(|hidden| !hidden)
48 })
49 .try_fold(Vec::new(), |mut accm, collection| {
50- let scanner = ayllu_git::Scanner::from_path(&collection.path)?;
51+ let scanner: ayllu_git::Scanner = collection.path.as_path().try_into()?;
52 let reposoitories: Result<Vec<(String, ayllu_git::Config)>, GitError> = scanner
53 .map(|repo_path| {
54 let repository = Repository::new(repo_path.as_path())?;
55 @@ -106,7 +106,7 @@ impl Resolver {
56
57 if let Some(resource) = collections.find_map(|collection| {
58 if collection.name.eq(resource.path().trim_start_matches("/")) {
59- let scanner = ayllu_git::Scanner::from_path(&collection.path).ok()?;
60+ let scanner: ayllu_git::Scanner = collection.path.as_path().try_into().ok()?;
61 Some(Resource::Collection((
62 collection.clone(),
63 scanner
64 @@ -122,7 +122,7 @@ impl Resolver {
65 }
66
67 if let Some(resource) = collections.find_map(|collection| {
68- let mut scanner = ayllu_git::Scanner::from_path(&collection.path).ok()?;
69+ let mut scanner: ayllu_git::Scanner = collection.path.as_path().try_into().ok()?;
70 scanner.find_map(|repo_path| {
71 let (collection_str, name) = ayllu_git::collection_and_name(repo_path.as_path());
72 if resource
73 diff --git a/ayllu/src/web2/routes/index.rs b/ayllu/src/web2/routes/index.rs
74index 1ea1f69..b044db1 100644
75--- a/ayllu/src/web2/routes/index.rs
76+++ b/ayllu/src/web2/routes/index.rs
77 @@ -28,9 +28,9 @@ struct Repository {
78 is_mirror: bool,
79 }
80
81- async fn load_repositories(collection_path: &str) -> Result<Vec<Repository>, Error> {
82+ async fn load_repositories(collection_path: &std::path::Path) -> Result<Vec<Repository>, Error> {
83 let mut repositories: Vec<Repository> = Vec::new();
84- let scanner = Scanner::from_path(collection_path)?;
85+ let scanner: Scanner = collection_path.try_into()?;
86 for repo_path in scanner {
87 let repository = Wrapper::new(repo_path.as_path())?;
88 let git_config = repository.config()?;
89 @@ -78,7 +78,7 @@ pub async fn index(
90 if collection.hidden.is_some_and(|hidden| hidden) {
91 continue;
92 };
93- let repositories = load_repositories(collection.path.as_str()).await?;
94+ let repositories = load_repositories(&collection.path).await?;
95 collections.push(Collection {
96 name: collection.name.clone(),
97 description: collection.description.clone(),
98 @@ -114,7 +114,7 @@ pub async fn collection(
99 return Err(Error::NotFound("collection not found".to_string()));
100 }
101 let entry = entry.unwrap();
102- let repositories = load_repositories(entry.path.as_str()).await?;
103+ let repositories = load_repositories(entry.path.as_path()).await?;
104 base.title = format!("{collection:?}");
105 base.nav_elements = crate::web2::navigation::global("index", false);
106 base.current_time = timeutil::timestamp();
107 diff --git a/ayllu/src/web2/routes/rest/discovery.rs b/ayllu/src/web2/routes/rest/discovery.rs
108index f825d04..11c3da7 100644
109--- a/ayllu/src/web2/routes/rest/discovery.rs
110+++ b/ayllu/src/web2/routes/rest/discovery.rs
111 @@ -13,7 +13,7 @@ pub async fn serve(Extension(cfg): Extension<Config>) -> Result<Json<Vec<Collect
112 continue;
113 }
114 let mut repositories: Vec<Repository> = Vec::new();
115- for repo in Scanner::from_path(&config.path)? {
116+ for repo in TryInto::<Scanner>::try_into(config.path.as_path())? {
117 let repository = Wrapper::new(repo.as_path())?;
118 let repo_config = repository.config()?;
119 repositories.push(Repository {
120 diff --git a/ayllu/src/web2/routes/rss.rs b/ayllu/src/web2/routes/rss.rs
121index f742768..d494588 100644
122--- a/ayllu/src/web2/routes/rss.rs
123+++ b/ayllu/src/web2/routes/rss.rs
124 @@ -131,7 +131,7 @@ impl Builder {
125 if collection.hidden.is_some_and(|hidden| hidden) {
126 continue;
127 }
128- for repository_path in Scanner::from_path(&collection.path)? {
129+ for repository_path in TryInto::<Scanner>::try_into(collection.path.as_path())? {
130 let file_name = repository_path.file_name().unwrap();
131 let name = file_name.to_str().unwrap();
132 entries.push((
133 diff --git a/crates/git/src/scanner.rs b/crates/git/src/scanner.rs
134index 6dac517..af6193e 100644
135--- a/crates/git/src/scanner.rs
136+++ b/crates/git/src/scanner.rs
137 @@ -67,9 +67,11 @@ pub struct Scanner {
138 files: ReadDir,
139 }
140
141- impl Scanner {
142- pub fn from_path(path: &str) -> Result<Self, Error> {
143- let files = read_dir(path)?;
144+ impl TryInto<Scanner> for &Path {
145+ type Error = Error;
146+
147+ fn try_into(self) -> Result<Scanner, Self::Error> {
148+ let files = read_dir(self)?;
149 Ok(Scanner { files })
150 }
151 }