create file

This commit is contained in:
sagiferi
2026-01-02 10:15:13 +01:00
parent 6cb5af9845
commit 3d3cd3a312
3 changed files with 39 additions and 9 deletions
+34
View File
@@ -0,0 +1,34 @@
use crate::models::S3Item;
pub fn create_directory_if_not_exists(folder_name: &str) -> std::io::Result<()> {
let folder_name_with_root = "./result".to_string() + "/" + folder_name;
if !std::path::Path::new(&folder_name_with_root).exists() {
std::fs::create_dir_all(folder_name_with_root)?;
}
Ok(())
}
pub fn create_file_if_not_exist_or_differ(
bucket_item: &S3Item,
content: &[u8],
) -> std::io::Result<()> {
use std::fs;
use std::io::Write;
use std::path::Path;
let path = Path::new(bucket_item.key.as_str());
if path.exists()
&& bucket_item
.size
.is_some_and(|s| std::fs::metadata(path).is_ok_and(|m| m.len() == s as u64))
{
return Ok(());
}
// Ha a fájl nem létezik vagy a tartalom különbözik, írjuk a fájlt
let mut file = fs::File::create(path)?;
file.write_all(content)?;
Ok(())
}
+4 -1
View File
@@ -1,2 +1,5 @@
pub mod file_utils;
pub mod s3_utils; pub mod s3_utils;
pub use s3_utils::print_bucket_contents; pub use file_utils::create_directory_if_not_exists;
pub use s3_utils::print_bucket_contents;
+1 -8
View File
@@ -1,3 +1,4 @@
use super::file_utils::create_directory_if_not_exists;
use crate::models::CloudS3; use crate::models::CloudS3;
use crate::models::S3Item; use crate::models::S3Item;
use aws_config::BehaviorVersion; use aws_config::BehaviorVersion;
@@ -133,11 +134,3 @@ pub async fn print_bucket_contents(client: &Client, s3: &CloudS3) -> Result<(),
Ok(()) Ok(())
} }
async fn create_directory_if_not_exists(folder_name: &str) -> std::io::Result<()> {
let folder_name_with_root = "./result".to_string() + "/" + folder_name;
if !std::path::Path::new(&folder_name_with_root).exists() {
std::fs::create_dir_all(folder_name_with_root)?;
}
Ok(())
}