Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspace: fix pointer scanning, add duplicate prefix error #814

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading