Mercurial > lbo > hg > async-google-apis
changeset 150:fcf0925a91b6
gcs_example: Allow prefix for upload
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 27 Oct 2020 13:29:04 +0100 |
parents | 6d0b3ba8155e |
children | a6620695e23c |
files | drive_example/Cargo.lock gcs_example/Cargo.lock gcs_example/src/main.rs |
diffstat | 3 files changed, 23 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/drive_example/Cargo.lock Tue Oct 27 11:19:00 2020 +0100 +++ b/drive_example/Cargo.lock Tue Oct 27 13:29:04 2020 +0100 @@ -64,9 +64,9 @@ [[package]] name = "base64" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d1ccbaf7d9ec9537465a97bf19edc1a4e158ecb49fc16178202238c569cc42" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] name = "bitflags" @@ -459,9 +459,9 @@ [[package]] name = "libc" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" [[package]] name = "log" @@ -831,9 +831,9 @@ [[package]] name = "syn" -version = "1.0.46" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942" +checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" dependencies = [ "proc-macro2", "quote", @@ -1159,11 +1159,11 @@ [[package]] name = "yup-oauth2" -version = "4.1.2" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "749192b9464694a95dbaf0586e845c835b315e38d491aa2766a8477aaadb48ec" +checksum = "92ed435d48d4c834ee654443dd3330399f9656506d7477ec645df58e406a25db" dependencies = [ - "base64 0.12.1", + "base64 0.12.3", "chrono", "futures", "http",
--- a/gcs_example/Cargo.lock Tue Oct 27 11:19:00 2020 +0100 +++ b/gcs_example/Cargo.lock Tue Oct 27 13:29:04 2020 +0100 @@ -485,9 +485,9 @@ [[package]] name = "libc" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" [[package]] name = "log" @@ -1212,9 +1212,9 @@ [[package]] name = "yup-oauth2" -version = "4.1.2" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "749192b9464694a95dbaf0586e845c835b315e38d491aa2766a8477aaadb48ec" +checksum = "92ed435d48d4c834ee654443dd3330399f9656506d7477ec645df58e406a25db" dependencies = [ "base64 0.12.3", "chrono",
--- a/gcs_example/src/main.rs Tue Oct 27 11:19:00 2020 +0100 +++ b/gcs_example/src/main.rs Tue Oct 27 13:29:04 2020 +0100 @@ -17,10 +17,12 @@ mut cl: storage_v1_types::ObjectsService, bucket: &str, p: &Path, + prefix: &str, ) -> common::Result<()> { let mut params = storage_v1_types::ObjectsInsertParams::default(); params.bucket = bucket.into(); - params.name = Some(p.file_name().unwrap().to_str().unwrap().into()); + assert!(prefix.ends_with("/")); + params.name = Some(prefix.to_string() + p.file_name().unwrap().to_str().unwrap()); let obj = storage_v1_types::Object::default(); let f = tokio::fs::OpenOptions::new().read(true).open(p).await?; @@ -144,7 +146,7 @@ ) .arg( clap::Arg::with_name("PREFIX") - .help("When listing with -a list: Prefix of objects to list.") + .help("When listing with -a list: Prefix of objects to list. When uploading with -a put: Prefix to prepend to filename.") .long("prefix") .short("p") .takes_value(true), @@ -189,8 +191,12 @@ let fp = matches .value_of("FILE_OR_OBJECT") .expect("FILE is a mandatory argument."); - println!("{}", fp); - upload_file(cl, buck, Path::new(&fp)) + let mut pre = matches + .value_of("PREFIX").unwrap_or("").to_string(); + if !pre.ends_with("/") { + pre = pre.to_string() + "/"; + } + upload_file(cl, buck, Path::new(&fp), &pre) .await .expect("Upload failed :("); return;