Skip to content

Commit

Permalink
Minor pathing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MPult committed May 14, 2023
1 parent 02c6329 commit c29212d
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ async fn main() {
// Initialize
client = init(debug, token, images, out.clone(), true).await;

// Creates out folder
if !out.join("messages").exists() {
std::fs::create_dir(out.join("messages").clone()).unwrap();
std::fs::create_dir(out.join("messages/images").clone()).unwrap();
}

// Get list of rooms
let rooms = ReAPI::download_rooms(&client, images).await;

Expand Down Expand Up @@ -76,6 +82,12 @@ async fn main() {
// Initialize
client = init(debug, token, images, out.clone(), true).await;

// Creates out folder
if !out.join("saved_posts").exists() {
std::fs::create_dir(out.join("saved_posts").clone()).unwrap();
std::fs::create_dir(out.join("saved_posts/images").clone()).unwrap();
}

// Gets saved posts
let saved_posts = ReAPI::download_saved_posts(&client, images);

Expand All @@ -98,6 +110,11 @@ async fn main() {
// Initialize
client = init(debug, token, images, out.clone(), false).await;

// Creates out folder
if !out.join("subreddit").exists() {
std::fs::create_dir(out.join("subreddit").clone()).unwrap();
std::fs::create_dir(out.join("subreddit/images").clone()).unwrap();
}
// Gets saved posts
let subreddit = ReAPI::download_subreddit(&client, name, images);

Expand Down Expand Up @@ -207,22 +224,8 @@ async fn init(debug: bool, token: bool, images: bool, out: PathBuf, auth: bool)
}

// Handle output folder stuff
// Deletes the output folder (we append the batches so this is necessary)
if out.exists() {
std::fs::remove_dir_all(out.clone()).expect("Error deleting out folder");
}

// Creates out folders
std::fs::create_dir(out.clone()).unwrap();
std::fs::create_dir(out.join("messages")).unwrap();
std::fs::create_dir(out.join("saved_posts")).unwrap();
std::fs::create_dir(out.join("subreddit")).unwrap();

// Make sure there is an images folder to output to if images is true
if images {
std::fs::create_dir(out.join("messages/images")).unwrap();
std::fs::create_dir(out.join("saved_posts/images")).unwrap();
std::fs::create_dir(out.join("subreddit/images")).unwrap();
if !out.exists() {
std::fs::create_dir(out.clone()).unwrap();
}

return client;
Expand Down

0 comments on commit c29212d

Please sign in to comment.