Skip to content

Commit 75594ba

Browse files
authored
Merge pull request #2906 from jyn514/remove-dead-code
Remove dead code warning for test-only `size` field for `diskio::Item`
2 parents 0e163d2 + 9f28b67 commit 75594ba

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/diskio/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ pub(crate) struct Item {
193193
start: Option<Instant>,
194194
/// Amount of time the operation took to finish
195195
finish: Option<Duration>,
196-
/// The length of the file, for files (for stats)
197-
size: Option<usize>,
198196
/// The result of the operation (could now be factored into CompletedIO...)
199197
pub(crate) result: io::Result<()>,
200198
/// The mode to apply
@@ -216,20 +214,17 @@ impl Item {
216214
kind: Kind::Directory,
217215
start: None,
218216
finish: None,
219-
size: None,
220217
result: Ok(()),
221218
mode,
222219
}
223220
}
224221

225222
pub(crate) fn write_file(full_path: PathBuf, mode: u32, content: FileBuffer) -> Self {
226-
let len = content.len();
227223
Self {
228224
full_path,
229225
kind: Kind::File(content),
230226
start: None,
231227
finish: None,
232-
size: Some(len),
233228
result: Ok(()),
234229
mode,
235230
}
@@ -246,7 +241,6 @@ impl Item {
246241
kind: Kind::IncrementalFile(content_callback),
247242
start: None,
248243
finish: None,
249-
size: None,
250244
result: Ok(()),
251245
mode,
252246
};

src/diskio/test.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ use anyhow::Result;
44

55
use crate::test::test_dir;
66

7-
use super::{get_executor, Executor, Item};
7+
use super::{get_executor, Executor, Item, Kind};
88
use crate::currentprocess;
99

10+
impl Item {
11+
/// The length of the file, for files (for stats)
12+
fn size(&self) -> Option<usize> {
13+
match &self.kind {
14+
Kind::File(buf) => Some(buf.len()),
15+
_ => None,
16+
}
17+
}
18+
}
19+
1020
fn test_incremental_file(io_threads: &str) -> Result<()> {
1121
let work_dir = test_dir()?;
1222
let mut vars = HashMap::new();
@@ -96,10 +106,10 @@ fn test_complete_file(io_threads: &str) -> Result<()> {
96106
assert_eq!(chunk.len(), 10);
97107
chunk = chunk.finished();
98108
let item = Item::write_file(work_dir.path().join("scratch"), 0o666, chunk);
99-
assert_eq!(item.size, Some(10));
109+
assert_eq!(item.size(), Some(10));
100110
let mut items = 0;
101111
let mut check_item = |item: Item| {
102-
assert_eq!(item.size, Some(10));
112+
assert_eq!(item.size(), Some(10));
103113
items += 1;
104114
assert_eq!(1, items);
105115
};

0 commit comments

Comments
 (0)