Skip to content

Commit f984bc3

Browse files
committed
Cleanup find_object_base & better error handling
1 parent 8823c22 commit f984bc3

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/cmd/dol.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,13 +2065,26 @@ pub fn find_object_base(config: &ProjectConfig) -> Result<ObjectBase> {
20652065
if let Some(base) = &config.object_base {
20662066
let base = base.with_encoding();
20672067
// Search for disc images in the object base directory
2068-
for result in fs::read_dir(&base)? {
2069-
let entry = result?;
2070-
// Use fs::metadata to follow symlinks
2071-
if fs::metadata(entry.path())?.file_type().is_file() {
2072-
let path = check_path_buf(entry.path())?;
2068+
for result in fs::read_dir(&base).with_context(|| format!("Reading directory {}", base))? {
2069+
let entry = result.with_context(|| format!("Reading entry in directory {}", base))?;
2070+
let Ok(path) = check_path_buf(entry.path()) else {
2071+
log::warn!("Path is not valid UTF-8: {:?}", entry.path());
2072+
continue;
2073+
};
2074+
let file_type =
2075+
entry.file_type().with_context(|| format!("Getting file type for {}", path))?;
2076+
let is_file = if file_type.is_symlink() {
2077+
// Also traverse symlinks to files
2078+
fs::metadata(&path)
2079+
.with_context(|| format!("Getting metadata for {}", path))?
2080+
.is_file()
2081+
} else {
2082+
file_type.is_file()
2083+
};
2084+
if is_file {
20732085
let mut file = open_file(&path, false)?;
2074-
let format = nodtool::nod::Disc::detect(file.as_mut())?;
2086+
let format = nodtool::nod::Disc::detect(file.as_mut())
2087+
.with_context(|| format!("Detecting file type for {}", path))?;
20752088
if let Some(format) = format {
20762089
file.rewind()?;
20772090
let fs = open_fs(file, ArchiveKind::Disc(format))?;

0 commit comments

Comments
 (0)