Skip to content

Commit 5700a73

Browse files
committed
fix: remove sfs root directory override on "new"
1 parent 1dbaf42 commit 5700a73

File tree

1 file changed

+1
-74
lines changed

1 file changed

+1
-74
lines changed

src/addon/static_file/scoped_file_system.rs

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
//! The `Entry` is a wrapper on OS file system entries such as `File` and
99
//! `Directory`. Both `File` and `Directory` are primitive types for
1010
//! `ScopedFileSystem`
11-
use anyhow::Context;
1211
use anyhow::Result;
13-
use std::env::current_dir;
1412
use std::path::{Component, Path, PathBuf};
1513
use tokio::fs::OpenOptions;
1614

@@ -51,24 +49,7 @@ impl ScopedFileSystem {
5149
///
5250
/// Provided paths will resolve relartive to the provided `root` directory.
5351
pub fn new(root: PathBuf) -> Result<Self> {
54-
let root_string = root.to_str().unwrap();
55-
let mut cwd = current_dir().context(
56-
"Failed to gather current working directory when instancing a new ScopedFileSystem",
57-
)?;
58-
59-
if root_string == "/"
60-
|| root_string.is_empty()
61-
|| root_string.starts_with('/')
62-
|| root_string.starts_with('\\')
63-
{
64-
// if the provided string is either "/" or "", the root directory
65-
// will be the current working directory (CWD)
66-
return Ok(ScopedFileSystem { root: cwd });
67-
}
68-
69-
cwd.push(root_string);
70-
71-
Ok(ScopedFileSystem { root: cwd })
52+
Ok(ScopedFileSystem { root })
7253
}
7354

7455
/// Resolves the provided path against the root directory of this
@@ -138,16 +119,6 @@ mod tests {
138119
#[allow(unused_imports)]
139120
use super::*;
140121

141-
#[test]
142-
fn creates_new_sfs() {
143-
let sfs = ScopedFileSystem::new(PathBuf::from("assets")).unwrap();
144-
let mut expect = current_dir().unwrap();
145-
146-
expect.push("assets");
147-
148-
assert_eq!(sfs.root, expect);
149-
}
150-
151122
#[test]
152123
fn builds_a_relative_path_to_root_from_provided_path() {
153124
let sfs = ScopedFileSystem::new(PathBuf::from("")).unwrap();
@@ -187,38 +158,6 @@ mod tests {
187158
assert_ne!(sfs.root, resolved_path);
188159
}
189160

190-
#[test]
191-
fn serves_cwd_whenever_the_path_begins_with_slash() {
192-
let sfs = ScopedFileSystem::new(PathBuf::from("/assets")).unwrap();
193-
let expect = current_dir().unwrap();
194-
195-
assert_eq!(sfs.root, expect);
196-
}
197-
198-
#[test]
199-
fn creates_sfs_with_cwd_using_forward_slash() {
200-
let sfs = ScopedFileSystem::new(PathBuf::from("/")).unwrap();
201-
let cwd = current_dir().unwrap();
202-
203-
assert_eq!(sfs.root, cwd);
204-
}
205-
206-
#[test]
207-
fn creates_sfs_with_cwd_using_empty_string() {
208-
let sfs = ScopedFileSystem::new(PathBuf::from("")).unwrap();
209-
let cwd = current_dir().unwrap();
210-
211-
assert_eq!(sfs.root, cwd);
212-
}
213-
214-
#[test]
215-
fn creates_sfs_with_cwd_using_dot() {
216-
let sfs = ScopedFileSystem::new(PathBuf::from(".")).unwrap();
217-
let cwd = current_dir().unwrap();
218-
219-
assert_eq!(sfs.root, cwd);
220-
}
221-
222161
#[test]
223162
fn normalizes_an_arbitrary_path() {
224163
let arbitrary_path = PathBuf::from("docs/collegue/cs50/lectures/../code/voting_excecise");
@@ -267,16 +206,4 @@ mod tests {
267206

268207
assert_eq!(resolved_entry.is_err(), true);
269208
}
270-
271-
#[tokio::test]
272-
async fn resolves_root_to_instance_root_dir() {
273-
let sfs = ScopedFileSystem::new(PathBuf::from("")).unwrap();
274-
let resolved_entry = sfs.resolve(PathBuf::from("/")).await.unwrap();
275-
276-
if let Entry::Directory(dir) = resolved_entry {
277-
assert_eq!(dir.path, sfs.root);
278-
} else {
279-
panic!("Expected a directory, but a file was received instead");
280-
}
281-
}
282209
}

0 commit comments

Comments
 (0)