Skip to content

Commit 58bf99d

Browse files
committed
Change path_exists_case_sensitive to return bool
1 parent dcd2aa4 commit 58bf99d

File tree

7 files changed

+25
-28
lines changed

7 files changed

+25
-28
lines changed

crates/red_knot_python_semantic/src/module_resolver/resolver.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ fn resolve_file_module(module: &ModulePath, resolver_state: &ResolverContext) ->
621621
if !system.case_sensitivity().is_case_sensitive()
622622
&& !system
623623
.path_exists_case_sensitive(path, module.search_path().as_system_path().unwrap())
624-
.unwrap_or(true)
625624
{
626625
return None;
627626
}

crates/red_knot_server/src/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl System for LSPSystem {
136136
self.os_system.canonicalize_path(path)
137137
}
138138

139-
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> Result<bool> {
139+
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> bool {
140140
self.os_system.path_exists_case_sensitive(path, prefix)
141141
}
142142

crates/red_knot_test/src/db.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,7 @@ impl System for MdtestSystem {
211211
self.as_system().read_virtual_path_to_notebook(path)
212212
}
213213

214-
fn path_exists_case_sensitive(
215-
&self,
216-
path: &SystemPath,
217-
prefix: &SystemPath,
218-
) -> ruff_db::system::Result<bool> {
214+
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> bool {
219215
self.as_system()
220216
.path_exists_case_sensitive(&self.normalize_path(path), &self.normalize_path(prefix))
221217
}

crates/red_knot_wasm/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,8 @@ impl System for WasmSystem {
260260
Err(ruff_notebook::NotebookError::Io(not_found()))
261261
}
262262

263-
fn path_exists_case_sensitive(
264-
&self,
265-
path: &SystemPath,
266-
_prefix: &SystemPath,
267-
) -> ruff_db::system::Result<bool> {
268-
Ok(self.path_exists(path))
263+
fn path_exists_case_sensitive(&self, path: &SystemPath, _prefix: &SystemPath) -> bool {
264+
self.path_exists(path)
269265
}
270266

271267
fn case_sensitivity(&self) -> CaseSensitivity {

crates/ruff_db/src/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub trait System: Debug {
9898
/// Prefix is only intended as an optimization for systems that can't efficiently check
9999
/// if an entire path exists with the exact casing as specified in `path`. However,
100100
/// implementations are allowed to check the casing of the entire path if they can do so efficiently.
101-
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> Result<bool>;
101+
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> bool;
102102

103103
/// Returns the [`CaseSensitivity`] of the system's file system.
104104
fn case_sensitivity(&self) -> CaseSensitivity;

crates/ruff_db/src/system/os.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ impl System for OsSystem {
115115
path.as_std_path().exists()
116116
}
117117

118-
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> Result<bool> {
118+
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> bool {
119119
if self.case_sensitivity().is_case_sensitive() {
120-
Ok(self.path_exists(path))
120+
self.path_exists(path)
121121
} else {
122122
self.path_exists_case_sensitive_fast(path)
123-
.map(Ok)
124123
.unwrap_or_else(|| self.path_exists_case_sensitive_slow(path, prefix))
125124
}
126125
}
@@ -276,23 +275,30 @@ impl OsSystem {
276275
Some(simplified_canonicalized == simplified)
277276
}
278277

279-
fn path_exists_case_sensitive_slow(
280-
&self,
281-
path: &SystemPath,
282-
prefix: &SystemPath,
283-
) -> Result<bool> {
278+
fn path_exists_case_sensitive_slow(&self, path: &SystemPath, prefix: &SystemPath) -> bool {
284279
// Iterate over the sub-paths up to prefix and check if they match the casing as on disk.
285280
for ancestor in path.ancestors() {
286281
if ancestor == prefix {
287282
break;
288283
}
289284

290-
if !self.inner.real_case_cache.has_name_case(ancestor)? {
291-
return Ok(false);
285+
match self.inner.real_case_cache.has_name_case(ancestor) {
286+
Ok(true) => {
287+
// Component has correct casing, continue with next component
288+
}
289+
Ok(false) => {
290+
// Component has incorrect casing
291+
return false;
292+
}
293+
Err(_) => {
294+
// Directory doesn't exist or can't be accessed. We can assume that the file with
295+
// the given casing doesn't exist.
296+
return false;
297+
}
292298
}
293299
}
294300

295-
Ok(true)
301+
true
296302
}
297303
}
298304

crates/ruff_db/src/system/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl System for TestSystem {
131131
self
132132
}
133133

134-
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> Result<bool> {
134+
fn path_exists_case_sensitive(&self, path: &SystemPath, prefix: &SystemPath) -> bool {
135135
self.system().path_exists_case_sensitive(path, prefix)
136136
}
137137

@@ -359,9 +359,9 @@ impl System for InMemorySystem {
359359
}
360360

361361
#[inline]
362-
fn path_exists_case_sensitive(&self, path: &SystemPath, _prefix: &SystemPath) -> Result<bool> {
362+
fn path_exists_case_sensitive(&self, path: &SystemPath, _prefix: &SystemPath) -> bool {
363363
// The memory file system is case-sensitive.
364-
Ok(self.path_exists(path))
364+
self.path_exists(path)
365365
}
366366

367367
fn case_sensitivity(&self) -> CaseSensitivity {

0 commit comments

Comments
 (0)