From 8f8a54b4fa6509d5bfae7c1223d7a1b9af7cb4e7 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 20 Aug 2019 13:06:19 -0300 Subject: [PATCH] Create the missing files --- src/main.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index b66b8e6..2abed64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,12 @@ -use std::env; use std::collections::HashSet; +use std::env; use std::path::Path; use rusoto_core::Region; -use rusoto_credential::StaticProvider; use rusoto_core::request::HttpClient; +use rusoto_credential::StaticProvider; use rusoto_s3::ListObjectsRequest; +use rusoto_s3::PutObjectRequest; use rusoto_s3::S3; use rusoto_s3::S3Client; @@ -64,7 +65,24 @@ fn main() { }); } + let missing: HashSet<_> = directory_files.difference(&files_dirs).collect(); + println!("Directories with files:\n{:#?}", directory_files); println!("Directories with controllers:\n{:#?}", files_dirs); println!("Difference:\n{:#?}", directory_files.difference(&files_dirs)); + + for control in missing.iter() { + println!("Creating {}", control); + let control_file = PutObjectRequest { + bucket: bucket.to_owned(), + content_type: Some("httpd/unix-directory".to_owned()), + content_length: Some(0), + key: control.to_string(), + ..Default::default() + }; + match client.put_object(control_file).sync() { + Ok(_) => println!("Success!"), + Err(error) => println!("Failed to create file: {}", error) + } + } }