Skip to content

Commit 9273566

Browse files
committed
sbuild: implement icon dir fallbacks
1 parent 6456561 commit 9273566

3 files changed

Lines changed: 72 additions & 29 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A repo containing the linter and builder for SBUILD packages.
44

55
## sbuild-linter
6+
67
The linter validates the provided `SBUILD` package recipe, performs checks and generates the validated recipe for the builder to work with.
78

89
```sh
@@ -17,6 +18,7 @@ Options:
1718
--inplace, -i Replace the original file on success
1819
--success <PATH> File to store successful packages list
1920
--fail <PATH> File to store failed packages list
21+
--timeout <DURATION> Timeout duration after which the pkgver check exits
2022
--help, -h Show this help message
2123

2224
Arguments:

sbuild/src/builder.rs

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ impl Builder {
162162
let final_path = format!("{}.desktop", context.sbuild_pkg);
163163
fs::rename(out_path, final_path).unwrap();
164164
} else {
165-
self.logger.error(&format!(
165+
self.logger.warn(&format!(
166166
"Desktop file not found in {}. Skipping...",
167-
self.desktop
167+
out_path.display()
168168
));
169169
}
170170
}
@@ -174,11 +174,53 @@ impl Builder {
174174
self.logger.info(&format!("Using local file from {}", file));
175175
extract_filename(file)
176176
} else if let Some(ref dir) = icon.dir {
177-
// TODO: add fallbacks
178-
let out_path = format!("{}/.DirIcon", dir);
179-
self.logger
180-
.info(&format!("Using local file from {}", out_path));
181-
out_path
177+
let dir_path = Path::new(dir);
178+
179+
let find_diricon = |dir_path: &Path| -> Result<Option<String>, String> {
180+
for entry in fs::read_dir(dir_path)
181+
.map_err(|err| format!("Unable to search dir {}: {:#?}", dir, err))?
182+
{
183+
if let Ok(entry) = entry {
184+
let path = entry.path();
185+
if path.is_file() {
186+
if path.file_name() == Some(".DirIcon".as_ref()) {
187+
return Ok(Some(path.to_string_lossy().into_owned()));
188+
}
189+
}
190+
}
191+
}
192+
Ok(None)
193+
};
194+
195+
let found_path = find_diricon(dir_path)?.or_else(|| {
196+
for extension in ["png", "svg"] {
197+
for entry in fs::read_dir(dir_path).unwrap() {
198+
if let Ok(entry) = entry {
199+
let path = entry.path();
200+
if path.is_file() {
201+
if let Some(ext) = path
202+
.extension()
203+
.and_then(|ext| ext.to_str())
204+
.map(|s| s.to_lowercase())
205+
{
206+
if ext == extension {
207+
return Some(path.to_string_lossy().into_owned());
208+
}
209+
}
210+
}
211+
}
212+
}
213+
}
214+
None
215+
});
216+
217+
if let Some(found) = found_path {
218+
self.logger
219+
.info(&format!("Using local file from {}", found));
220+
found
221+
} else {
222+
format!("{}/.DirIcon", dir)
223+
}
182224
} else {
183225
let url = &icon.url.clone().unwrap();
184226
let out_path = extract_filename(url);
@@ -209,9 +251,9 @@ impl Builder {
209251
.warn(&format!("Unsupported icon. Moved to {}", tmp_path));
210252
}
211253
} else {
212-
self.logger.error(&format!(
213-
"Desktop file not found in {}. Skipping...",
214-
self.desktop
254+
self.logger.warn(&format!(
255+
"Icon not found in {}. Skipping...",
256+
out_path.display()
215257
));
216258
}
217259
}
@@ -289,24 +331,23 @@ impl Builder {
289331
// if the builder is invoked from soar, need to find a better way to install
290332
// build utils
291333
if self.external {
292-
let build_utils = build_config.build_util.clone().unwrap_or_default();
293-
let mut child = Command::new("soar")
294-
.env_clear()
295-
.envs(context.env_vars(&self.soar_env.bin_path))
296-
.args(["add".to_string()].iter().chain(build_utils.iter()))
297-
.stdout(Stdio::piped())
298-
.stderr(Stdio::piped())
299-
.stdin(Stdio::null())
300-
.spawn()
301-
.unwrap();
302-
303-
self.setup_cmd_logging(&mut child);
304-
305-
let status = child.wait().unwrap();
306-
if !status.success() {
307-
self.logger.error("Failed to install build utils");
308-
return false;
309-
}
334+
if let Some(build_utils) = build_config.build_util.clone() {
335+
let mut child = Command::new("soar")
336+
.env_clear()
337+
.envs(context.env_vars(&self.soar_env.bin_path))
338+
.args(["add".to_string()].iter().chain(build_utils.iter()))
339+
.stdout(Stdio::piped())
340+
.stderr(Stdio::piped())
341+
.stdin(Stdio::null())
342+
.spawn()
343+
.unwrap();
344+
self.setup_cmd_logging(&mut child);
345+
let status = child.wait().unwrap();
346+
if !status.success() {
347+
self.logger.error("Failed to install build utils");
348+
return false;
349+
}
350+
};
310351
}
311352

312353
if let Some(ref build_assets) = build_config.build_asset {

sbuild/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub async fn download<P: AsRef<Path>>(url: &str, out: P) -> Result<(), String> {
1919
.unwrap();
2020

2121
if !response.status().is_success() {
22-
return Err(format!("Error download build asset from {}", url));
22+
return Err(format!("Error downloading build asset from {}", url));
2323
}
2424

2525
let output_path = out.as_ref();

0 commit comments

Comments
 (0)