Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 1 | //! Lazy workspaces (`on get --lazy`, Linux): the workspace folder is a |
| 2 | //! FUSE mount that shows the change's whole tree at once and fetches a file |
| 3 | //! from the host the first time it's opened. What's written goes to a real |
| 4 | //! folder, the workspace's backing (ONSET_HOME/lazy/<workspace>), which the |
| 5 |
| 6 | //! gone. Saves read the workspace like any other: its index starts with |
| 7 | //! every file in the tree, at the sizes and times the mount shows them, so |
| 8 | //! only what changed is read. `on mount` starts the mount again (after a |
| 9 | //! restart, say); any Onset command run in the folder does that too. |
| 10 |
| 11 | use std::path::{Path, PathBuf}; |
| 12 |
| 13 | use anyhow::{Result, anyhow}; |
| 14 |
| 15 | use crate::app::App; |
| 16 | use crate::db::Workspace; |
| 17 | use crate::paths; |
| 18 | use crate::ws; |
| 19 |
| 20 | /// The time a file the mount hasn't fetched yet shows (2000-01-01), in ns. |
| 21 | pub const MTIME_NS: i64 = 946_684_800_123_456_789; |
| 22 |
| 23 | /// Where a lazy workspace's own files are. |
| 24 | pub fn backing(workspace: &str) -> PathBuf { |
| 25 | paths::home().join("lazy").join(workspace) |
| 26 | } |
| 27 |
| 28 | pub fn is_lazy(workspace: &str) -> bool { |
| 29 | ws::is_workspace(&backing(workspace)) |
| 30 | } |
| 31 |
| 32 | /// The inode number a path starts with, the same each time the mount |
| 33 | /// starts, as the index records it. |
| 34 | pub fn ino(path: &str) -> u64 { |
| 35 | if path.is_empty() { |
| 36 | return 1; |
| 37 | } |
| 38 | let id = onset_core::id::sha256(&[b"vcs inode\n", path.as_bytes()]); |
| 39 | u64::from_le_bytes(id.0[..8].try_into().unwrap_or_default()).max(2) |
| 40 | } |
| 41 |
| 42 | /// Whether something is mounted at `root`. |
| 43 | pub fn mounted(root: &Path) -> bool { |
| 44 | let Ok(info) = std::fs::read_to_string("/proc/self/mountinfo") else { return false }; |
| 45 | let want = root.to_string_lossy(); |
| 46 | // Field 5 is the mount point, with spaces and such as octal escapes. |
| 47 | info.lines().any(|line| line.split(' ').nth(4).is_some_and(|m| unescape(m) == want)) |
| 48 | } |
| 49 |
| 50 | fn unescape(text: &str) -> String { |
| 51 | let bytes = text.as_bytes(); |
| 52 | let mut out = Vec::with_capacity(bytes.len()); |
| 53 | let mut i = 0; |
| 54 | while i < bytes.len() { |
| 55 | if bytes[i] == b'\\' |
| 56 | && i + 3 < bytes.len() |
| 57 | && let Ok(n) = u8::from_str_radix(&text[i + 1..i + 4], 8) |
| 58 | { |
| 59 | out.push(n); |
| 60 | i += 4; |
| 61 | } else { |
| 62 | out.push(bytes[i]); |
| 63 | i += 1; |
| 64 | } |
| 65 | } |
| 66 | String::from_utf8_lossy(&out).into_owned() |
| 67 | } |
| 68 |
| 69 | /// The lazy workspace whose folder is `root` or holds it (this machine's). |
| 70 | pub fn workspace_at(app: &App, root: &Path) -> Result<Option<Workspace>> { |
| 71 | Ok(app.db.all_workspaces()?.into_iter().filter(|w| root.starts_with(&w.path) && is_lazy(&w.id)).max_by_key(|w| w.path.as_os_str().len())) |
| 72 | } |
| 73 |
| 74 | /// Starts the mount for a lazy workspace, if it isn't running: `on mount |
| 75 | /// --serve` in the background, and back once the folder shows the tree. |
| 76 | pub fn mount(w: &Workspace) -> Result<()> { |
| 77 | if mounted(&w.path) { |
| 78 | return Ok(()); |
| 79 | } |
| 80 | std::fs::create_dir_all(&w.path)?; |
| 81 | let log = backing(&w.id).join(ws::DIR).join("mount.log"); |
| 82 | let out = std::fs::File::create(&log)?; |
| 83 | let mut command = std::process::Command::new(std::env::current_exe()?); |
| 84 | command.arg("mount").arg("--serve").arg(&w.path).stdin(std::process::Stdio::null()).stdout(out.try_clone()?).stderr(out); |
| 85 | #[cfg(unix)] |
| 86 | { |
| 87 | use std::os::unix::process::CommandExt; |
| 88 | command.process_group(0); |
| 89 | } |
| 90 | let mut child = command.spawn()?; |
| 91 | for _ in 0..200 { |
| 92 | if mounted(&w.path) { |
| 93 | return Ok(()); |
| 94 | } |
| 95 | if let Ok(Some(status)) = child.try_wait() { |
| 96 | let said = std::fs::read_to_string(&log).unwrap_or_default(); |
| 97 | return Err(anyhow!("the mount at {} stopped ({status}): {}", w.path.display(), said.trim())); |
| 98 | } |
| 99 | std::thread::sleep(std::time::Duration::from_millis(50)); |
| 100 | } |
| 101 | Err(anyhow!("the mount at {} didn't start; see {}", w.path.display(), log.display())) |
| 102 | } |
| 103 |
| 104 | /// Stops a lazy workspace's mount (its backing keeps everything). |
| 105 | pub fn unmount(root: &Path) -> Result<()> { |
| 106 | if !mounted(root) { |
| 107 | return Ok(()); |
| 108 | } |
| 109 | for tool in ["fusermount3", "fusermount"] { |
| 110 | if std::process::Command::new(tool).arg("-u").arg(root).status().is_ok_and(|s| s.success()) { |
| 111 | return Ok(()); |
| 112 | } |
| 113 | } |
| 114 | Err(anyhow!("couldn't unmount {} (is something still using it?)", root.display())) |
| 115 | } |
| 116 |
| 117 | /// `on mount [folder] [--stop]`: a lazy workspace's mount, started again or stopped. |
| 118 | pub fn run(app: &App, folder: Option<PathBuf>, stop: bool, serve_now: bool) -> crate::out::Out { |
| 119 | use crate::out::{Fail, Report}; |
| 120 | let path = crate::sys::canonical(&app.cwd.join(folder.unwrap_or_else(|| PathBuf::from(".")))).map_err(|e| Fail::new("not_found", e.to_string()))?; |
| 121 | if serve_now { |
| 122 | serve(app, &path)?; |
| 123 | return Ok(Report::new()); |
| 124 | } |
| 125 | let w = workspace_at(app, &path)?.ok_or_else(|| { |
| 126 | Fail::new("not_found", format!("{} isn't a lazy workspace", path.display())).state("nothing changed").next("on get <project> <folder> --lazy makes one") |
| 127 | })?; |
| 128 | let mut r = Report::new(); |
| 129 | if stop { |
| 130 | unmount(&w.path)?; |
| 131 | r.line("stopped", format!("{} (its work is kept; on mount starts it again)", w.path.display())); |
| 132 | } else { |
| 133 | mount(&w)?; |
| 134 | r.line("mounted", w.path.display().to_string()); |
| 135 | } |
| 136 | r.set("workspace", w.path.display().to_string()).set("mounted", !stop); |
| 137 | Ok(r) |
| 138 | } |
| 139 |
| 140 | #[cfg(target_os = "linux")] |
| 141 | pub use mount_fs::{prepare, serve}; |
| 142 |
| 143 | #[cfg(not(target_os = "linux"))] |
| 144 | pub fn prepare(_app: &App, _project: &crate::db::Project, _workspace: &str, _tree: &onset_core::Id) -> Result<ws::Index> { |
| 145 | Err(anyhow!("lazy workspaces need Linux for now (macOS comes with FSKit)")) |
| 146 | } |
| 147 |
| 148 | #[cfg(not(target_os = "linux"))] |
| 149 | pub fn serve(_app: &App, _root: &Path) -> Result<()> { |
| 150 | Err(anyhow!("lazy workspaces need Linux for now (macOS comes with FSKit)")) |
| 151 | } |
| 152 |
| 153 | #[cfg(target_os = "linux")] |
| 154 | mod mount_fs { |
| 155 | use std::collections::{BTreeMap, BTreeSet, HashMap}; |
| 156 | use std::ffi::{CString, OsStr}; |
| 157 | use std::fs; |
| 158 | use std::os::unix::ffi::OsStrExt; |
| 159 | use std::os::unix::fs::{FileExt, MetadataExt, OpenOptionsExt, PermissionsExt}; |
| 160 | use std::path::{Path, PathBuf}; |
| 161 | use std::sync::Mutex; |
| 162 | use std::time::{Duration, SystemTime, UNIX_EPOCH}; |
| 163 |
| 164 | use anyhow::{Result, anyhow}; |
| 165 | use fuser::{ |
| 166 | AccessFlags, Config, Errno, FileAttr, FileHandle, FileType, Filesystem, FopenFlags, Generation, INodeNo, LockOwner, MountOption, OpenFlags, RenameFlags, ReplyAttr, |
| 167 | ReplyCreate, ReplyData, ReplyDirectory, ReplyEmpty, ReplyEntry, ReplyOpen, ReplyStatfs, ReplyWrite, Request, TimeOrNow, WriteFlags, |
| 168 | }; |
| 169 | use serde::Deserialize; |
| 170 | use serde_json::json; |
| 171 | use onset_core::Id; |
| 172 | use onset_core::tree::{self, Entry, EntryKind}; |
| 173 |
| 174 | use super::{MTIME_NS, backing, ino}; |
| 175 | use crate::app::App; |
| 176 | use crate::db::Project; |
| 177 | use crate::objects::Store; |
| 178 | use crate::remote::Remote; |
| 179 | use crate::ws::{self, Index, IndexEntry, Stat}; |
| 180 |
| 181 | /// Makes workspace `workspace` a lazy one of `tree`: its folders and its |
| 182 | /// files' sizes from the host, and the index the mount matches. Answers |
| 183 | /// that index (the workspace's first). |
| 184 | pub fn prepare(app: &App, project: &Project, workspace: &str, tree: &Id) -> Result<Index> { |
| 185 | let remote = Remote::for_project(project); |
| 186 | app.store.ingest(&remote.get_bytes(&format!("/trees/{tree}?folders=1"))?)?; |
| 187 | #[derive(Deserialize)] |
| 188 | struct Sizes { |
| 189 | sizes: HashMap<String, u64>, |
| 190 | } |
| 191 | let sizes: Sizes = remote.get_json(&format!("/trees/{tree}/sizes"))?; |
| 192 | // Sealed folders: ones this machine can't open are left out (a save keeps them as the change has them); |
| 193 | // the rest come now, since the host's sizes are their sealed ones. |
| 194 | let seals = crate::seal::Seals::load(&app.db, &project.id)?; |
| 195 | let closed = seals.unreadable(); |
| 196 | let all = tree::flatten(&app.store, tree)?; |
| 197 | let sealed: Vec<&String> = all.keys().filter(|p| seals.folder_of(p).is_some() && !closed.iter().any(|f| tree::under(p, f))).collect(); |
| 198 | if !sealed.is_empty() { |
| 199 | app.store.ingest(&remote.post_for_bytes(&format!("/trees/{tree}/files"), &json!({ "paths": sealed }))?)?; |
| 200 | } |
| 201 | let mut base = Index::default(); |
| 202 | for (path, e) in all { |
| 203 | if closed.iter().any(|f| tree::under(&path, f)) { |
| 204 | continue; |
| 205 | } |
| 206 | let size = if e.kind == EntryKind::Gitlink { |
| 207 | 0 |
| 208 | } else if seals.folder_of(&path).is_some() { |
| 209 | app.store.read_file(&e.id).map(|b| b.len() as u64).unwrap_or(0) |
| 210 | } else { |
| 211 | sizes.sizes.get(&e.id.hex()).copied().unwrap_or(0) |
| 212 | }; |
| 213 | let stat = Stat { size, mtime_ns: MTIME_NS, ino: ino(&path) }; |
| 214 | base.entries.insert(path, IndexEntry { entry: e, stat }); |
| 215 | } |
| 216 | base.tree = Some(*tree); |
| 217 | let dir = backing(workspace); |
| 218 | fs::create_dir_all(dir.join(ws::DIR))?; |
| 219 | base.save_as(&dir, "lazy-base")?; |
| 220 | Ok(base) |
| 221 | } |
| 222 |
| 223 | /// `on mount --serve <folder>`: runs the mount until it's unmounted. |
| 224 | pub fn serve(app: &App, root: &Path) -> Result<()> { |
| 225 | let w = super::workspace_at(app, root)?.filter(|w| w.path == root).ok_or_else(|| anyhow!("{} isn't a lazy workspace on this machine", root.display()))?; |
| 226 | let project = app.db.project(&w.project)?.ok_or_else(|| anyhow!("the workspace's project isn't known here"))?; |
| 227 | let dir = backing(&w.id); |
| 228 | let base = Index::load_from(&dir, "lazy-base").ok_or_else(|| anyhow!("{} has no lazy index", dir.display()))?; |
| 229 | let tree = base.tree.ok_or_else(|| anyhow!("{} has no tree", dir.display()))?; |
| 230 | let mut files = BTreeMap::new(); |
| 231 | let mut dirs: HashMap<String, BTreeSet<String>> = HashMap::new(); |
| 232 | dirs.insert(String::new(), BTreeSet::new()); |
| 233 | for (path, e) in base.entries { |
| 234 | let mut child = path.as_str(); |
| 235 | while let Some((parent, name)) = child.rsplit_once('/') { |
| 236 | dirs.entry(parent.to_string()).or_default().insert(name.to_string()); |
| 237 | child = parent; |
| 238 | } |
| 239 | dirs.entry(String::new()).or_default().insert(child.to_string()); |
| 240 | if e.entry.kind == EntryKind::Gitlink { |
| 241 | dirs.entry(path.clone()).or_default(); |
| 242 | } |
| 243 | files.insert(path, (e.entry, e.stat.size)); |
| 244 | } |
| 245 | let gone: BTreeSet<String> = fs::read_to_string(dir.join(ws::DIR).join("lazy-gone")).unwrap_or_default().lines().filter(|l| !l.is_empty()).map(str::to_string).collect(); |
| 246 | let mut state = State { inodes: HashMap::new(), paths: HashMap::new(), gone, handles: HashMap::new(), next_fh: 1 }; |
| 247 | state.inodes.insert(1, String::new()); |
| 248 | state.paths.insert(String::new(), 1); |
| 249 | let fs_ = Lazy { |
| 250 | backing: dir, |
| 251 | files, |
| 252 | dirs, |
| 253 | tree, |
| 254 | store: Store::open(&crate::paths::objects())?, |
| 255 | remote: Remote::for_project(&project), |
| 256 | state: Mutex::new(state), |
| 257 | }; |
| 258 | let mut config = Config::default(); |
| 259 | config.mount_options = vec![MountOption::FSName("onset".into()), MountOption::Subtype("onset".into()), MountOption::DefaultPermissions, MountOption::NoAtime]; |
| 260 | fuser::mount(fs_, root, &config)?; |
| 261 | Ok(()) |
| 262 | } |
| 263 |
| 264 | const TTL_ENTRY: Duration = Duration::from_secs(1); |
| 265 | /// Attributes are asked for every time: a save compares them with the index. |
| 266 | const TTL_ATTR: Duration = Duration::ZERO; |
| 267 |
| 268 | enum Node { |
| 269 | /// In the backing: written here, or fetched. |
| 270 | Real(fs::Metadata), |
| 271 | /// In the tree, not fetched yet: (entry, size). |
| 272 | File(Entry, u64), |
| 273 | Dir, |
| 274 | } |
| 275 |
| 276 | impl Node { |
| 277 | fn is_dir(&self) -> bool { |
| 278 | match self { |
| 279 | Node::Real(m) => m.is_dir(), |
| 280 | Node::File(..) => false, |
| 281 | Node::Dir => true, |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 |
| 286 | struct State { |
| 287 | inodes: HashMap<u64, String>, |
| 288 | paths: HashMap<String, u64>, |
| 289 | /// Paths in the tree deleted here (and everything under them). |
| 290 | gone: BTreeSet<String>, |
| 291 | handles: HashMap<u64, fs::File>, |
| 292 | next_fh: u64, |
| 293 | } |
| 294 |
| 295 | struct Lazy { |
| 296 | backing: PathBuf, |
| 297 | files: BTreeMap<String, (Entry, u64)>, |
| 298 | dirs: HashMap<String, BTreeSet<String>>, |
| 299 | tree: Id, |
| 300 | store: Store, |
| 301 | remote: Remote, |
| 302 | state: Mutex<State>, |
| 303 | } |
| 304 |
| 305 | fn join(dir: &str, name: &str) -> String { |
| 306 | if dir.is_empty() { name.to_string() } else { format!("{dir}/{name}") } |
| 307 | } |
| 308 |
| 309 | fn parent(path: &str) -> &str { |
| 310 | path.rsplit_once('/').map(|(p, _)| p).unwrap_or("") |
| 311 | } |
| 312 |
| 313 | fn time(ns: i64) -> SystemTime { |
| 314 | UNIX_EPOCH + Duration::from_nanos(ns.max(0) as u64) |
| 315 | } |
| 316 |
| 317 | fn cpath(path: &Path) -> Result<CString, Errno> { |
| 318 | CString::new(path.as_os_str().as_bytes()).map_err(|_| Errno::EINVAL) |
| 319 | } |
| 320 |
| 321 | fn timespec(t: Option<TimeOrNow>) -> libc::timespec { |
| 322 | match t { |
| 323 | None => libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT }, |
| 324 | Some(TimeOrNow::Now) => libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_NOW }, |
| 325 | Some(TimeOrNow::SpecificTime(t)) => { |
| 326 | let d = t.duration_since(UNIX_EPOCH).unwrap_or_default(); |
| 327 | libc::timespec { tv_sec: d.as_secs() as libc::time_t, tv_nsec: d.subsec_nanos() as libc::c_long } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 |
| 332 | fn set_times(path: &Path, atime: Option<TimeOrNow>, mtime: Option<TimeOrNow>) -> Result<(), Errno> { |
| 333 | let c = cpath(path)?; |
| 334 | let times = [timespec(atime), timespec(mtime)]; |
| 335 | // SAFETY: a NUL-terminated path and two timespecs, as utimensat takes. |
| 336 | if unsafe { libc::utimensat(libc::AT_FDCWD, c.as_ptr(), times.as_ptr(), libc::AT_SYMLINK_NOFOLLOW) } != 0 { |
| 337 | return Err(Errno::from(std::io::Error::last_os_error())); |
| 338 | } |
| 339 | Ok(()) |
| 340 | } |
| 341 |
| 342 | fn io(e: std::io::Error) -> Errno { |
| 343 | Errno::from(e) |
| 344 | } |
| 345 |
| 346 | impl Lazy { |
| 347 | fn real(&self, path: &str) -> PathBuf { |
| 348 | if path.is_empty() { self.backing.clone() } else { self.backing.join(path) } |
| 349 | } |
| 350 |
| 351 | fn in_tree(&self, path: &str) -> bool { |
| 352 | self.files.contains_key(path) || self.dirs.contains_key(path) |
| 353 | } |
| 354 |
| 355 | /// Whether `path`, or a folder holding it, was deleted from the tree here. |
| 356 | fn hidden(&self, st: &State, path: &str) -> bool { |
| 357 | let mut p = path; |
| 358 | loop { |
| 359 | if st.gone.contains(p) { |
| 360 | return true; |
| 361 | } |
| 362 | match p.rsplit_once('/') { |
| 363 | Some((up, _)) => p = up, |
| 364 | None => return false, |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 |
| 369 | fn find(&self, st: &State, path: &str) -> Option<Node> { |
| 370 | if let Ok(m) = fs::symlink_metadata(self.real(path)) { |
| 371 | return Some(Node::Real(m)); |
| 372 | } |
| 373 | if self.hidden(st, path) { |
| 374 | return None; |
| 375 | } |
| 376 | // A real file where a folder holding it was. |
| 377 | let mut p = path; |
| 378 | while let Some((up, _)) = p.rsplit_once('/') { |
| 379 | p = up; |
| 380 | if fs::symlink_metadata(self.real(p)).is_ok_and(|m| !m.is_dir()) { |
| 381 | return None; |
| 382 | } |
| 383 | } |
| 384 | match self.files.get(path) { |
| 385 | Some((e, _)) if e.kind == EntryKind::Gitlink => Some(Node::Dir), |
| 386 | Some((e, size)) => Some(Node::File(*e, *size)), |
| 387 | None if self.dirs.contains_key(path) => Some(Node::Dir), |
| 388 | None => None, |
| 389 | } |
| 390 | } |
| 391 |
| 392 | fn ino_of(&self, st: &mut State, path: &str) -> u64 { |
| 393 | if let Some(i) = st.paths.get(path) { |
| 394 | return *i; |
| 395 | } |
| 396 | let mut i = ino(path); |
| 397 | while st.inodes.get(&i).is_some_and(|p| p != path) { |
| 398 | i = i.wrapping_add(1).max(2); |
| 399 | } |
| 400 | st.inodes.insert(i, path.to_string()); |
| 401 | st.paths.insert(path.to_string(), i); |
| 402 | i |
| 403 | } |
| 404 |
| 405 | fn attr(&self, st: &mut State, path: &str, node: &Node) -> FileAttr { |
| 406 | let ino = INodeNo(self.ino_of(st, path)); |
| 407 | let (uid, gid) = (unsafe { libc::getuid() }, unsafe { libc::getgid() }); |
| 408 | let at = time(MTIME_NS); |
| 409 | let base = FileAttr { |
| 410 | ino, |
| 411 | size: 0, |
| 412 | blocks: 0, |
| 413 | atime: at, |
| 414 | mtime: at, |
| 415 | ctime: at, |
| 416 | crtime: at, |
| 417 | kind: FileType::Directory, |
| 418 | perm: 0o755, |
| 419 | nlink: 2, |
| 420 | uid, |
| 421 | gid, |
| 422 | rdev: 0, |
| 423 | blksize: 4096, |
| 424 | flags: 0, |
| 425 | }; |
| 426 | match node { |
| 427 | Node::Real(m) => { |
| 428 | let kind = if m.is_dir() { |
| 429 | FileType::Directory |
| 430 | } else if m.file_type().is_symlink() { |
| 431 | FileType::Symlink |
| 432 | } else { |
| 433 | FileType::RegularFile |
| 434 | }; |
| 435 | FileAttr { |
| 436 | size: m.len(), |
| 437 | blocks: m.blocks(), |
| 438 | atime: time(m.atime() * 1_000_000_000 + m.atime_nsec()), |
| 439 | mtime: time(m.mtime() * 1_000_000_000 + m.mtime_nsec()), |
| 440 | ctime: time(m.ctime() * 1_000_000_000 + m.ctime_nsec()), |
| 441 | crtime: time(m.mtime() * 1_000_000_000 + m.mtime_nsec()), |
| 442 | kind, |
| 443 | perm: (m.mode() & 0o7777) as u16, |
| 444 | nlink: m.nlink() as u32, |
| 445 | uid: m.uid(), |
| 446 | gid: m.gid(), |
| 447 | ..base |
| 448 | } |
| 449 | } |
| 450 | Node::File(e, size) => FileAttr { |
| 451 | size: *size, |
| 452 | blocks: size.div_ceil(512), |
| 453 | kind: if e.kind == EntryKind::Link { FileType::Symlink } else { FileType::RegularFile }, |
| 454 | perm: match e.kind { |
| 455 | EntryKind::Exec => 0o755, |
| 456 | EntryKind::Link => 0o777, |
| 457 | _ => 0o644, |
| 458 | }, |
| 459 | nlink: 1, |
| 460 | ..base |
| 461 | }, |
| 462 | Node::Dir => base, |
| 463 | } |
| 464 | } |
| 465 |
| 466 | /// What's in folder `path`: the backing's files over the tree's. |
| 467 | fn listing(&self, st: &State, path: &str) -> Vec<(String, Node)> { |
| 468 | let mut names = BTreeSet::new(); |
| 469 | if let Ok(read) = fs::read_dir(self.real(path)) { |
| 470 | for e in read.flatten() { |
| 471 | if let Some(n) = e.file_name().to_str() { |
| 472 | names.insert(n.to_string()); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | if let Some(kids) = self.dirs.get(path) { |
| 477 | names.extend(kids.iter().cloned()); |
| 478 | } |
| 479 | names.into_iter().filter_map(|n| self.find(st, &join(path, &n)).map(|node| (n, node))).collect() |
| 480 | } |
| 481 |
| 482 | /// A file's content from the store, fetched from the host first if it isn't here. |
| 483 | fn content(&self, path: &str, entry: &Entry) -> Result<Vec<u8>> { |
| 484 | if let Ok(bytes) = self.store.read_file(&entry.id) { |
| 485 | return Ok(bytes); |
| 486 | } |
| 487 | let bundle = self.remote.post_for_bytes(&format!("/trees/{}/files", self.tree), &json!({ "paths": [path] }))?; |
| 488 | self.store.ingest(&bundle)?; |
| 489 | Ok(self.store.read_file(&entry.id)?) |
| 490 | } |
| 491 |
| 492 | fn real_dir(&self, path: &str) -> Result<(), Errno> { |
| 493 | fs::create_dir_all(self.real(path)).map_err(io) |
| 494 | } |
| 495 |
| 496 | /// A file in the tree, fetched into the backing: from here on it's an ordinary file. |
| 497 | fn copy_up(&self, path: &str, entry: &Entry) -> Result<(), Errno> { |
| 498 | let bytes = self.content(path, entry).map_err(|e| { |
| 499 | eprintln!("on mount: couldn't fetch {path}: {e:#}"); |
| 500 | Errno::EIO |
| 501 | })?; |
| 502 | self.real_dir(parent(path))?; |
| 503 | let real = self.real(path); |
| 504 | if entry.kind == EntryKind::Link { |
| 505 | std::os::unix::fs::symlink(OsStr::from_bytes(&bytes), &real).map_err(io)?; |
| 506 | } else { |
| 507 | fs::write(&real, &bytes).map_err(io)?; |
| 508 | fs::set_permissions(&real, fs::Permissions::from_mode(if entry.kind == EntryKind::Exec { 0o755 } else { 0o644 })).map_err(io)?; |
| 509 | } |
| 510 | // The time it showed before, so the index still knows it. |
| 511 | let shown = Some(TimeOrNow::SpecificTime(time(MTIME_NS))); |
| 512 | set_times(&real, shown, shown) |
| 513 | } |
| 514 |
| 515 | /// `path` and everything under it into the backing (before it moves). |
| 516 | fn copy_up_all(&self, st: &State, path: &str) -> Result<(), Errno> { |
| 517 | match self.find(st, path) { |
| 518 | Some(Node::File(e, _)) => self.copy_up(path, &e), |
| 519 | Some(node) if node.is_dir() => { |
| 520 | self.real_dir(path)?; |
| 521 | for (name, _) in self.listing(st, path) { |
| 522 | self.copy_up_all(st, &join(path, &name))?; |
| 523 | } |
| 524 | Ok(()) |
| 525 | } |
| 526 | _ => Ok(()), |
| 527 | } |
| 528 | } |
| 529 |
| 530 | fn save_gone(&self, st: &State) { |
| 531 | let text: String = st.gone.iter().map(|p| format!("{p}\n")).collect(); |
| 532 | let _ = fs::write(self.backing.join(ws::DIR).join("lazy-gone"), text); |
| 533 | } |
| 534 |
| 535 | fn path_of(&self, st: &State, ino: INodeNo) -> Result<String, Errno> { |
| 536 | st.inodes.get(&ino.0).cloned().ok_or(Errno::ENOENT) |
| 537 | } |
| 538 |
| 539 | fn child(&self, st: &State, parent: INodeNo, name: &OsStr) -> Result<String, Errno> { |
| 540 | let dir = self.path_of(st, parent)?; |
| 541 | let name = name.to_str().filter(|n| !n.is_empty() && !n.contains('/')).ok_or(Errno::EINVAL)?; |
| 542 | Ok(join(&dir, name)) |
| 543 | } |
| 544 |
| 545 | fn entry_reply(&self, st: &mut State, path: &str, reply: ReplyEntry) { |
| 546 | match self.find(st, path) { |
| 547 | Some(node) => { |
| 548 | let a = self.attr(st, path, &node); |
| 549 | reply.entry(&TTL_ENTRY, &a, Generation(0)); |
| 550 | } |
| 551 | None => reply.error(Errno::ENOENT), |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 |
| 556 | impl Filesystem for Lazy { |
| 557 | fn lookup(&self, _req: &Request, parent: INodeNo, name: &OsStr, reply: ReplyEntry) { |
| 558 | let mut st = self.state.lock().unwrap(); |
| 559 | match self.child(&st, parent, name) { |
| 560 | Ok(path) => self.entry_reply(&mut st, &path, reply), |
| 561 | Err(_) => reply.error(Errno::ENOENT), |
| 562 | } |
| 563 | } |
| 564 |
| 565 | fn getattr(&self, _req: &Request, ino: INodeNo, _fh: Option<FileHandle>, reply: ReplyAttr) { |
| 566 | let mut st = self.state.lock().unwrap(); |
| 567 | let Ok(path) = self.path_of(&st, ino) else { return reply.error(Errno::ENOENT) }; |
| 568 | match self.find(&st, &path) { |
| 569 | Some(node) => { |
| 570 | let a = self.attr(&mut st, &path, &node); |
| 571 | reply.attr(&TTL_ATTR, &a); |
| 572 | } |
| 573 | None => reply.error(Errno::ENOENT), |
| 574 | } |
| 575 | } |
| 576 |
| 577 | fn setattr( |
| 578 | &self, |
| 579 | _req: &Request, |
| 580 | ino: INodeNo, |
| 581 | mode: Option<u32>, |
| 582 | _uid: Option<u32>, |
| 583 | _gid: Option<u32>, |
| 584 | size: Option<u64>, |
| 585 | atime: Option<TimeOrNow>, |
| 586 | mtime: Option<TimeOrNow>, |
| 587 | _ctime: Option<SystemTime>, |
| 588 | fh: Option<FileHandle>, |
| 589 | _crtime: Option<SystemTime>, |
| 590 | _chgtime: Option<SystemTime>, |
| 591 | _bkuptime: Option<SystemTime>, |
| 592 | _flags: Option<fuser::BsdFileFlags>, |
| 593 | reply: ReplyAttr, |
| 594 | ) { |
| 595 | let mut st = self.state.lock().unwrap(); |
| 596 | let result = (|| -> Result<(), Errno> { |
| 597 | let path = self.path_of(&st, ino)?; |
| 598 | match self.find(&st, &path).ok_or(Errno::ENOENT)? { |
| 599 | Node::File(e, _) => self.copy_up(&path, &e)?, |
| 600 | Node::Dir => self.real_dir(&path)?, |
| 601 | Node::Real(_) => {} |
| 602 | } |
| 603 | let real = self.real(&path); |
| 604 | if let Some(m) = mode { |
| 605 | fs::set_permissions(&real, fs::Permissions::from_mode(m & 0o7777)).map_err(io)?; |
| 606 | } |
| 607 | if let Some(s) = size { |
| 608 | match fh.and_then(|h| st.handles.get(&h.0)) { |
| 609 | Some(f) => f.set_len(s).map_err(io)?, |
| 610 | None => fs::OpenOptions::new().write(true).open(&real).and_then(|f| f.set_len(s)).map_err(io)?, |
| 611 | } |
| 612 | } |
| 613 | if atime.is_some() || mtime.is_some() { |
| 614 | set_times(&real, atime, mtime)?; |
| 615 | } |
| 616 | Ok(()) |
| 617 | })(); |
| 618 | match result { |
| 619 | Ok(()) => { |
| 620 | let Ok(path) = self.path_of(&st, ino) else { return reply.error(Errno::ENOENT) }; |
| 621 | match self.find(&st, &path) { |
| 622 | Some(node) => { |
| 623 | let a = self.attr(&mut st, &path, &node); |
| 624 | reply.attr(&TTL_ATTR, &a); |
| 625 | } |
| 626 | None => reply.error(Errno::ENOENT), |
| 627 | } |
| 628 | } |
| 629 | Err(e) => reply.error(e), |
| 630 | } |
| 631 | } |
| 632 |
| 633 | fn readlink(&self, _req: &Request, ino: INodeNo, reply: ReplyData) { |
| 634 | let st = self.state.lock().unwrap(); |
| 635 | let Ok(path) = self.path_of(&st, ino) else { return reply.error(Errno::ENOENT) }; |
| 636 | match self.find(&st, &path) { |
| 637 | Some(Node::Real(_)) => match fs::read_link(self.real(&path)) { |
| 638 | Ok(target) => reply.data(target.as_os_str().as_bytes()), |
| 639 | Err(e) => reply.error(io(e)), |
| 640 | }, |
| 641 | Some(Node::File(e, _)) if e.kind == EntryKind::Link => match self.content(&path, &e) { |
| 642 | Ok(bytes) => reply.data(&bytes), |
| 643 | Err(_) => reply.error(Errno::EIO), |
| 644 | }, |
| 645 | Some(_) => reply.error(Errno::EINVAL), |
| 646 | None => reply.error(Errno::ENOENT), |
| 647 | } |
| 648 | } |
| 649 |
| 650 | fn mkdir(&self, _req: &Request, parent: INodeNo, name: &OsStr, mode: u32, umask: u32, reply: ReplyEntry) { |
| 651 | let mut st = self.state.lock().unwrap(); |
| 652 | let result = (|| -> Result<String, Errno> { |
| 653 | let path = self.child(&st, parent, name)?; |
| 654 | if self.find(&st, &path).is_some() { |
| 655 | return Err(Errno::EEXIST); |
| 656 | } |
| 657 | self.real_dir(parent_of(&path))?; |
| 658 | fs::create_dir(self.real(&path)).map_err(io)?; |
| 659 | fs::set_permissions(self.real(&path), fs::Permissions::from_mode(mode & !umask & 0o7777)).map_err(io)?; |
| 660 | Ok(path) |
| 661 | })(); |
| 662 | match result { |
| 663 | Ok(path) => self.entry_reply(&mut st, &path, reply), |
| 664 | Err(e) => reply.error(e), |
| 665 | } |
| 666 | } |
| 667 |
| 668 | fn unlink(&self, _req: &Request, parent: INodeNo, name: &OsStr, reply: ReplyEmpty) { |
| 669 | let mut st = self.state.lock().unwrap(); |
| 670 | let result = (|| -> Result<(), Errno> { |
| 671 | let path = self.child(&st, parent, name)?; |
| 672 | match self.find(&st, &path).ok_or(Errno::ENOENT)? { |
| 673 | node if node.is_dir() => return Err(Errno::EISDIR), |
| 674 | Node::Real(_) => fs::remove_file(self.real(&path)).map_err(io)?, |
| 675 | _ => {} |
| 676 | } |
| 677 | if self.in_tree(&path) { |
| 678 | st.gone.insert(path); |
| 679 | self.save_gone(&st); |
| 680 | } |
| 681 | Ok(()) |
| 682 | })(); |
| 683 | match result { |
| 684 | Ok(()) => reply.ok(), |
| 685 | Err(e) => reply.error(e), |
| 686 | } |
| 687 | } |
| 688 |
| 689 | fn rmdir(&self, _req: &Request, parent: INodeNo, name: &OsStr, reply: ReplyEmpty) { |
| 690 | let mut st = self.state.lock().unwrap(); |
| 691 | let result = (|| -> Result<(), Errno> { |
| 692 | let path = self.child(&st, parent, name)?; |
| 693 | let node = self.find(&st, &path).ok_or(Errno::ENOENT)?; |
| 694 | if !node.is_dir() { |
| 695 | return Err(Errno::ENOTDIR); |
| 696 | } |
| 697 | if !self.listing(&st, &path).is_empty() { |
| 698 | return Err(Errno::ENOTEMPTY); |
| 699 | } |
| 700 | if let Node::Real(_) = node { |
| 701 | fs::remove_dir(self.real(&path)).map_err(io)?; |
| 702 | } |
| 703 | if self.in_tree(&path) { |
| 704 | st.gone.insert(path); |
| 705 | self.save_gone(&st); |
| 706 | } |
| 707 | Ok(()) |
| 708 | })(); |
| 709 | match result { |
| 710 | Ok(()) => reply.ok(), |
| 711 | Err(e) => reply.error(e), |
| 712 | } |
| 713 | } |
| 714 |
| 715 | fn symlink(&self, _req: &Request, parent: INodeNo, link_name: &OsStr, target: &Path, reply: ReplyEntry) { |
| 716 | let mut st = self.state.lock().unwrap(); |
| 717 | let result = (|| -> Result<String, Errno> { |
| 718 | let path = self.child(&st, parent, link_name)?; |
| 719 | if self.find(&st, &path).is_some() { |
| 720 | return Err(Errno::EEXIST); |
| 721 | } |
| 722 | self.real_dir(parent_of(&path))?; |
| 723 | std::os::unix::fs::symlink(target, self.real(&path)).map_err(io)?; |
| 724 | Ok(path) |
| 725 | })(); |
| 726 | match result { |
| 727 | Ok(path) => self.entry_reply(&mut st, &path, reply), |
| 728 | Err(e) => reply.error(e), |
| 729 | } |
| 730 | } |
| 731 |
| 732 | fn rename(&self, _req: &Request, parent: INodeNo, name: &OsStr, newparent: INodeNo, newname: &OsStr, flags: RenameFlags, reply: ReplyEmpty) { |
| 733 | let mut st = self.state.lock().unwrap(); |
| 734 | let result = (|| -> Result<(String, String), Errno> { |
| 735 | if flags.contains(RenameFlags::RENAME_EXCHANGE) { |
| 736 | return Err(Errno::EINVAL); |
| 737 | } |
| 738 | let from = self.child(&st, parent, name)?; |
| 739 | let to = self.child(&st, newparent, newname)?; |
| 740 | if from == to { |
| 741 | return Ok((from, to)); |
| 742 | } |
| 743 | if to.starts_with(&format!("{from}/")) { |
| 744 | return Err(Errno::EINVAL); |
| 745 | } |
| 746 | let src = self.find(&st, &from).ok_or(Errno::ENOENT)?; |
| 747 | if let Some(dst) = self.find(&st, &to) { |
| 748 | if flags.contains(RenameFlags::RENAME_NOREPLACE) { |
| 749 | return Err(Errno::EEXIST); |
| 750 | } |
| 751 | match (src.is_dir(), dst.is_dir()) { |
| 752 | (true, false) => return Err(Errno::ENOTDIR), |
| 753 | (false, true) => return Err(Errno::EISDIR), |
| 754 | (true, true) if !self.listing(&st, &to).is_empty() => return Err(Errno::ENOTEMPTY), |
| 755 | _ => {} |
| 756 | } |
| 757 | if dst.is_dir() && fs::symlink_metadata(self.real(&to)).is_ok() { |
| 758 | fs::remove_dir(self.real(&to)).map_err(io)?; |
| 759 | } |
| 760 | } |
| 761 | self.copy_up_all(&st, &from)?; |
| 762 | self.real_dir(parent_of(&to))?; |
| 763 | fs::rename(self.real(&from), self.real(&to)).map_err(io)?; |
| 764 | // What the tree has at either name stays out of sight. |
| 765 | for p in [&from, &to] { |
| 766 | if self.in_tree(p) { |
| 767 | st.gone.insert(p.clone()); |
| 768 | } |
| 769 | } |
| 770 | self.save_gone(&st); |
| 771 | Ok((from, to)) |
| 772 | })(); |
| 773 | match result { |
| 774 | Ok((from, to)) => { |
| 775 | // Inodes the kernel holds follow the move. |
| 776 | let prefix = format!("{from}/"); |
| 777 | let moved: Vec<(String, u64)> = st.paths.iter().filter(|(p, _)| **p == from || p.starts_with(&prefix)).map(|(p, i)| (p.clone(), *i)).collect(); |
| 778 | let to_prefix = format!("{to}/"); |
| 779 | st.paths.retain(|p, _| *p != to && !p.starts_with(&to_prefix)); |
| 780 | for (old, i) in moved { |
| 781 | let new = format!("{to}{}", &old[from.len()..]); |
| 782 | st.paths.remove(&old); |
| 783 | st.paths.insert(new.clone(), i); |
| 784 | st.inodes.insert(i, new); |
| 785 | } |
| 786 | reply.ok(); |
| 787 | } |
| 788 | Err(e) => reply.error(e), |
| 789 | } |
| 790 | } |
| 791 |
| 792 | fn open(&self, _req: &Request, ino: INodeNo, flags: OpenFlags, reply: ReplyOpen) { |
| 793 | let mut st = self.state.lock().unwrap(); |
| 794 | let result = (|| -> Result<u64, Errno> { |
| 795 | let path = self.path_of(&st, ino)?; |
| 796 | match self.find(&st, &path).ok_or(Errno::ENOENT)? { |
| 797 | node if node.is_dir() => return Err(Errno::EISDIR), |
| 798 | Node::File(e, _) => self.copy_up(&path, &e)?, |
| 799 | _ => {} |
| 800 | } |
| 801 | let acc = flags.0 & libc::O_ACCMODE; |
| 802 | let write = acc == libc::O_WRONLY || acc == libc::O_RDWR; |
| 803 | let file = fs::OpenOptions::new() |
| 804 | .read(acc == libc::O_RDONLY || acc == libc::O_RDWR) |
| 805 | .write(write) |
| 806 | .truncate(write && flags.0 & libc::O_TRUNC != 0) |
| 807 | .open(self.real(&path)) |
| 808 | .map_err(io)?; |
| 809 | let fh = st.next_fh; |
| 810 | st.next_fh += 1; |
| 811 | st.handles.insert(fh, file); |
| 812 | Ok(fh) |
| 813 | })(); |
| 814 | match result { |
| 815 | Ok(fh) => reply.opened(FileHandle(fh), FopenFlags::empty()), |
| 816 | Err(e) => reply.error(e), |
| 817 | } |
| 818 | } |
| 819 |
| 820 | fn read(&self, _req: &Request, _ino: INodeNo, fh: FileHandle, offset: u64, size: u32, _flags: OpenFlags, _lock: Option<LockOwner>, reply: ReplyData) { |
| 821 | let st = self.state.lock().unwrap(); |
| 822 | let Some(file) = st.handles.get(&fh.0) else { return reply.error(Errno::EBADF) }; |
| 823 | let mut buf = vec![0u8; size as usize]; |
| 824 | let mut got = 0; |
| 825 | while got < buf.len() { |
| 826 | match file.read_at(&mut buf[got..], offset + got as u64) { |
| 827 | Ok(0) => break, |
| 828 | Ok(n) => got += n, |
| 829 | Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {} |
| 830 | Err(e) => return reply.error(io(e)), |
| 831 | } |
| 832 | } |
| 833 | reply.data(&buf[..got]); |
| 834 | } |
| 835 |
| 836 | fn write(&self, _req: &Request, _ino: INodeNo, fh: FileHandle, offset: u64, data: &[u8], _wf: WriteFlags, _flags: OpenFlags, _lock: Option<LockOwner>, reply: ReplyWrite) { |
| 837 | let st = self.state.lock().unwrap(); |
| 838 | let Some(file) = st.handles.get(&fh.0) else { return reply.error(Errno::EBADF) }; |
| 839 | match file.write_all_at(data, offset) { |
| 840 | Ok(()) => reply.written(data.len() as u32), |
| 841 | Err(e) => reply.error(io(e)), |
| 842 | } |
| 843 | } |
| 844 |
| 845 | fn flush(&self, _req: &Request, _ino: INodeNo, _fh: FileHandle, _lock: LockOwner, reply: ReplyEmpty) { |
| 846 | reply.ok(); |
| 847 | } |
| 848 |
| 849 | fn release(&self, _req: &Request, _ino: INodeNo, fh: FileHandle, _flags: OpenFlags, _lock: Option<LockOwner>, _flush: bool, reply: ReplyEmpty) { |
| 850 | self.state.lock().unwrap().handles.remove(&fh.0); |
| 851 | reply.ok(); |
| 852 | } |
| 853 |
| 854 | fn fsync(&self, _req: &Request, _ino: INodeNo, fh: FileHandle, _datasync: bool, reply: ReplyEmpty) { |
| 855 | let st = self.state.lock().unwrap(); |
| 856 | match st.handles.get(&fh.0).map(|f| f.sync_all()) { |
| 857 | Some(Err(e)) => reply.error(io(e)), |
| 858 | _ => reply.ok(), |
| 859 | } |
| 860 | } |
| 861 |
| 862 | fn readdir(&self, _req: &Request, ino: INodeNo, _fh: FileHandle, offset: u64, mut reply: ReplyDirectory) { |
| 863 | let mut st = self.state.lock().unwrap(); |
| 864 | let Ok(path) = self.path_of(&st, ino) else { return reply.error(Errno::ENOENT) }; |
| 865 | if !self.find(&st, &path).is_some_and(|n| n.is_dir()) { |
| 866 | return reply.error(Errno::ENOTDIR); |
| 867 | } |
| 868 | let up = if path.is_empty() { 1 } else { self.ino_of(&mut st, parent(&path)) }; |
| 869 | let mut list = vec![(ino.0, FileType::Directory, ".".to_string()), (up, FileType::Directory, "..".to_string())]; |
| 870 | for (name, node) in self.listing(&st, &path) { |
| 871 | let child = join(&path, &name); |
| 872 | let kind = self.attr(&mut st, &child, &node).kind; |
| 873 | list.push((self.ino_of(&mut st, &child), kind, name)); |
| 874 | } |
| 875 | for (i, (child, kind, name)) in list.into_iter().enumerate().skip(offset as usize) { |
| 876 | if reply.add(INodeNo(child), (i + 1) as u64, kind, name) { |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | reply.ok(); |
| 881 | } |
| 882 |
| 883 | fn statfs(&self, _req: &Request, _ino: INodeNo, reply: ReplyStatfs) { |
| 884 | let Ok(c) = cpath(&self.backing) else { return reply.error(Errno::EINVAL) }; |
| 885 | let mut s: libc::statvfs = unsafe { std::mem::zeroed() }; |
| 886 | // SAFETY: a NUL-terminated path and a statvfs to fill. |
| 887 | if unsafe { libc::statvfs(c.as_ptr(), &mut s) } != 0 { |
| 888 | return reply.error(Errno::from(std::io::Error::last_os_error())); |
| 889 | } |
| 890 | reply.statfs(s.f_blocks, s.f_bfree, s.f_bavail, s.f_files, s.f_ffree, s.f_bsize as u32, s.f_namemax as u32, s.f_frsize as u32); |
| 891 | } |
| 892 |
| 893 | fn access(&self, _req: &Request, _ino: INodeNo, _mask: AccessFlags, reply: ReplyEmpty) { |
| 894 | reply.ok(); |
| 895 | } |
| 896 |
| 897 | fn create(&self, _req: &Request, parent: INodeNo, name: &OsStr, mode: u32, umask: u32, flags: i32, reply: ReplyCreate) { |
| 898 | let mut st = self.state.lock().unwrap(); |
| 899 | let result = (|| -> Result<(String, u64), Errno> { |
| 900 | let path = self.child(&st, parent, name)?; |
| 901 | if flags & libc::O_EXCL != 0 && self.find(&st, &path).is_some() { |
| 902 | return Err(Errno::EEXIST); |
| 903 | } |
| 904 | if let Some(Node::File(e, _)) = self.find(&st, &path) { |
| 905 | self.copy_up(&path, &e)?; |
| 906 | } |
| 907 | self.real_dir(parent_of(&path))?; |
| 908 | let file = fs::OpenOptions::new() |
| 909 | .read(true) |
| 910 | .write(true) |
| 911 | .create(true) |
| 912 | .truncate(flags & libc::O_TRUNC != 0) |
| 913 | .mode(mode & !umask & 0o7777) |
| 914 | .open(self.real(&path)) |
| 915 | .map_err(io)?; |
| 916 | let fh = st.next_fh; |
| 917 | st.next_fh += 1; |
| 918 | st.handles.insert(fh, file); |
| 919 | Ok((path, fh)) |
| 920 | })(); |
| 921 | match result { |
| 922 | Ok((path, fh)) => match self.find(&st, &path) { |
| 923 | Some(node) => { |
| 924 | let a = self.attr(&mut st, &path, &node); |
| 925 | reply.created(&TTL_ENTRY, &a, Generation(0), FileHandle(fh), FopenFlags::empty()); |
| 926 | } |
| 927 | None => reply.error(Errno::EIO), |
| 928 | }, |
| 929 | Err(e) => reply.error(e), |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 |
| 934 | fn parent_of(path: &str) -> &str { |
| 935 | parent(path) |
| 936 | } |
| 937 | } |
| 938 |