|
@@ -94,15 +94,17 @@ impl Cmd {
|
|
pub async fn run(self) -> crate::Result<InvokeResponse> {
|
|
pub async fn run(self) -> crate::Result<InvokeResponse> {
|
|
match self {
|
|
match self {
|
|
Self::ReadTextFile { path, options } => {
|
|
Self::ReadTextFile { path, options } => {
|
|
- #[cfg(read_text_file)]
|
|
|
|
|
|
+ #[cfg(fs_read_text_file)]
|
|
return read_text_file(path, options).await.map(Into::into);
|
|
return read_text_file(path, options).await.map(Into::into);
|
|
- #[cfg(not(read_text_file))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("readTextFile".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_read_text_file))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted(
|
|
|
|
+ "fs > readTextFile".to_string(),
|
|
|
|
+ ))
|
|
}
|
|
}
|
|
Self::ReadBinaryFile { path, options } => {
|
|
Self::ReadBinaryFile { path, options } => {
|
|
- #[cfg(read_binary_file)]
|
|
|
|
|
|
+ #[cfg(fs_read_binary_file)]
|
|
return read_binary_file(path, options).await.map(Into::into);
|
|
return read_binary_file(path, options).await.map(Into::into);
|
|
- #[cfg(not(read_binary_file))]
|
|
|
|
|
|
+ #[cfg(not(fs_read_binary_file))]
|
|
Err(crate::Error::ApiNotAllowlisted(
|
|
Err(crate::Error::ApiNotAllowlisted(
|
|
"readBinaryFile".to_string(),
|
|
"readBinaryFile".to_string(),
|
|
))
|
|
))
|
|
@@ -112,85 +114,95 @@ impl Cmd {
|
|
contents,
|
|
contents,
|
|
options,
|
|
options,
|
|
} => {
|
|
} => {
|
|
- #[cfg(write_file)]
|
|
|
|
|
|
+ #[cfg(fs_write_file)]
|
|
return write_file(path, contents, options).await.map(Into::into);
|
|
return write_file(path, contents, options).await.map(Into::into);
|
|
- #[cfg(not(write_file))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("writeFile".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_write_file))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted(
|
|
|
|
+ "fs > writeFile".to_string(),
|
|
|
|
+ ))
|
|
}
|
|
}
|
|
Self::WriteBinaryFile {
|
|
Self::WriteBinaryFile {
|
|
path,
|
|
path,
|
|
contents,
|
|
contents,
|
|
options,
|
|
options,
|
|
} => {
|
|
} => {
|
|
- #[cfg(write_binary_file)]
|
|
|
|
|
|
+ #[cfg(fs_write_binary_file)]
|
|
return write_binary_file(path, contents, options)
|
|
return write_binary_file(path, contents, options)
|
|
.await
|
|
.await
|
|
.map(Into::into);
|
|
.map(Into::into);
|
|
- #[cfg(not(write_binary_file))]
|
|
|
|
|
|
+ #[cfg(not(fs_write_binary_file))]
|
|
Err(crate::Error::ApiNotAllowlisted(
|
|
Err(crate::Error::ApiNotAllowlisted(
|
|
"writeBinaryFile".to_string(),
|
|
"writeBinaryFile".to_string(),
|
|
))
|
|
))
|
|
}
|
|
}
|
|
Self::ReadDir { path, options } => {
|
|
Self::ReadDir { path, options } => {
|
|
- #[cfg(read_dir)]
|
|
|
|
|
|
+ #[cfg(fs_read_dir)]
|
|
return read_dir(path, options).await.map(Into::into);
|
|
return read_dir(path, options).await.map(Into::into);
|
|
- #[cfg(not(read_dir))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("readDir".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_read_dir))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted("fs > readDir".to_string()))
|
|
}
|
|
}
|
|
Self::CopyFile {
|
|
Self::CopyFile {
|
|
source,
|
|
source,
|
|
destination,
|
|
destination,
|
|
options,
|
|
options,
|
|
} => {
|
|
} => {
|
|
- #[cfg(copy_file)]
|
|
|
|
|
|
+ #[cfg(fs_copy_file)]
|
|
return copy_file(source, destination, options)
|
|
return copy_file(source, destination, options)
|
|
.await
|
|
.await
|
|
.map(Into::into);
|
|
.map(Into::into);
|
|
- #[cfg(not(copy_file))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("copyFile".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_copy_file))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted("fs > copyFile".to_string()))
|
|
}
|
|
}
|
|
Self::CreateDir { path, options } => {
|
|
Self::CreateDir { path, options } => {
|
|
- #[cfg(create_dir)]
|
|
|
|
|
|
+ #[cfg(fs_create_dir)]
|
|
return create_dir(path, options).await.map(Into::into);
|
|
return create_dir(path, options).await.map(Into::into);
|
|
- #[cfg(not(create_dir))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("createDir".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_create_dir))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted(
|
|
|
|
+ "fs > createDir".to_string(),
|
|
|
|
+ ))
|
|
}
|
|
}
|
|
Self::RemoveDir { path, options } => {
|
|
Self::RemoveDir { path, options } => {
|
|
- #[cfg(remove_dir)]
|
|
|
|
|
|
+ #[cfg(fs_remove_dir)]
|
|
return remove_dir(path, options).await.map(Into::into);
|
|
return remove_dir(path, options).await.map(Into::into);
|
|
- #[cfg(not(remove_dir))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("removeDir".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_remove_dir))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted(
|
|
|
|
+ "fs > removeDir".to_string(),
|
|
|
|
+ ))
|
|
}
|
|
}
|
|
Self::RemoveFile { path, options } => {
|
|
Self::RemoveFile { path, options } => {
|
|
- #[cfg(remove_file)]
|
|
|
|
|
|
+ #[cfg(fs_remove_file)]
|
|
return remove_file(path, options).await.map(Into::into);
|
|
return remove_file(path, options).await.map(Into::into);
|
|
- #[cfg(not(remove_file))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("removeFile".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_remove_file))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted(
|
|
|
|
+ "fs > removeFile".to_string(),
|
|
|
|
+ ))
|
|
}
|
|
}
|
|
Self::RenameFile {
|
|
Self::RenameFile {
|
|
old_path,
|
|
old_path,
|
|
new_path,
|
|
new_path,
|
|
options,
|
|
options,
|
|
} => {
|
|
} => {
|
|
- #[cfg(rename_file)]
|
|
|
|
|
|
+ #[cfg(fs_rename_file)]
|
|
return rename_file(old_path, new_path, options)
|
|
return rename_file(old_path, new_path, options)
|
|
.await
|
|
.await
|
|
.map(Into::into);
|
|
.map(Into::into);
|
|
- #[cfg(not(rename_file))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("renameFile".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_rename_file))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted(
|
|
|
|
+ "fs > renameFile".to_string(),
|
|
|
|
+ ))
|
|
}
|
|
}
|
|
Self::ResolvePath { path, directory } => {
|
|
Self::ResolvePath { path, directory } => {
|
|
- #[cfg(path_api)]
|
|
|
|
|
|
+ #[cfg(fs_path)]
|
|
return resolve_path_handler(path, directory).await.map(Into::into);
|
|
return resolve_path_handler(path, directory).await.map(Into::into);
|
|
- #[cfg(not(path_api))]
|
|
|
|
- Err(crate::Error::ApiNotAllowlisted("pathApi".to_string()))
|
|
|
|
|
|
+ #[cfg(not(fs_path))]
|
|
|
|
+ Err(crate::Error::ApiNotAllowlisted("fs > pathApi".to_string()))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// Reads a directory.
|
|
/// Reads a directory.
|
|
-#[cfg(read_dir)]
|
|
|
|
|
|
+#[cfg(fs_read_dir)]
|
|
pub async fn read_dir(
|
|
pub async fn read_dir(
|
|
path: PathBuf,
|
|
path: PathBuf,
|
|
options: Option<DirOperationOptions>,
|
|
options: Option<DirOperationOptions>,
|
|
@@ -204,7 +216,7 @@ pub async fn read_dir(
|
|
}
|
|
}
|
|
|
|
|
|
/// Copies a file.
|
|
/// Copies a file.
|
|
-#[cfg(copy_file)]
|
|
|
|
|
|
+#[cfg(fs_copy_file)]
|
|
pub async fn copy_file(
|
|
pub async fn copy_file(
|
|
source: PathBuf,
|
|
source: PathBuf,
|
|
destination: PathBuf,
|
|
destination: PathBuf,
|
|
@@ -222,7 +234,7 @@ pub async fn copy_file(
|
|
}
|
|
}
|
|
|
|
|
|
/// Creates a directory.
|
|
/// Creates a directory.
|
|
-#[cfg(create_dir)]
|
|
|
|
|
|
+#[cfg(fs_create_dir)]
|
|
pub async fn create_dir(path: PathBuf, options: Option<DirOperationOptions>) -> crate::Result<()> {
|
|
pub async fn create_dir(path: PathBuf, options: Option<DirOperationOptions>) -> crate::Result<()> {
|
|
let (recursive, dir) = if let Some(options_value) = options {
|
|
let (recursive, dir) = if let Some(options_value) = options {
|
|
(options_value.recursive, options_value.dir)
|
|
(options_value.recursive, options_value.dir)
|
|
@@ -240,7 +252,7 @@ pub async fn create_dir(path: PathBuf, options: Option<DirOperationOptions>) ->
|
|
}
|
|
}
|
|
|
|
|
|
/// Removes a directory.
|
|
/// Removes a directory.
|
|
-#[cfg(remove_dir)]
|
|
|
|
|
|
+#[cfg(fs_remove_dir)]
|
|
pub async fn remove_dir(path: PathBuf, options: Option<DirOperationOptions>) -> crate::Result<()> {
|
|
pub async fn remove_dir(path: PathBuf, options: Option<DirOperationOptions>) -> crate::Result<()> {
|
|
let (recursive, dir) = if let Some(options_value) = options {
|
|
let (recursive, dir) = if let Some(options_value) = options {
|
|
(options_value.recursive, options_value.dir)
|
|
(options_value.recursive, options_value.dir)
|
|
@@ -258,7 +270,7 @@ pub async fn remove_dir(path: PathBuf, options: Option<DirOperationOptions>) ->
|
|
}
|
|
}
|
|
|
|
|
|
/// Removes a file
|
|
/// Removes a file
|
|
-#[cfg(remove_file)]
|
|
|
|
|
|
+#[cfg(fs_remove_file)]
|
|
pub async fn remove_file(
|
|
pub async fn remove_file(
|
|
path: PathBuf,
|
|
path: PathBuf,
|
|
options: Option<FileOperationOptions>,
|
|
options: Option<FileOperationOptions>,
|
|
@@ -269,7 +281,7 @@ pub async fn remove_file(
|
|
}
|
|
}
|
|
|
|
|
|
/// Renames a file.
|
|
/// Renames a file.
|
|
-#[cfg(rename_file)]
|
|
|
|
|
|
+#[cfg(fs_rename_file)]
|
|
pub async fn rename_file(
|
|
pub async fn rename_file(
|
|
old_path: PathBuf,
|
|
old_path: PathBuf,
|
|
new_path: PathBuf,
|
|
new_path: PathBuf,
|
|
@@ -286,7 +298,7 @@ pub async fn rename_file(
|
|
}
|
|
}
|
|
|
|
|
|
/// Writes a text file.
|
|
/// Writes a text file.
|
|
-#[cfg(write_file)]
|
|
|
|
|
|
+#[cfg(fs_write_file)]
|
|
pub async fn write_file(
|
|
pub async fn write_file(
|
|
path: PathBuf,
|
|
path: PathBuf,
|
|
contents: String,
|
|
contents: String,
|
|
@@ -299,7 +311,7 @@ pub async fn write_file(
|
|
}
|
|
}
|
|
|
|
|
|
/// Writes a binary file.
|
|
/// Writes a binary file.
|
|
-#[cfg(write_binary_file)]
|
|
|
|
|
|
+#[cfg(fs_write_binary_file)]
|
|
pub async fn write_binary_file(
|
|
pub async fn write_binary_file(
|
|
path: PathBuf,
|
|
path: PathBuf,
|
|
contents: String,
|
|
contents: String,
|
|
@@ -316,7 +328,7 @@ pub async fn write_binary_file(
|
|
}
|
|
}
|
|
|
|
|
|
/// Reads a text file.
|
|
/// Reads a text file.
|
|
-#[cfg(read_text_file)]
|
|
|
|
|
|
+#[cfg(fs_read_text_file)]
|
|
pub async fn read_text_file(
|
|
pub async fn read_text_file(
|
|
path: PathBuf,
|
|
path: PathBuf,
|
|
options: Option<FileOperationOptions>,
|
|
options: Option<FileOperationOptions>,
|
|
@@ -326,7 +338,7 @@ pub async fn read_text_file(
|
|
}
|
|
}
|
|
|
|
|
|
/// Reads a binary file.
|
|
/// Reads a binary file.
|
|
-#[cfg(read_binary_file)]
|
|
|
|
|
|
+#[cfg(fs_read_binary_file)]
|
|
pub async fn read_binary_file(
|
|
pub async fn read_binary_file(
|
|
path: PathBuf,
|
|
path: PathBuf,
|
|
options: Option<FileOperationOptions>,
|
|
options: Option<FileOperationOptions>,
|
|
@@ -335,6 +347,7 @@ pub async fn read_binary_file(
|
|
.map_err(crate::Error::FailedToExecuteApi)
|
|
.map_err(crate::Error::FailedToExecuteApi)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#[cfg(fs_path)]
|
|
pub async fn resolve_path_handler(
|
|
pub async fn resolve_path_handler(
|
|
path: String,
|
|
path: String,
|
|
directory: Option<BaseDirectory>,
|
|
directory: Option<BaseDirectory>,
|