1use std::io;
8use std::time::SystemTime;
9
10pub use fs::*;
11pub use handle::*;
12use ion::{Error, ToValue};
13
14mod dir;
15mod fs;
16mod handle;
17
18pub(crate) fn base_error(base: &str, path: &str, err: &io::Error) -> Error {
19 Error::new(format!("Could not {base} {path}: {err}"), None)
20}
21
22pub(crate) fn file_error(action: &str, path: &str, err: &io::Error, _: ()) -> Error {
23 Error::new(format!("Could not {action} file {path}: {err}"), None)
24}
25
26pub(crate) fn seek_error(_: &str, path: &str, err: &io::Error, (mode, offset): (SeekMode, i64)) -> Error {
27 Error::new(
28 format!("Could not seek file {path} to mode '{mode}' with {offset}: {err}"),
29 None,
30 )
31}
32
33pub(crate) fn dir_error(action: &str, path: &str, err: &io::Error) -> Error {
34 Error::new(format!("Could not {action} directory {path}: {err}"), None)
35}
36
37pub(crate) fn metadata_error(path: &str, err: &io::Error) -> Error {
38 Error::new(format!("Could not get metadata for {path}: {err}"), None)
39}
40
41pub(crate) fn translate_error(action: &str, from: &str, to: &str, err: &io::Error) -> Error {
42 Error::new(format!("Could not {action} {from} to {to}: {err}"), None)
43}
44
45#[derive(Debug, ToValue)]
46pub struct Metadata {
47 size: u64,
48 is_file: bool,
49 is_directory: bool,
50 is_symlink: bool,
51 created: Option<SystemTime>,
52 accessed: Option<SystemTime>,
53 modified: Option<SystemTime>,
54 readonly: bool,
55}
56
57impl Metadata {
58 fn new(meta: &std::fs::Metadata) -> Metadata {
59 Metadata {
60 size: meta.len(),
61 is_file: meta.is_file(),
62 is_directory: meta.is_dir(),
63 is_symlink: meta.is_symlink(),
64 created: meta.created().ok(),
65 accessed: meta.accessed().ok(),
66 modified: meta.modified().ok(),
67 readonly: meta.permissions().readonly(),
68 }
69 }
70}