Skip to content

Commit

Permalink
fix pointer scanning, add duplicate prefix error (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Oct 24, 2024
1 parent 8216250 commit 6b99d9f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
3 changes: 3 additions & 0 deletions libs/common/src/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ pub enum Error {
#[error("Invalid prefix: {0}")]
/// Invalid prefix
InvalidPrefix(String),
#[error("Duplicate prefix: {0}")]
/// Duplicate prefix
DuplicatePrefix(String),
}

#[cfg(test)]
Expand Down
58 changes: 36 additions & 22 deletions libs/workspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,45 @@ impl Workspace {
}

fn discover(&mut self) -> Result<(), Error> {
for entry in self.vfs.walk_dir()? {
let Ok(entry) = entry else {
trace!("unknown issue with entry: {:?}", entry);
continue;
};
if entry.as_str().contains(".hemtt") {
for root in &["include", "optionals", "addons"] {
let root = self.vfs.join(root)?;
if !root.exists()? {
continue;
}
match entry.filename().to_lowercase().as_str() {
"config.cpp" => {
trace!("config.cpp: {:?}", entry);
self.addons.push(entry);
}
"mission.sqm" => {
trace!("mission.sqm: {:?}", entry);
self.missions.push(entry);
for entry in root.walk_dir()? {
let Ok(entry) = entry else {
trace!("unknown issue with entry: {:?}", entry);
continue;
};
if entry.as_str().contains(".hemtt") {
continue;
}
_ => {
if FILES.contains(&entry.filename().to_lowercase().as_str()) {
trace!("Prefix: {:?}", entry);
let prefix = Prefix::new(&entry.read_to_string()?)?;
self.pointers.insert(
format!("/{}", prefix.to_string().to_lowercase().replace('\\', "/")),
entry.parent(),
);
match entry.filename().to_lowercase().as_str() {
"config.cpp" => {
trace!("config.cpp: {:?}", entry);
self.addons.push(entry);
}
"mission.sqm" => {
trace!("mission.sqm: {:?}", entry);
self.missions.push(entry);
}
_ => {
if FILES.contains(&entry.filename().to_lowercase().as_str()) {
trace!("Prefix: {:?}", entry);
let prefix = Prefix::new(&entry.read_to_string()?)?;
let prefix_str = format!(
"/{}",
prefix.to_string().to_lowercase().replace('\\', "/")
);
if self.pointers.contains_key(&prefix_str) {
return Err(Error::Prefix(
hemtt_common::prefix::Error::DuplicatePrefix(
prefix.to_string(),
),
));
}
self.pointers.insert(prefix_str, entry.parent());
}
}
}
}
Expand Down

0 comments on commit 6b99d9f

Please sign in to comment.