estimate: size CalDAV and CardDAV items too #68
No files matched your search
@@ -38,8 +38,9 @@ later `import` into the same archive adds what arrived since. Every command
|
||||
takes `--dry-run` and then only reports the plan. An `import` also takes
|
||||
`--estimate`, which connects to the source and reports how much is new to
|
||||
fetch — counts, bytes and a rough time — before committing, and writes
|
||||
nothing. It reports sizes for `imap` and `maildir`; other sources fall back to
|
||||
a plain dry-run. `inspect` reads an archive and changes nothing.
|
||||
nothing. It reports sizes for `imap`, `maildir`, `caldav` and `carddav`; other
|
||||
sources fall back to a plain dry-run. `inspect` reads an archive and changes
|
||||
nothing.
|
||||
|
||||
The archive is also a backup. Import on a schedule, keep the file, and
|
||||
restore it later with `export`. An archive remembers which account filled it
|
||||
|
||||
+13
-7
@@ -156,8 +156,9 @@ struct GlobalArgs {
|
||||
help = "Preview an import: counts, sizes and a rough time, before any writes",
|
||||
long_help = "Preview an import before committing: for each type, how much is new since \
|
||||
the archive was last filled, how many bytes that is, and a rough time.\n \
|
||||
Available for imap and maildir today; other sources fall back to --dry-run with a \
|
||||
note. It implies --dry-run, so it never writes. On an export it is just --dry-run."
|
||||
Available for imap, maildir, caldav and carddav today; other sources fall back to \
|
||||
--dry-run with a note. It implies --dry-run, so it never writes. On an export it is \
|
||||
just --dry-run."
|
||||
)]
|
||||
estimate: bool,
|
||||
|
||||
@@ -918,14 +919,19 @@ impl Action {
|
||||
}
|
||||
|
||||
/// Whether this import can give the size-and-time estimate: the source
|
||||
/// enumerates messages in its dry run and can size them cheaply. The
|
||||
/// enumerates its items in its dry run and can size them cheaply. The
|
||||
/// others fall back to a plain dry run with a note; adding them is
|
||||
/// per-source follow-up work.
|
||||
pub fn estimate_available(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Action::ImportImap(c, _) | Action::ImportMaildir(c, _) if c.estimate
|
||||
)
|
||||
match self {
|
||||
Action::ImportImap(c, _) | Action::ImportMaildir(c, _) => c.estimate,
|
||||
// CalDAV and CardDAV size their items from the getcontentlength
|
||||
// the enumeration PROPFIND already returns. WebDAV files go
|
||||
// through the same command but report differently, so they stay
|
||||
// on the fallback for now.
|
||||
Action::ImportDav(c, cfg) => c.estimate && !matches!(cfg.kind, DavKindArg::Webdav),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ pub fn propfind_dav_items() -> String {
|
||||
<d:resourcetype/>\
|
||||
<d:getetag/>\
|
||||
<d:getcontenttype/>\
|
||||
<d:getcontentlength/>\
|
||||
<d:getlastmodified/>\
|
||||
</d:prop>\
|
||||
</d:propfind>",
|
||||
@@ -305,4 +306,11 @@ mod tests {
|
||||
assert!(body.contains("<d:getcontentlength/>"));
|
||||
assert!(body.contains("<d:creationdate/>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dav_items_request_a_content_length_so_estimate_can_size_them() {
|
||||
let body = propfind_dav_items();
|
||||
assert!(body.contains("<d:getcontentlength/>"));
|
||||
assert!(body.contains("<d:getetag/>"));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -35,7 +35,7 @@ fn run() -> i32 {
|
||||
if action.estimate_requested() && !do_estimate {
|
||||
eprintln!(
|
||||
"note: --estimate isn't available for this source yet; running --dry-run instead \
|
||||
(its plan is below). Estimates work for imap and maildir today."
|
||||
(its plan is below). Estimates work for imap, maildir, caldav and carddav today."
|
||||
);
|
||||
}
|
||||
let mut quiet_report = false;
|
||||
|
||||
@@ -173,7 +173,15 @@ fn run_into(
|
||||
);
|
||||
}
|
||||
}
|
||||
let result = run_dry_diff(&conn, &client, &discovery, &config, logger, summary);
|
||||
let result = run_dry_diff(
|
||||
&conn,
|
||||
&client,
|
||||
&discovery,
|
||||
&config,
|
||||
common.estimate,
|
||||
logger,
|
||||
summary,
|
||||
);
|
||||
summary.retries_observed = client.retries_observed();
|
||||
summary.retry_after_sleeps = client.retry_after_sleeps();
|
||||
return result;
|
||||
@@ -340,6 +348,7 @@ fn run_dry_diff(
|
||||
client: &DavClient,
|
||||
discovery: &Discovery,
|
||||
config: &DavImportConfig,
|
||||
want_sizes: bool,
|
||||
logger: Logger,
|
||||
summary: &mut Summary,
|
||||
) -> Result<(), Error> {
|
||||
@@ -387,12 +396,21 @@ fn run_dry_diff(
|
||||
.map_err(super::per_collection_failure)
|
||||
{
|
||||
Ok(ms) => {
|
||||
let new_count = ms
|
||||
.responses
|
||||
.iter()
|
||||
.filter(|r| !r.props.is_collection)
|
||||
.count();
|
||||
item_counts.created += new_count as u64;
|
||||
let mut new_count = 0u64;
|
||||
let mut bytes = 0u64;
|
||||
for r in ms.responses.iter().filter(|r| !r.props.is_collection) {
|
||||
new_count += 1;
|
||||
// --estimate: getcontentlength comes back in the same
|
||||
// PROPFIND, so sizing the items costs no extra request.
|
||||
// A server that omits it leaves those items unsized.
|
||||
if let Some(n) = r.props.content_length {
|
||||
bytes += n;
|
||||
}
|
||||
}
|
||||
item_counts.created += new_count;
|
||||
if want_sizes {
|
||||
item_counts.bytes += bytes;
|
||||
}
|
||||
if logger.enabled(LEVEL_DEFAULT) {
|
||||
eprintln!(" {} items: {new_count}", coll.href.as_str());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user