summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Michaelis <gitter@liftm.de>2020-07-13 14:47:54 +0900
committerJulius Michaelis <gitter@liftm.de>2020-07-13 15:54:53 +0900
commit50718691022f479e144ab4b06a7f74e84cd967a7 (patch)
tree5756991f130ecce2124a583457fde509c079f6e7
parent3905626f8f1c53a5ef933cd9bbefec31f8eb9355 (diff)
Revert changes to files_* since extra parameters can be passed through *_with_options and adding *_with_options can be a non-breaking change
-rw-r--r--ipfs-api/examples/mfs.rs6
-rw-r--r--ipfs-api/src/client/internal.rs42
-rw-r--r--ipfs-api/src/request/files.rs14
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<response::FilesCpResponse, Error> {
- 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<response::FilesLsResponse, Error> {
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<response::FilesMkdirResponse, Error> {
- 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<response::FilesMkdirResponse, Error> {
+ 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<response::FilesMvResponse, Error> {
- 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<response::FilesStatResponse, Error> {
- self.request(request::FilesStat { path, with_local }, None).await
+ pub async fn files_stat(&self, path: &str) -> Result<response::FilesStatResponse, Error> {
+ 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<R>(
&self,
path: &str,
+ create: bool,
+ truncate: bool,
data: R,
) -> Result<response::FilesWriteResponse, Error>
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<bool>,
}
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<bool>,
}
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<bool>,
}
impl<'a> ApiRequest for FilesStat<'a> {