Skip to content

Commit

Permalink
Must load timezone before starting threads
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Sep 1, 2023
1 parent dfcd203 commit 4bef6d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ snap = "1.0.0"
tempfile = "3"
thiserror = "1.0.19"
thousands = "0.2.0"
time = { version = "0.3", features = [
time = { version = "0.3.28", features = [
"local-offset",
"serde",
"serde-human-readable",
Expand Down
7 changes: 6 additions & 1 deletion src/bin/conserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use conserve::change::Change;
use conserve::progress::ProgressImpl;
use conserve::trace_counter::{global_error_count, global_warn_count};
use metrics::increment_counter;
use time::UtcOffset;
#[allow(unused_imports)]
use tracing::{debug, error, info, trace, warn, Level};

Expand Down Expand Up @@ -292,6 +293,9 @@ impl std::process::Termination for ExitCode {
impl Command {
fn run(&self) -> Result<ExitCode> {
let mut stdout = std::io::stdout();
// Before anything else, get the local time offset, to avoid `time-rs`
// problems with loading it when threads are running.
let local_offset = UtcOffset::current_local_offset().expect("get local time offset");
match self {
Command::Backup {
archive,
Expand Down Expand Up @@ -516,11 +520,12 @@ impl Command {
sizes,
utc,
} => {
let timezone = if *utc { None } else { Some(local_offset) };
let archive = Archive::open(open_transport(archive)?)?;
let options = ShowVersionsOptions {
newest_first: *newest,
tree_size: *sizes,
utc: *utc,
timezone,
start_time: !*short,
backup_duration: !*short,
};
Expand Down
9 changes: 4 additions & 5 deletions src/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub struct ShowVersionsOptions {
pub start_time: bool,
/// Show how much time the backup took, or "incomplete" if it never finished.
pub backup_duration: bool,
/// Show times in UTC rather than the local timezone.
pub utc: bool,
/// Show times in this zone.
pub timezone: Option<UtcOffset>,
}

/// Print a list of versions, one per line.
Expand All @@ -53,7 +53,6 @@ pub fn show_versions(
if options.newest_first {
band_ids.reverse();
}
let local_offset = UtcOffset::current_local_offset().expect("get local time offset");
for band_id in band_ids {
if !(options.tree_size || options.start_time || options.backup_duration) {
writeln!(w, "{band_id}")?;
Expand All @@ -78,8 +77,8 @@ pub fn show_versions(

if options.start_time {
let mut start_time = info.start_time;
if !options.utc {
start_time = start_time.to_offset(local_offset);
if let Some(timezone) = options.timezone {
start_time = start_time.to_offset(timezone);
}
l.push(format!(
"{date:<25}", // "yyyy-mm-ddThh:mm:ss+oooo" => 25
Expand Down

0 comments on commit 4bef6d9

Please sign in to comment.