Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Sep 26, 2024
1 parent 98ab10c commit 3e42b3c
Show file tree
Hide file tree
Showing 25 changed files with 1,861 additions and 4,312 deletions.
1,694 changes: 892 additions & 802 deletions Source/commands.rs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Source/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use serde::Deserialize;
#[derive(Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Config {
/// Whether or not paths that contain components that start with a `.`
/// will require that `.` appears literally in the pattern; `*`, `?`, `**`,
/// or `[...]` will not match. This is useful because such files are
/// conventionally considered hidden on Unix systems and it might be
/// desirable to skip them when listing files.
///
/// Defaults to `true` on Unix systems and `false` on Windows
// dotfiles are not supposed to be exposed by default on unix
pub require_literal_leading_dot: Option<bool>,
/// Whether or not paths that contain components that start with a `.`
/// will require that `.` appears literally in the pattern; `*`, `?`, `**`,
/// or `[...]` will not match. This is useful because such files are
/// conventionally considered hidden on Unix systems and it might be
/// desirable to skip them when listing files.
///
/// Defaults to `true` on Unix systems and `false` on Windows
// dotfiles are not supposed to be exposed by default on unix
pub require_literal_leading_dot: Option<bool>,
}
36 changes: 18 additions & 18 deletions Source/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ use crate::{FilePath, OpenOptions};
pub struct Fs<R: Runtime>(pub(crate) AppHandle<R>);

fn path_or_err<P: Into<FilePath>>(p: P) -> std::io::Result<PathBuf> {
match p.into() {
FilePath::Path(p) => Ok(p),
FilePath::Url(u) if u.scheme() == "file" => u
.to_file_path()
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "invalid file URL")),
FilePath::Url(_) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"cannot use a URL to load files on desktop and iOS",
)),
}
match p.into() {
FilePath::Path(p) => Ok(p),
FilePath::Url(u) if u.scheme() == "file" => u
.to_file_path()
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "invalid file URL")),
FilePath::Url(_) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"cannot use a URL to load files on desktop and iOS",
)),
}
}

impl<R: Runtime> Fs<R> {
pub fn open<P: Into<FilePath>>(
&self,
path: P,
opts: OpenOptions,
) -> std::io::Result<std::fs::File> {
let path = path_or_err(path)?;
std::fs::OpenOptions::from(opts).open(path)
}
pub fn open<P: Into<FilePath>>(
&self,
path: P,
opts: OpenOptions,
) -> std::io::Result<std::fs::File> {
let path = path_or_err(path)?;
std::fs::OpenOptions::from(opts).open(path)
}
}
56 changes: 28 additions & 28 deletions Source/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ use serde::{Serialize, Serializer};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error(transparent)]
Tauri(#[from] tauri::Error),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("forbidden path: {0}")]
PathForbidden(PathBuf),
/// Invalid glob pattern.
#[error("invalid glob pattern: {0}")]
GlobPattern(#[from] glob::PatternError),
/// Watcher error.
#[cfg(feature = "watch")]
#[error(transparent)]
Watch(#[from] notify::Error),
#[cfg(target_os = "android")]
#[error(transparent)]
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
#[error("URL is not a valid path")]
InvalidPathUrl,
#[error("Unsafe PathBuf: {0}")]
UnsafePathBuf(&'static str),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error(transparent)]
Tauri(#[from] tauri::Error),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("forbidden path: {0}")]
PathForbidden(PathBuf),
/// Invalid glob pattern.
#[error("invalid glob pattern: {0}")]
GlobPattern(#[from] glob::PatternError),
/// Watcher error.
#[cfg(feature = "watch")]
#[error(transparent)]
Watch(#[from] notify::Error),
#[cfg(target_os = "android")]
#[error(transparent)]
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
#[error("URL is not a valid path")]
InvalidPathUrl,
#[error("Unsafe PathBuf: {0}")]
UnsafePathBuf(&'static str),
}

impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}
Loading

0 comments on commit 3e42b3c

Please sign in to comment.