Skip to content

Commit c31c9f6

Browse files
committed
Replace [chrono] with [time] to address [RUSTSEC-2020-0159]
[chrono]: https://crates.io/crates/chrono [time]: https://crates.io/crates/time [RUSTSEC-2020-0159]: https://rustsec.org/advisories/RUSTSEC-2020-0159
1 parent 3b05202 commit c31c9f6

File tree

9 files changed

+45
-49
lines changed

9 files changed

+45
-49
lines changed

CHANGELOG.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
<!-- next-header -->
9-
<!-- ## [Unreleased] - ReleaseDate -->
9+
## [Unreleased] - ReleaseDate
10+
11+
Replaced [chrono] with [time] to address [RUSTSEC-2020-0159].
12+
13+
[chrono]: https://crates.io/crates/chrono
14+
[time]: https://crates.io/crates/time
15+
[RUSTSEC-2020-0159]: https://rustsec.org/advisories/RUSTSEC-2020-0159
1016

1117
## [1.0.0] - 2022-03-29
1218

1319
I'm using it regularly on Linux and MacOS. It works well and has all the features I need, so... happy v1.0! :tada: :rocket:
1420

1521
## [0.9.1] - 2022-03-28
1622

17-
- Fix: When archiving, subprojects are cleaned but no longer attempted to be archived. This doesn't change the current behavior: subprojects are still included in the tar.xz file as-is and not as nested archives. But previously, the attempt to archive the subproject after the parent project produced an error, and the user needed to execute the command again to continue archiving the remaining projects.
23+
Fix: When archiving, subprojects are cleaned but no longer attempted to be archived. This doesn't change the current behavior: subprojects are still included in the tar.xz file as-is and not as nested archives. But previously, the attempt to archive the subproject after the parent project produced an error, and the user needed to execute the command again to continue archiving the remaining projects.
1824

1925
## [0.9.0] - 2022-03-26
2026

21-
- Support multiple directories as input. For example:
27+
Support multiple directories as input. For example:
2228

23-
```bash
24-
makeclean -l ~/code ~/work ~/projects
25-
```
29+
```bash
30+
makeclean -l ~/code ~/work ~/projects
31+
```
2632

2733
## [0.8.0] - 2022-03-24
2834

Cargo.lock

Lines changed: 12 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pre-release-replacements = [
2727
[dependencies]
2828
anyhow = "1.0.45"
2929
assert_fs = "1.0.7"
30-
chrono = "0.4.19"
3130
clap = { version = "3.1.3", features = [
3231
"derive",
3332
"env",
@@ -47,6 +46,7 @@ serde_yaml = "0.8.23"
4746
tabular = "0.1.4"
4847
tar = "0.4.38"
4948
thiserror = "1.0.30"
49+
time = { version = "0.3.9", features = ["formatting"] }
5050
toml = "0.5.8"
5151
tracing = "0.1.26"
5252
tracing-subscriber = { version = "0.3.8", features = ["json"] }

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use std::path::PathBuf;
66

7-
use chrono::Duration;
87
use clap::Parser;
98
use regex::Regex;
9+
use time::Duration;
1010

1111
use crate::build_tools::BuildToolKind;
1212

src/find_projects.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mod test {
4444
fixture::{FileWriteStr, PathChild, PathCreateDir},
4545
TempDir,
4646
};
47-
use chrono::Duration;
47+
use time::Duration;
4848

4949
use crate::{
5050
build_tool_manager::BuildToolManager,
@@ -102,7 +102,7 @@ mod test {
102102

103103
fn project_filter() -> ProjectFilter {
104104
ProjectFilter {
105-
min_stale: Duration::zero(),
105+
min_stale: Duration::ZERO,
106106
status: StatusFilter::Any,
107107
}
108108
}

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub mod project;
77

88
use anyhow::Context;
99
use build_tool_manager::BuildToolManager;
10-
use chrono::Duration;
1110
use clap::{CommandFactory, ErrorKind};
1211
use console::{colors_enabled, style};
1312
use dialoguer::{
@@ -20,6 +19,7 @@ use std::{
2019
io,
2120
path::{Path, PathBuf},
2221
};
22+
use time::Duration;
2323
use tracing::debug;
2424

2525
pub use crate::cli::Cli;
@@ -32,7 +32,7 @@ use crate::{
3232
/// Prints projects to stdout.
3333
pub fn list(cli: Cli, build_tool_manager: BuildToolManager) -> anyhow::Result<()> {
3434
let project_filter = {
35-
let min_stale = cli.min_stale.unwrap_or_else(Duration::zero);
35+
let min_stale = cli.min_stale.unwrap_or(Duration::ZERO);
3636
let status = StatusFilter::Any;
3737
ProjectFilter { min_stale, status }
3838
};
@@ -272,8 +272,7 @@ fn pretty_print_project(project: &Project) -> anyhow::Result<()> {
272272
0 => String::new(),
273273
bytes => format!("; {}", format_size(bytes)),
274274
};
275-
// See https://docs.rs/chrono/latest/chrono/format/strftime/index.html
276-
let mtime = project.mtime.format("%F");
275+
let mtime = project.mtime.to_string();
277276

278277
let path = ProjectPath::from(project).render(use_color);
279278

src/project.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use crate::{
1111
build_tools::{BuildStatus, BuildTool},
1212
};
1313
use anyhow::format_err;
14-
use chrono::{DateTime, Duration, Local, Utc};
1514
use std::{
1615
fmt,
1716
path::{Path, PathBuf},
1817
};
18+
use time::{Duration, OffsetDateTime};
1919
use tracing::{trace, warn};
2020

2121
use self::{mtime::dir_mtime, vcs::VersionControlSystem};
@@ -35,7 +35,7 @@ pub struct Project {
3535
/// The VCS, if under version control.
3636
pub vcs: Option<VersionControlSystem>,
3737
/// When this project was last modified (most recent commit timestamp).
38-
pub mtime: DateTime<Utc>,
38+
pub mtime: OffsetDateTime,
3939
}
4040

4141
impl Project {
@@ -70,10 +70,9 @@ impl Project {
7070

7171
let mtime = dir_mtime(path)
7272
.ok_or_else(|| format_err!("BUG: build tool recognized but no files?!"))?;
73-
let mtime: DateTime<Local> = mtime.into();
74-
let mtime: DateTime<Utc> = mtime.into();
73+
let now = OffsetDateTime::now_utc();
7574

76-
if Utc::now().signed_duration_since(mtime) < project_filter.min_stale {
75+
if (now - mtime) < project_filter.min_stale {
7776
trace!(
7877
?path,
7978
%mtime,

src/project/dto.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Representation of a [`Project`] used for JSON output.
22
33
use serde::{Deserialize, Serialize};
4+
use time::format_description::well_known::Rfc3339;
45

56
use crate::Project;
67

@@ -19,7 +20,7 @@ pub struct ProjectDto {
1920
pub build_tools: Vec<String>,
2021
/// The VCS, if under version control.
2122
pub vcs: Option<VcsDto>,
22-
/// When this project was last modified (most recent commit timestamp).
23+
/// When this project was last modified (most recent commit timestamp), in RFC3339.
2324
pub mtime: String,
2425
}
2526

@@ -34,7 +35,10 @@ impl From<&Project> for ProjectDto {
3435
.map(|x| x.to_string())
3536
.collect::<Vec<_>>(),
3637
vcs: project.vcs.as_ref().map(VcsDto::from),
37-
mtime: project.mtime.to_rfc3339(),
38+
mtime: project
39+
.mtime
40+
.format(&Rfc3339)
41+
.expect("can format as RFC3339"),
3842
}
3943
}
4044
}

src/project/mtime.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use ignore::WalkBuilder;
2-
use std::{path::Path, time::SystemTime};
2+
use std::path::Path;
3+
use time::OffsetDateTime;
34

4-
pub(crate) fn dir_mtime(path: &Path) -> Option<SystemTime> {
5+
pub(crate) fn dir_mtime(path: &Path) -> Option<OffsetDateTime> {
56
WalkBuilder::new(path)
67
.standard_filters(true)
78
.hidden(false)
@@ -10,5 +11,6 @@ pub(crate) fn dir_mtime(path: &Path) -> Option<SystemTime> {
1011
.filter_map(|entry| entry.metadata().ok())
1112
.filter(|metadata| metadata.is_file())
1213
.filter_map(|metadata| metadata.modified().ok())
14+
.map(OffsetDateTime::from)
1315
.max()
1416
}

0 commit comments

Comments
 (0)