1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use Path;
use_enabled_fs_module!;
use crate::;
/// Retrieve the size of a file in bytes.
///
///
/// ## Symbolic link behaviour
/// Symbolic links are not followed.
///
/// This matches the behaviour of `du` on Unix[^unix-du].
///
///
/// # Errors
/// If the size of the file cannot be retrieved, a [`FileSizeError`] is returned;
/// see its documentation for more details.
/// Here is a non-exhaustive list of error causes:
/// - If the file does not exist, a [`NotFound`] variant is returned.
/// - If the path exists, but is not a file, [`NotAFile`] is returned.
/// - If there is an issue accessing the file, for example due to missing permissions,
/// then a [`UnableToAccessFile`] is returned.
///
/// There do exist other failure points, mostly due to unavoidable
/// [time-of-check time-of-use](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use)
/// issues and other potential IO errors that can prop up.
/// These errors are grouped under the [`OtherIoError`] variant.
///
///
/// [`NotFound`]: FileSizeError::NotFound
/// [`NotAFile`]: FileSizeError::NotAFile
/// [`UnableToAccessFile`]: FileSizeError::UnableToAccessFile
/// [`OtherIoError`]: FileSizeError::OtherIoError
/// [^unix-du]: Source for coreutils' `du` is available
/// [here](https://github.com/coreutils/coreutils/blob/ccf47cad93bc0b85da0401b0a9d4b652e4c930e4/src/du.c).