mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Rename Vfs::inner to Vfs::data, use Self more
This commit is contained in:
@@ -28,7 +28,7 @@ use super::{
|
|||||||
pub struct Vfs<F> {
|
pub struct Vfs<F> {
|
||||||
/// A hierarchical map from paths to items that have been read or partially
|
/// A hierarchical map from paths to items that have been read or partially
|
||||||
/// read into memory by the Vfs.
|
/// read into memory by the Vfs.
|
||||||
inner: PathMap<VfsItem>,
|
data: PathMap<VfsItem>,
|
||||||
|
|
||||||
/// This Vfs's fetcher, which is used for all actual interactions with the
|
/// This Vfs's fetcher, which is used for all actual interactions with the
|
||||||
/// filesystem. It's referred to by the type parameter `F` all over, and is
|
/// filesystem. It's referred to by the type parameter `F` all over, and is
|
||||||
@@ -37,9 +37,9 @@ pub struct Vfs<F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F: VfsFetcher> Vfs<F> {
|
impl<F: VfsFetcher> Vfs<F> {
|
||||||
pub fn new(fetcher: F) -> Vfs<F> {
|
pub fn new(fetcher: F) -> Self {
|
||||||
Vfs {
|
Self {
|
||||||
inner: PathMap::new(),
|
data: PathMap::new(),
|
||||||
fetcher,
|
fetcher,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
.file_type(path)
|
.file_type(path)
|
||||||
.map_err(|err| FsError::new(err, path.to_path_buf()))?;
|
.map_err(|err| FsError::new(err, path.to_path_buf()))?;
|
||||||
|
|
||||||
match self.inner.get_mut(path) {
|
match self.data.get_mut(path) {
|
||||||
Some(existing_item) => {
|
Some(existing_item) => {
|
||||||
match (existing_item, &new_type) {
|
match (existing_item, &new_type) {
|
||||||
(VfsItem::File(existing_file), FileType::File) => {
|
(VfsItem::File(existing_file), FileType::File) => {
|
||||||
@@ -90,16 +90,16 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
self.fetcher.watch(path);
|
self.fetcher.watch(path);
|
||||||
}
|
}
|
||||||
(VfsItem::File(_), FileType::Directory) => {
|
(VfsItem::File(_), FileType::Directory) => {
|
||||||
self.inner.remove(path);
|
self.data.remove(path);
|
||||||
self.inner.insert(
|
self.data.insert(
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
VfsItem::new_from_type(FileType::Directory, path),
|
VfsItem::new_from_type(FileType::Directory, path),
|
||||||
);
|
);
|
||||||
self.fetcher.watch(path);
|
self.fetcher.watch(path);
|
||||||
}
|
}
|
||||||
(VfsItem::Directory(_), FileType::File) => {
|
(VfsItem::Directory(_), FileType::File) => {
|
||||||
self.inner.remove(path);
|
self.data.remove(path);
|
||||||
self.inner.insert(
|
self.data.insert(
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
VfsItem::new_from_type(FileType::File, path),
|
VfsItem::new_from_type(FileType::File, path),
|
||||||
);
|
);
|
||||||
@@ -108,7 +108,7 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.inner
|
self.data
|
||||||
.insert(path.to_path_buf(), VfsItem::new_from_type(new_type, path));
|
.insert(path.to_path_buf(), VfsItem::new_from_type(new_type, path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.inner.remove(path);
|
self.data.remove(path);
|
||||||
self.fetcher.unwatch(path);
|
self.fetcher.unwatch(path);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
pub fn get(&mut self, path: impl AsRef<Path>) -> FsResult<VfsEntry> {
|
pub fn get(&mut self, path: impl AsRef<Path>) -> FsResult<VfsEntry> {
|
||||||
self.read_if_not_exists(path.as_ref())?;
|
self.read_if_not_exists(path.as_ref())?;
|
||||||
|
|
||||||
let item = self.inner.get(path.as_ref()).unwrap();
|
let item = self.data.get(path.as_ref()).unwrap();
|
||||||
|
|
||||||
let is_file = match item {
|
let is_file = match item {
|
||||||
VfsItem::File(_) => true,
|
VfsItem::File(_) => true,
|
||||||
@@ -149,7 +149,7 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
|
|
||||||
self.read_if_not_exists(path)?;
|
self.read_if_not_exists(path)?;
|
||||||
|
|
||||||
match self.inner.get_mut(path).unwrap() {
|
match self.data.get_mut(path).unwrap() {
|
||||||
VfsItem::File(file) => {
|
VfsItem::File(file) => {
|
||||||
if file.contents.is_none() {
|
if file.contents.is_none() {
|
||||||
file.contents = Some(
|
file.contents = Some(
|
||||||
@@ -174,14 +174,14 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
|
|
||||||
self.read_if_not_exists(path)?;
|
self.read_if_not_exists(path)?;
|
||||||
|
|
||||||
match self.inner.get_mut(path).unwrap() {
|
match self.data.get_mut(path).unwrap() {
|
||||||
VfsItem::Directory(dir) => {
|
VfsItem::Directory(dir) => {
|
||||||
self.fetcher.watch(path);
|
self.fetcher.watch(path);
|
||||||
|
|
||||||
let enumerated = dir.children_enumerated;
|
let enumerated = dir.children_enumerated;
|
||||||
|
|
||||||
if enumerated {
|
if enumerated {
|
||||||
self.inner
|
self.data
|
||||||
.children(path)
|
.children(path)
|
||||||
.unwrap() // TODO: Handle None here, which means the PathMap entry did not exist.
|
.unwrap() // TODO: Handle None here, which means the PathMap entry did not exist.
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -219,12 +219,12 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
/// resident, we need to read it, and if its contents were known before, we
|
/// resident, we need to read it, and if its contents were known before, we
|
||||||
/// need to update them.
|
/// need to update them.
|
||||||
fn would_be_resident(&self, path: &Path) -> bool {
|
fn would_be_resident(&self, path: &Path) -> bool {
|
||||||
if self.inner.contains_key(path) {
|
if self.data.contains_key(path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
if let Some(VfsItem::Directory(dir)) = self.inner.get(parent) {
|
if let Some(VfsItem::Directory(dir)) = self.data.get(parent) {
|
||||||
return !dir.children_enumerated;
|
return !dir.children_enumerated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
/// be read. Depending on the `VfsFetcher` implementation that the `Vfs`
|
/// be read. Depending on the `VfsFetcher` implementation that the `Vfs`
|
||||||
/// is using, this call may read exactly only the given path and no more.
|
/// is using, this call may read exactly only the given path and no more.
|
||||||
fn read_if_not_exists(&mut self, path: &Path) -> FsResult<()> {
|
fn read_if_not_exists(&mut self, path: &Path) -> FsResult<()> {
|
||||||
if !self.inner.contains_key(path) {
|
if !self.data.contains_key(path) {
|
||||||
let kind = self
|
let kind = self
|
||||||
.fetcher
|
.fetcher
|
||||||
.file_type(path)
|
.file_type(path)
|
||||||
@@ -248,7 +248,7 @@ impl<F: VfsFetcher> Vfs<F> {
|
|||||||
self.fetcher.watch(path);
|
self.fetcher.watch(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.inner
|
self.data
|
||||||
.insert(path.to_path_buf(), VfsItem::new_from_type(kind, path));
|
.insert(path.to_path_buf(), VfsItem::new_from_type(kind, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +273,7 @@ impl<F: VfsFetcher> VfsDebug for Vfs<F> {
|
|||||||
|
|
||||||
match snapshot {
|
match snapshot {
|
||||||
VfsSnapshot::File(file) => {
|
VfsSnapshot::File(file) => {
|
||||||
self.inner.insert(
|
self.data.insert(
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
VfsItem::File(VfsFile {
|
VfsItem::File(VfsFile {
|
||||||
path: path.to_path_buf(),
|
path: path.to_path_buf(),
|
||||||
@@ -282,7 +282,7 @@ impl<F: VfsFetcher> VfsDebug for Vfs<F> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
VfsSnapshot::Directory(directory) => {
|
VfsSnapshot::Directory(directory) => {
|
||||||
self.inner.insert(
|
self.data.insert(
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
VfsItem::Directory(VfsDirectory {
|
VfsItem::Directory(VfsDirectory {
|
||||||
path: path.to_path_buf(),
|
path: path.to_path_buf(),
|
||||||
@@ -298,30 +298,30 @@ impl<F: VfsFetcher> VfsDebug for Vfs<F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn debug_is_file(&self, path: &Path) -> bool {
|
fn debug_is_file(&self, path: &Path) -> bool {
|
||||||
match self.inner.get(path) {
|
match self.data.get(path) {
|
||||||
Some(VfsItem::File(_)) => true,
|
Some(VfsItem::File(_)) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_contents<'a>(&'a self, path: &Path) -> Option<&'a [u8]> {
|
fn debug_contents<'a>(&'a self, path: &Path) -> Option<&'a [u8]> {
|
||||||
match self.inner.get(path) {
|
match self.data.get(path) {
|
||||||
Some(VfsItem::File(file)) => file.contents.as_ref().map(|vec| vec.as_slice()),
|
Some(VfsItem::File(file)) => file.contents.as_ref().map(|vec| vec.as_slice()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_children<'a>(&'a self, path: &Path) -> Option<(bool, Vec<&'a Path>)> {
|
fn debug_children<'a>(&'a self, path: &Path) -> Option<(bool, Vec<&'a Path>)> {
|
||||||
match self.inner.get(path) {
|
match self.data.get(path) {
|
||||||
Some(VfsItem::Directory(dir)) => {
|
Some(VfsItem::Directory(dir)) => {
|
||||||
Some((dir.children_enumerated, self.inner.children(path).unwrap()))
|
Some((dir.children_enumerated, self.data.children(path).unwrap()))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_orphans(&self) -> Vec<&Path> {
|
fn debug_orphans(&self) -> Vec<&Path> {
|
||||||
self.inner.orphans().collect()
|
self.data.orphans().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_watched_paths(&self) -> Vec<&Path> {
|
fn debug_watched_paths(&self) -> Vec<&Path> {
|
||||||
|
|||||||
Reference in New Issue
Block a user