Skip to content

Commit ae52c10

Browse files
committed
chore(git): merge from master
2 parents 900d13a + 67d3079 commit ae52c10

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

src/app.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod sub;
33
pub use sub::Sub;
44

55
use crate::{
6-
args::{Args, Quantity},
6+
args::{Args, Quantity, Threads},
77
get_size::GetApparentSize,
88
json_data::{JsonData, UnitAndTree},
99
reporter::{ErrorOnlyReporter, ErrorReport, ProgressAndErrorReporter, ProgressReport},
@@ -12,8 +12,10 @@ use crate::{
1212
visualizer::{BarAlignment, Direction, Visualizer},
1313
};
1414
use clap::Parser;
15+
use hdd::any_path_is_in_hdd;
1516
use pipe_trait::Pipe;
1617
use std::{io::stdin, time::Duration};
18+
use sysinfo::Disks;
1719

1820
#[cfg(unix)]
1921
use crate::{
@@ -44,6 +46,27 @@ impl App {
4446
//
4547
// The other operations which are invoked frequently should not utilize dynamic dispatch.
4648

49+
let threads = match self.args.threads {
50+
Threads::Auto => {
51+
let disks = Disks::new_with_refreshed_list();
52+
if any_path_is_in_hdd::<hdd::RealApi>(&self.args.files, &disks) {
53+
eprintln!("warning: HDD detected, the thread limit will be set to 1");
54+
Some(1)
55+
} else {
56+
None
57+
}
58+
}
59+
Threads::Max => None,
60+
Threads::Fixed(threads) => Some(threads),
61+
};
62+
63+
if let Some(threads) = threads {
64+
rayon::ThreadPoolBuilder::new()
65+
.num_threads(threads)
66+
.build_global()
67+
.unwrap_or_else(|_| eprintln!("warning: Failed to set thread limit to {threads}"));
68+
}
69+
4770
let column_width_distribution = self.args.column_width_distribution();
4871

4972
if self.args.json_input {
@@ -141,7 +164,6 @@ impl App {
141164
max_depth,
142165
min_ratio,
143166
no_sort,
144-
threads,
145167
..
146168
} => Sub {
147169
direction: Direction::from_top_down(top_down),
@@ -155,7 +177,6 @@ impl App {
155177
max_depth,
156178
min_ratio,
157179
no_sort,
158-
threads,
159180
}
160181
.run(),
161182
)*} };
@@ -204,3 +225,6 @@ impl App {
204225
}
205226
}
206227
}
228+
229+
mod hdd;
230+
mod mount_point;
File renamed without changes.
File renamed without changes.

src/app/sub.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
mod hdd;
2-
mod mount_point;
3-
41
use crate::{
5-
args::{Fraction, Threads},
2+
args::Fraction,
63
data_tree::{DataTree, DataTreeReflection},
74
fs_tree_builder::FsTreeBuilder,
85
get_size::GetSize,
@@ -14,10 +11,8 @@ use crate::{
1411
status_board::GLOBAL_STATUS_BOARD,
1512
visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer},
1613
};
17-
use hdd::any_path_is_in_hdd;
1814
use serde::Serialize;
1915
use std::{io::stdout, iter::once, num::NonZeroUsize, path::PathBuf};
20-
use sysinfo::Disks;
2116

2217
/// The sub program of the main application.
2318
pub struct Sub<Size, SizeGetter, Report>
@@ -47,8 +42,6 @@ where
4742
pub reporter: Report,
4843
/// Minimal size proportion required to appear.
4944
pub min_ratio: Fraction,
50-
/// The number of threads [`rayon`] can use.
51-
pub threads: Threads,
5245
/// Preserve order of entries.
5346
pub no_sort: bool,
5447
}
@@ -73,31 +66,9 @@ where
7366
size_getter,
7467
reporter,
7568
min_ratio,
76-
threads,
7769
no_sort,
7870
} = self;
7971

80-
let threads = match threads {
81-
Threads::Auto => {
82-
let disks = Disks::new_with_refreshed_list();
83-
if any_path_is_in_hdd::<hdd::RealApi>(&files, &disks) {
84-
eprintln!("warning: HDD detected, the thread limit will be set to 1");
85-
Some(1)
86-
} else {
87-
None
88-
}
89-
}
90-
Threads::Max => None,
91-
Threads::Fixed(threads) => Some(threads),
92-
};
93-
94-
if let Some(threads) = threads {
95-
rayon::ThreadPoolBuilder::new()
96-
.num_threads(threads)
97-
.build_global()
98-
.unwrap_or_else(|_| eprintln!("warning: Failed to set thread limit to {threads}"));
99-
}
100-
10172
let mut iter = files
10273
.into_iter()
10374
.map(|root| -> DataTree<OsStringDisplay, Size> {

0 commit comments

Comments
 (0)