Skip to content

Commit be86864

Browse files
committed
Add conserve versions --utc
This should fix tests that assumed they were run in a particular timezone.
1 parent 6546d34 commit be86864

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
- Better display of deletion stats.
1010

11+
- New `conserve versions --utc` option.
12+
1113
## v0.6.10 2020-12-30
1214

1315
### Features

src/bin/conserve.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ enum Command {
148148
/// Show size of stored trees.
149149
#[structopt(long, short = "z", conflicts_with = "short")]
150150
sizes: bool,
151+
/// Show times in UTC.
152+
#[structopt(long)]
153+
utc: bool,
151154
},
152155
}
153156

@@ -355,13 +358,14 @@ impl Command {
355358
archive,
356359
short,
357360
sizes,
361+
utc,
358362
} => {
359363
ui::enable_progress(false);
360364
let archive = Archive::open_path(archive)?;
361365
if *short {
362366
output::show_brief_version_list(&archive, &mut stdout)?;
363367
} else {
364-
output::show_verbose_version_list(&archive, *sizes, &mut stdout)?;
368+
output::show_verbose_version_list(&archive, *sizes, *utc, &mut stdout)?;
365369
}
366370
}
367371
}

src/output.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Conserve backup system.
2-
// Copyright 2018, 2020 Martin Pool.
2+
// Copyright 2018, 2020, 2021 Martin Pool.
33

44
// This program is free software; you can redistribute it and/or modify
55
// it under the terms of the GNU General Public License as published by
@@ -18,8 +18,6 @@
1818
1919
use std::io::{BufWriter, Write};
2020

21-
use chrono::Local;
22-
2321
use crate::*;
2422

2523
pub fn show_brief_version_list(archive: &Archive, w: &mut dyn Write) -> Result<()> {
@@ -29,9 +27,16 @@ pub fn show_brief_version_list(archive: &Archive, w: &mut dyn Write) -> Result<(
2927
Ok(())
3028
}
3129

30+
/// Print a list of versions, one per line.
31+
///
32+
/// With `show_sizes` the (unpacked) size of the stored tree is included. This is
33+
/// slower because it requires walking the whole index.
34+
///
35+
/// With `utc_times`, times are shown in UTC rather than the local timezone.
3236
pub fn show_verbose_version_list(
3337
archive: &Archive,
3438
show_sizes: bool,
39+
utc_times: bool,
3540
w: &mut dyn Write,
3641
) -> Result<()> {
3742
for band_id in archive.list_band_ids()? {
@@ -54,10 +59,12 @@ pub fn show_verbose_version_list(
5459
} else {
5560
"incomplete"
5661
};
57-
let start_time_str = info
58-
.start_time
59-
.with_timezone(&Local)
60-
.format(crate::TIMESTAMP_FORMAT);
62+
let start_time = info.start_time;
63+
let start_time_str = if utc_times {
64+
start_time.format(crate::TIMESTAMP_FORMAT)
65+
} else {
66+
start_time.with_timezone(&chrono::Local).format(crate::TIMESTAMP_FORMAT)
67+
};
6168
let duration_str = info
6269
.end_time
6370
.and_then(|et| (et - info.start_time).to_std().ok())

tests/cli/versions.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,39 @@
1111
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
// GNU General Public License for more details.
1313

14+
//! Tests of the `conserve versions` command.
15+
1416
use assert_cmd::prelude::*;
17+
use predicates::function::function;
1518

1619
use crate::run_conserve;
1720

1821
#[test]
1922
fn versions() {
2023
run_conserve()
21-
.args(&["versions", "testdata/archive/simple/v0.6.10"])
24+
.args(&["versions", "--utc", "testdata/archive/simple/v0.6.10"])
2225
.assert()
2326
.success()
2427
.stdout(
2528
"\
26-
b0000 complete 2021-03-04 05:21:15 0:00
27-
b0001 complete 2021-03-04 05:21:30 0:00
28-
b0002 complete 2021-03-04 05:27:28 0:00
29+
b0000 complete 2021-03-04 13:21:15 0:00
30+
b0001 complete 2021-03-04 13:21:30 0:00
31+
b0002 complete 2021-03-04 13:27:28 0:00
2932
",
3033
);
3134
}
3235

36+
#[test]
37+
fn versions_in_local_time() {
38+
// Without --utc we don't know exactly what times will be produced,
39+
// and it's hard to control the timezone for tests on Windows.
40+
run_conserve()
41+
.args(&["versions", "testdata/archive/simple/v0.6.10"])
42+
.assert()
43+
.success()
44+
.stdout(function(|s: &str| s.lines().count() == 3));
45+
}
46+
3347
#[test]
3448
fn versions_short() {
3549
run_conserve()
@@ -48,14 +62,19 @@ b0002
4862
#[test]
4963
fn versions_sizes() {
5064
run_conserve()
51-
.args(&["versions", "--sizes", "testdata/archive/simple/v0.6.10"])
65+
.args(&[
66+
"versions",
67+
"--sizes",
68+
"--utc",
69+
"testdata/archive/simple/v0.6.10",
70+
])
5271
.assert()
5372
.success()
5473
.stdout(
5574
"\
56-
b0000 complete 2021-03-04 05:21:15 0:00 0 MB
57-
b0001 complete 2021-03-04 05:21:30 0:00 0 MB
58-
b0002 complete 2021-03-04 05:27:28 0:00 0 MB
75+
b0000 complete 2021-03-04 13:21:15 0:00 0 MB
76+
b0001 complete 2021-03-04 13:21:30 0:00 0 MB
77+
b0002 complete 2021-03-04 13:27:28 0:00 0 MB
5978
",
6079
);
6180
}

0 commit comments

Comments
 (0)