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