|
8 | 8 | //! The `Entry` is a wrapper on OS file system entries such as `File` and |
9 | 9 | //! `Directory`. Both `File` and `Directory` are primitive types for |
10 | 10 | //! `ScopedFileSystem` |
11 | | -use anyhow::Context; |
12 | 11 | use anyhow::Result; |
13 | | -use std::env::current_dir; |
14 | 12 | use std::path::{Component, Path, PathBuf}; |
15 | 13 | use tokio::fs::OpenOptions; |
16 | 14 |
|
@@ -51,24 +49,7 @@ impl ScopedFileSystem { |
51 | 49 | /// |
52 | 50 | /// Provided paths will resolve relartive to the provided `root` directory. |
53 | 51 | 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 }) |
72 | 53 | } |
73 | 54 |
|
74 | 55 | /// Resolves the provided path against the root directory of this |
@@ -138,16 +119,6 @@ mod tests { |
138 | 119 | #[allow(unused_imports)] |
139 | 120 | use super::*; |
140 | 121 |
|
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 | | - |
151 | 122 | #[test] |
152 | 123 | fn builds_a_relative_path_to_root_from_provided_path() { |
153 | 124 | let sfs = ScopedFileSystem::new(PathBuf::from("")).unwrap(); |
@@ -187,38 +158,6 @@ mod tests { |
187 | 158 | assert_ne!(sfs.root, resolved_path); |
188 | 159 | } |
189 | 160 |
|
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 | | - |
222 | 161 | #[test] |
223 | 162 | fn normalizes_an_arbitrary_path() { |
224 | 163 | let arbitrary_path = PathBuf::from("docs/collegue/cs50/lectures/../code/voting_excecise"); |
@@ -267,16 +206,4 @@ mod tests { |
267 | 206 |
|
268 | 207 | assert_eq!(resolved_entry.is_err(), true); |
269 | 208 | } |
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 | | - } |
282 | 209 | } |
0 commit comments