diff --git a/fixtures/vyos/index.html b/fixtures/vyos/index.html new file mode 100644 index 0000000..9378fd2 --- /dev/null +++ b/fixtures/vyos/index.html @@ -0,0 +1,409 @@ + + + + + + + + + + + + + + + +repositories/current/dists/current • dev.packages.vyos.net + +
+
+
+
+
+ + + + +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+ + + + + +
+
+
+ + + + + +
+
+ +
+
+ +
+
+
+ + +
+ + +
+ + +
+

+ + + + + +
+
+
+
+ + +
+
+
diff --git a/fixtures/vyos/vyos-accel-ppp/index.html b/fixtures/vyos/vyos-accel-ppp/index.html new file mode 100644 index 0000000..8cda2db --- /dev/null +++ b/fixtures/vyos/vyos-accel-ppp/index.html @@ -0,0 +1,296 @@ + + + + + + + + + + + + + + + +repositories/crux/vyos/pool/main/v/vyos-accel-ppp • dev.packages.vyos.net + +
+
+
+
+
+ + + + +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+ + Home + + + / repositories + / crux + / vyos + / pool + / main + / v + / vyos-accel-ppp +
+ + + + +
+
+
+ + + + + +
+
+ +
+
+ +
+
+
+ + +
+ + +
+ + +
+

+ + + + + +
+
+
+
+ + +
+
+
diff --git a/src/cli/sync.rs b/src/cli/sync.rs index 8a5f940..5207385 100644 --- a/src/cli/sync.rs +++ b/src/cli/sync.rs @@ -380,35 +380,48 @@ pub fn sync(args: SyncArgs, bind_address: Option) -> ! { exit_code = 1; } else { // Don't even walkdir when dry_run, to prevent no dir error - if !args.dry_run { - for entry in walkdir::WalkDir::new(download_dir).contents_first(true) { - let entry = entry.unwrap(); - let path = entry.path(); - if !remote_list.contains(&path.to_path_buf()) { - if !args.no_delete { - // always make sure that we are deleting the right thing - if del_cnt >= args.max_delete { - info!("Exceeding max delete count, aborting"); - // exit with 25 to indicate that the deletion has been aborted - // this is the same as rsync - exit_code = 25; - break; - } - del_cnt += 1; - assert!(path.starts_with(download_dir)); + + for entry in walkdir::WalkDir::new(download_dir).contents_first(true) { + let entry = match entry { + Ok(entry) => entry, + Err(e) => { + error!("Failed to walkdir: {:?}", e); + if !args.dry_run { + exit_code = 1; + } + break; + } + }; + let path = entry.path(); + if !remote_list.contains(&path.to_path_buf()) { + if !args.no_delete { + // always make sure that we are deleting the right thing + if del_cnt >= args.max_delete { + info!("Exceeding max delete count, aborting"); + // exit with 25 to indicate that the deletion has been aborted + // this is the same as rsync + exit_code = 25; + break; + } + del_cnt += 1; + assert!(path.starts_with(download_dir)); + if args.dry_run { + info!("Dry run, not deleting {:?}", path); + continue; + } else { info!("Deleting {:?}", path); - if entry.file_type().is_dir() { - if let Err(e) = std::fs::remove_dir(path) { - error!("Failed to remove {:?}: {:?}", path, e); - exit_code = 4; - } - } else if let Err(e) = std::fs::remove_file(path) { + } + if entry.file_type().is_dir() { + if let Err(e) = std::fs::remove_dir(path) { error!("Failed to remove {:?}: {:?}", path, e); exit_code = 4; } - } else { - info!("{:?} not in remote", path); + } else if let Err(e) = std::fs::remove_file(path) { + error!("Failed to remove {:?}: {:?}", path, e); + exit_code = 4; } + } else { + info!("{:?} not in remote", path); } } } diff --git a/src/parser/directory_lister.rs b/src/parser/directory_lister.rs new file mode 100644 index 0000000..c5d4fd1 --- /dev/null +++ b/src/parser/directory_lister.rs @@ -0,0 +1,148 @@ +use crate::{ + listing::{FileSize, FileType, ListItem}, + utils::get, +}; + +use super::{ListResult, Parser}; +use anyhow::Result; +use chrono::NaiveDateTime; +use scraper::{Html, Selector}; + +#[derive(Debug, Clone, Default)] +pub struct DirectoryListerListingParser; + +impl Parser for DirectoryListerListingParser { + fn get_list(&self, client: &reqwest::blocking::Client, url: &url::Url) -> Result { + let resp = get(client, url.clone())?; + let url = resp.url().clone(); + let body = resp.text()?; + assert!( + url.path().ends_with('/'), + "URL for listing should have a trailing slash" + ); + let document = Html::parse_document(&body); + // https://github.com/DirectoryLister/DirectoryLister/blob/0283f14aa1fbd97796f753e8d6105c752546050f/app/views/components/file.twig + + // find