mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 11:24:35 +00:00
Change File::touch_path
to only take a SystemPath
(#12273)
This commit is contained in:
parent
e8b5341c97
commit
abcf07c8c5
4 changed files with 29 additions and 28 deletions
|
@ -5,7 +5,7 @@ use salsa::{Cancelled, Database};
|
||||||
|
|
||||||
use red_knot_module_resolver::{vendored_typeshed_stubs, Db as ResolverDb, Jar as ResolverJar};
|
use red_knot_module_resolver::{vendored_typeshed_stubs, Db as ResolverDb, Jar as ResolverJar};
|
||||||
use red_knot_python_semantic::{Db as SemanticDb, Jar as SemanticJar};
|
use red_knot_python_semantic::{Db as SemanticDb, Jar as SemanticJar};
|
||||||
use ruff_db::files::{File, FilePath, Files};
|
use ruff_db::files::{File, Files};
|
||||||
use ruff_db::system::{System, SystemPathBuf};
|
use ruff_db::system::{System, SystemPathBuf};
|
||||||
use ruff_db::vendored::VendoredFileSystem;
|
use ruff_db::vendored::VendoredFileSystem;
|
||||||
use ruff_db::{Db as SourceDb, Jar as SourceJar, Upcast};
|
use ruff_db::{Db as SourceDb, Jar as SourceJar, Upcast};
|
||||||
|
@ -41,7 +41,7 @@ impl Program {
|
||||||
I: IntoIterator<Item = FileWatcherChange>,
|
I: IntoIterator<Item = FileWatcherChange>,
|
||||||
{
|
{
|
||||||
for change in changes {
|
for change in changes {
|
||||||
File::touch_path(self, &FilePath::system(change.path));
|
File::touch_path(self, &change.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1002,7 +1002,7 @@ mod tests {
|
||||||
db.memory_file_system().remove_file(&foo_init_path)?;
|
db.memory_file_system().remove_file(&foo_init_path)?;
|
||||||
db.memory_file_system()
|
db.memory_file_system()
|
||||||
.remove_directory(foo_init_path.parent().unwrap())?;
|
.remove_directory(foo_init_path.parent().unwrap())?;
|
||||||
File::touch_path(&mut db, &FilePath::System(foo_init_path));
|
File::touch_path(&mut db, &foo_init_path);
|
||||||
|
|
||||||
let foo_module = resolve_module(&db, foo_module_name).expect("Foo module to resolve");
|
let foo_module = resolve_module(&db, foo_module_name).expect("Foo module to resolve");
|
||||||
assert_eq!(&src.join("foo.py"), foo_module.file().path(&db));
|
assert_eq!(&src.join("foo.py"), foo_module.file().path(&db));
|
||||||
|
|
|
@ -206,19 +206,25 @@ impl File {
|
||||||
/// Refreshes the file metadata by querying the file system if needed.
|
/// Refreshes the file metadata by querying the file system if needed.
|
||||||
/// TODO: The API should instead take all observed changes from the file system directly
|
/// TODO: The API should instead take all observed changes from the file system directly
|
||||||
/// and then apply the VfsFile status accordingly. But for now, this is sufficient.
|
/// and then apply the VfsFile status accordingly. But for now, this is sufficient.
|
||||||
pub fn touch_path(db: &mut dyn Db, path: &FilePath) {
|
pub fn touch_path(db: &mut dyn Db, path: &SystemPath) {
|
||||||
Self::touch_impl(db, path, None);
|
Self::touch_impl(db, path, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn touch(self, db: &mut dyn Db) {
|
pub fn touch(self, db: &mut dyn Db) {
|
||||||
let path = self.path(db).clone();
|
let path = self.path(db).clone();
|
||||||
Self::touch_impl(db, &path, Some(self));
|
|
||||||
|
match path {
|
||||||
|
FilePath::System(system) => {
|
||||||
|
Self::touch_impl(db, &system, Some(self));
|
||||||
|
}
|
||||||
|
FilePath::Vendored(_) => {
|
||||||
|
// Readonly, can never be out of date.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Private method providing the implementation for [`Self::touch_path`] and [`Self::touch`].
|
/// Private method providing the implementation for [`Self::touch_path`] and [`Self::touch`].
|
||||||
fn touch_impl(db: &mut dyn Db, path: &FilePath, file: Option<File>) {
|
fn touch_impl(db: &mut dyn Db, path: &SystemPath, file: Option<File>) {
|
||||||
match path {
|
|
||||||
FilePath::System(path) => {
|
|
||||||
let metadata = db.system().path_metadata(path);
|
let metadata = db.system().path_metadata(path);
|
||||||
|
|
||||||
let (status, revision) = match metadata {
|
let (status, revision) = match metadata {
|
||||||
|
@ -235,11 +241,6 @@ impl File {
|
||||||
file.set_status(db).to(status);
|
file.set_status(db).to(status);
|
||||||
file.set_revision(db).to(revision);
|
file.set_revision(db).to(revision);
|
||||||
}
|
}
|
||||||
FilePath::Vendored(_) => {
|
|
||||||
// Readonly, can never be out of date.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The types in here need to be public because they're salsa ingredients but we
|
// The types in here need to be public because they're salsa ingredients but we
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::files::{File, FilePath};
|
use crate::files::File;
|
||||||
use crate::system::{MemoryFileSystem, Metadata, OsSystem, System, SystemPath};
|
use crate::system::{MemoryFileSystem, Metadata, OsSystem, System, SystemPath};
|
||||||
use crate::Db;
|
use crate::Db;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
@ -104,14 +104,14 @@ pub trait DbWithTestSystem: Db + Sized {
|
||||||
path: impl AsRef<SystemPath>,
|
path: impl AsRef<SystemPath>,
|
||||||
content: impl ToString,
|
content: impl ToString,
|
||||||
) -> crate::system::Result<()> {
|
) -> crate::system::Result<()> {
|
||||||
let path = path.as_ref().to_path_buf();
|
let path = path.as_ref();
|
||||||
let result = self
|
let result = self
|
||||||
.test_system()
|
.test_system()
|
||||||
.memory_file_system()
|
.memory_file_system()
|
||||||
.write_file(&path, content);
|
.write_file(path, content);
|
||||||
|
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
File::touch_path(self, &FilePath::System(path));
|
File::touch_path(self, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue