podman_client/images/
copy.rs

1use http_body_util::Empty;
2use hyper::body::Bytes;
3use url::form_urlencoded;
4
5use crate::{
6    client::Client,
7    models::{
8        connection::SendRequestOptions,
9        lib::Error,
10        podman::images::copy::{ImageCopy, ImageCopyOptions},
11    },
12    utils::bool_to_str::bool_to_str,
13};
14
15impl Client {
16    pub async fn image_copy(&self, options: ImageCopyOptions<'_>) -> Result<ImageCopy, Error> {
17        let mut path = ["/libpod/images/scp/", options.name].concat();
18
19        let mut query = form_urlencoded::Serializer::new(String::new());
20        if let Some(destination) = options.destination
21            && !destination.is_empty()
22        {
23            query.append_pair("destination", destination);
24        }
25        if let Some(quite) = options.quite {
26            query.append_pair("quite", bool_to_str(quite));
27        }
28        let query_string = query.finish();
29
30        if !query_string.is_empty() {
31            path += &["?", &query_string].concat();
32        }
33
34        let (_, data) = self
35            .send_request::<_, (), _>(SendRequestOptions {
36                method: "POST",
37                path: &path,
38                header: None,
39                body: Empty::<Bytes>::new(),
40            })
41            .await?;
42
43        Ok(data)
44    }
45}