Skip to content

Commit a5778a8

Browse files
committed
Fix import_graph depth/cycle tests and windows locking
1 parent 742adeb commit a5778a8

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

lib/src/api.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,14 @@ impl OntoEnv {
11411141
}
11421142
// if location is a file, add it to the list
11431143
if resolved.is_file() && self.config.is_included(&resolved) {
1144-
files.insert(OntologyLocation::File(resolved.clone()));
1144+
if let Err(err) = std::fs::File::open(&resolved) {
1145+
if self.config.strict {
1146+
return Err(err.into());
1147+
}
1148+
warn!("Skipping {:?} due to access error: {}", resolved, err);
1149+
} else {
1150+
files.insert(OntologyLocation::File(resolved.clone()));
1151+
}
11451152
continue;
11461153
}
11471154
for entry in walkdir::WalkDir::new(&resolved) {
@@ -1160,6 +1167,18 @@ impl OntoEnv {
11601167
}
11611168
};
11621169
if entry.file_type().is_file() && self.config.is_included(entry.path()) {
1170+
// Skip unreadable files when not strict
1171+
if let Err(err) = std::fs::File::open(entry.path()) {
1172+
if self.config.strict {
1173+
return Err(err.into());
1174+
}
1175+
warn!(
1176+
"Skipping {:?} due to access error while opening: {}",
1177+
entry.path(),
1178+
err
1179+
);
1180+
continue;
1181+
}
11631182
files.insert(OntologyLocation::File(entry.path().to_path_buf()));
11641183
}
11651184
}

lib/tests/test_ontoenv.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ fn import_graph_handles_cycles() -> Result<()> {
219219

220220
let a_path = dir.path().join("A.ttl");
221221
let b_path = dir.path().join("B.ttl");
222-
let a_iri = format!("file://{}", a_path.display());
223-
let b_iri = format!("file://{}", b_path.display());
222+
let a_iri = url::Url::from_file_path(&a_path).unwrap().to_string();
223+
let b_iri = url::Url::from_file_path(&b_path).unwrap().to_string();
224224

225225
fs::write(
226226
&a_path,
@@ -307,9 +307,9 @@ fn import_graph_respects_recursion_depth() -> Result<()> {
307307
let b_path = dir.path().join("B.ttl");
308308
let c_path = dir.path().join("C.ttl");
309309

310-
let a_iri = format!("file://{}", a_path.display());
311-
let b_iri = format!("file://{}", b_path.display());
312-
let c_iri = format!("file://{}", c_path.display());
310+
let a_iri = url::Url::from_file_path(&a_path).unwrap().to_string();
311+
let b_iri = url::Url::from_file_path(&b_path).unwrap().to_string();
312+
let c_iri = url::Url::from_file_path(&c_path).unwrap().to_string();
313313

314314
fs::write(
315315
&a_path,

0 commit comments

Comments
 (0)