From 50718691022f479e144ab4b06a7f74e84cd967a7 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Mon, 13 Jul 2020 14:47:54 +0900 Subject: Revert changes to files_* since extra parameters can be passed through *_with_options and adding *_with_options can be a non-breaking change --- ipfs-api/examples/mfs.rs | 6 +++--- ipfs-api/src/client/internal.rs | 42 +++++++++++++++++++++++------------------ ipfs-api/src/request/files.rs | 14 +++++++------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs index 9deb90f..3d6419c 100644 --- a/ipfs-api/examples/mfs.rs +++ b/ipfs-api/examples/mfs.rs @@ -47,7 +47,7 @@ async fn main() { eprintln!("getting status of /test/does..."); eprintln!(); - match client.files_stat("/test/does", false).await { + match client.files_stat("/test/does").await { Ok(stat) => print_stat(stat), Err(e) => { eprintln!("error getting status of /test/does: {}", e); @@ -60,7 +60,7 @@ async fn main() { let src = File::open(file!()).expect("could not read source file"); - if let Err(e) = client.files_write("/test/mfs.rs", src).await { + if let Err(e) = client.files_write("/test/mfs.rs", true, true, src).await { eprintln!("error writing source file /test/mfs.rs: {}", e); return; } @@ -68,7 +68,7 @@ async fn main() { eprintln!("getting status of /test/mfs.rs..."); eprintln!(); - match client.files_stat("/test/mfs.rs", false).await { + match client.files_stat("/test/mfs.rs").await { Ok(stat) => print_stat(stat), Err(e) => { eprintln!("error getting status of /test/mfs.rs: {}", e); diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs index 420e896..d652458 100644 --- a/ipfs-api/src/client/internal.rs +++ b/ipfs-api/src/client/internal.rs @@ -1115,7 +1115,7 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// let res = client.files_cp("/path/to/file", "/dest", true); + /// let res = client.files_cp("/path/to/file", "/dest"); /// ``` /// #[inline] @@ -1123,9 +1123,8 @@ impl IpfsClient { &self, path: &str, dest: &str, - flush: bool, ) -> Result { - self.request_empty(request::FilesCp { path, dest, flush }, None) + self.request_empty(request::FilesCp { path, dest, .. default() }, None) .await } @@ -1147,7 +1146,7 @@ impl IpfsClient { self.request_empty(request::FilesFlush { path }, None).await } - /// List directories in MFS.. + /// List directories in MFS. /// /// ```no_run /// use ipfs_api::IpfsClient; @@ -1157,8 +1156,6 @@ impl IpfsClient { /// let res = client.files_ls(Some("/tmp")); /// ``` /// - /// Defaults to `-U`, so the output is unsorted. - /// #[inline] pub async fn files_ls(&self, path: Option<&str>) -> Result { self.files_ls_with_options(request::FilesLs { path: path, .. default() }).await @@ -1204,8 +1201,12 @@ impl IpfsClient { /// ``` /// #[inline] - pub async fn files_mkdir(&self, path: &str, parents: bool) -> Result { - self.files_mkdir_with_options(request::FilesMkdir { path: path, parents: Some(parents), .. default() }).await + pub async fn files_mkdir( + &self, + path: &str, + parents: bool, + ) -> Result { + self.files_mkdir_with_options(request::FilesMkdir { path, parents: Some(parents), .. default() }).await } /// Make directories in MFS. @@ -1245,7 +1246,7 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// let res = client.files_mv("/test/tmp.json", "/test/file.json", true); + /// let res = client.files_mv("/test/tmp.json", "/test/file.json"); /// ``` /// #[inline] @@ -1253,9 +1254,8 @@ impl IpfsClient { &self, path: &str, dest: &str, - flush: bool, ) -> Result { - self.request_empty(request::FilesMv { path, dest, flush }, None) + self.request_empty(request::FilesMv { path, dest, .. default() }, None) .await } @@ -1353,12 +1353,12 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// let res = client.files_stat("/test/file.json", false); + /// let res = client.files_stat("/test/file.json"); /// ``` /// #[inline] - pub async fn files_stat(&self, path: &str, with_local: bool) -> Result { - self.request(request::FilesStat { path, with_local }, None).await + pub async fn files_stat(&self, path: &str) -> Result { + self.request(request::FilesStat { path, .. default() }, None).await } /// Write to a mutable file in the filesystem. @@ -1369,21 +1369,27 @@ impl IpfsClient { /// /// let client = IpfsClient::default(); /// let file = File::open("test.json").unwrap(); - /// let res = client.files_write("/test/file.json", file); + /// let res = client.files_write("/test/file.json", true, true, file); /// ``` /// - /// For convenience reasons, this defaults create and truncate to true - /// #[inline] pub async fn files_write( &self, path: &str, + create: bool, + truncate: bool, data: R, ) -> Result where R: 'static + Read + Send + Sync, { - self.files_write_with_options(request::FilesWrite { path, .. request::FilesWrite::default() }, data).await + let options = request::FilesWrite { + path, + create: Some(create), + truncate: Some(truncate), + .. request::FilesWrite::default() + }; + self.files_write_with_options(options, data).await } /// Write to a mutable file in the filesystem. diff --git a/ipfs-api/src/request/files.rs b/ipfs-api/src/request/files.rs index 2a7b996..498faa9 100644 --- a/ipfs-api/src/request/files.rs +++ b/ipfs-api/src/request/files.rs @@ -9,7 +9,7 @@ use crate::request::ApiRequest; use crate::serde::Serialize; -#[derive(Serialize)] +#[derive(Serialize, Default)] pub struct FilesCp<'a> { #[serde(rename = "arg")] pub path: &'a str, @@ -17,7 +17,7 @@ pub struct FilesCp<'a> { #[serde(rename = "arg")] pub dest: &'a str, - pub flush: bool, + pub flush: Option, } impl<'a> ApiRequest for FilesCp<'a> { @@ -77,7 +77,7 @@ impl<'a> ApiRequest for FilesMkdir<'a> { const PATH: &'static str = "/files/mkdir"; } -#[derive(Serialize)] +#[derive(Serialize, Default)] pub struct FilesMv<'a> { #[serde(rename = "arg")] pub path: &'a str, @@ -85,7 +85,7 @@ pub struct FilesMv<'a> { #[serde(rename = "arg")] pub dest: &'a str, - pub flush: bool, + pub flush: Option, } impl<'a> ApiRequest for FilesMv<'a> { @@ -126,13 +126,13 @@ impl<'a> ApiRequest for FilesRm<'a> { const PATH: &'static str = "/files/rm"; } -#[derive(Serialize)] +#[derive(Serialize, Default)] +#[serde(rename_all = "kebab-case")] pub struct FilesStat<'a> { #[serde(rename = "arg")] pub path: &'a str, - #[serde(rename = "with-local")] - pub with_local: bool, + pub with_local: Option, } impl<'a> ApiRequest for FilesStat<'a> { -- cgit v1.2.3