Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! Simple library to handle configuration fragments.
2 //!
3 //! This crate provides helpers to scan configuration fragments on disk.
4 //! The goal is to help in writing Linux services which are shipped as part of a [Reproducible OS][reproducible].
5 //! Its name derives from **over**lays and **drop**ins (base directories and configuration fragments).
6 //!
7 //! The main entrypoint is [`scan`](fn.scan.html). It scans
8 //! for configuration fragments across multiple directories (with increasing priority),
9 //! following these rules:
10 //!
11 //! * fragments are identified by unique filenames, lexicographically (e.g. `50-default-limits.conf`).
12 //! * in case of name duplication, last directory wins (e.g. `/etc/svc/custom.conf` can override `/usr/lib/svc/custom.conf`).
13 //! * a fragment symlinked to `/dev/null` is used to ignore any previous fragment with the same filename.
14 //!
15 //! [reproducible]: http://0pointer.net/blog/projects/stateless.html
16 //!
17 //! # Example
18 //!
19 //! ```rust,no_run
20 //! # use liboverdrop;
21 //! // Scan for fragments under:
22 //! // * /usr/lib/my-crate/config.d/*.toml
23 //! // * /run/my-crate/config.d/*.toml
24 //! // * /etc/my-crate/config.d/*.toml
25 //!
26 //! let base_dirs = [
27 //! "/usr/lib",
28 //! "/run",
29 //! "/etc",
30 //! ];
31 //! let fragments = liboverdrop::scan(&base_dirs, "my-crate/config.d", &["toml"], false);
32 //!
33 //! for (filename, filepath) in fragments {
34 //! println!("fragment '{}' located at '{}'", filename.to_string_lossy(), filepath.display());
35 //! }
36 //! ```
37 //!
38 //! # Migrating from liboverdrop 0.0.x
39 //!
40 //! The signature changed from
41 //! ```rust,compile_fail
42 //! # use liboverdrop::FragmentScanner;
43 //! let base_dirs: Vec<String> = vec![/**/];
44 //! let shared_path: &str = "config.d";
45 //! let allowed_extensions: Vec<String> = vec![/**/];
46 //! for (basename, filepath) in FragmentScanner::new(
47 //! base_dirs, shared_path, false, allowed_extensions).scan() {
48 //! // basename: String
49 //! // filepath: PathBuf
50 //! }
51 //! ```
52 //! to
53 //! ```rust,no_run
54 //! # use liboverdrop;
55 //! # /*
56 //! let base_dirs: IntoIterator<Item = AsRef<Path>> = /* could be anything */;
57 //! let shared_path: AsRef<Path> = /* ... */;
58 //! let allowed_extensions: &[AsRef<OsStr>] = &[/* ... */];
59 //! # */
60 //! # let base_dirs = [""];
61 //! # let shared_path = "";
62 //! # let allowed_extensions = &[""];
63 //! for (basename, filepath) in liboverdrop::scan(
64 //! base_dirs, shared_path, allowed_extensions, false) {
65 //! // basename: OsString
66 //! // filepath: PathBuf
67 //! }
68 //! ```
69 //!
70 //! When updating, re-consider if you need to allocate any argument now,
71 //! since they can all be literals or borrowed.
72
73 use logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!;
74 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
75 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#};
76 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/;
77 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#};
78
79 /// The well-known path to the null device used for overrides.
80 const DEVNULLrust-analyzer cargo liboverdrop 0.1.0 DEVNULL.: &str = "/dev/null";
81
82 /// Scan unique configuration fragments from the configuration directories specified.
83 ///
84 /// # Arguments
85 ///
86 /// * `base_dirs` - Base components of directories where configuration fragments are located.
87 /// * `shared_path` - Common relative path from each entry in `base_dirs` to the directory
88 /// holding configuration fragments.
89 /// * `allowed_extensions` - Only scan files that have an extension listed in `allowed_extensions`.
90 /// If an empty slice is passed, then all extensions are allowed.
91 /// * `ignore_dotfiles` - Whether to ignore dotfiles (hidden files with name prefixed with '.').
92 ///
93 /// `shared_path` is joined onto each entry in `base_dirs` to form the directory paths to scan.
94 ///
95 /// Returns a `BTreeMap` indexed by configuration fragment filename,
96 /// holding the path where the unique configuration fragment is located.
97 ///
98 /// Configuration fragments are stored in the `BTreeMap` in alphanumeric order by filename.
99 /// Configuration fragments existing in directories that are scanned later override fragments
100 /// of the same filename in directories that are scanned earlier.
101 pub fn scanrust-analyzer cargo liboverdrop 0.1.0 scan().<BdS: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, BdI: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = BdS>, Sp: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, As: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(
102 base_dirs: BdI,
103 shared_path: Sp,
104 allowed_extensions: &[As],
105 ignore_dotfiles: bool,
106 ) -> BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#> {
107 let shared_path = shared_path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().();
108
109 let mut files_map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
110 for dir in base_dirs {
111 let dir = dir.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(shared_path);
112 tracerust-analyzer cargo log 0.4.34 macros/trace!!("Scanning directory '{}'", dir.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
113
114 let dir_iter = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(dir) {
115 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(iter) => iter,
116 _ => continue,
117 };
118 for entry in dir_iter.flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
119 let fpath = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
120 let fname = entry.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().();
121
122 // If hidden files not allowed, ignore dotfiles.
123 // Rust RFC 900 &c.: there's no way to check if a Path/OsStr starts with a prefix;
124 // instead, we check via to_string_lossy(), which will only allocate if the basename wasn't UTF-8,
125 // and the lossiness doesn't bother us; https://github.com/rust-lang/rfcs/issues/900
126 if ignore_dotfiles && fname.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('.') {
127 continue;
128 }
129
130 // If extensions are specified, proceed only if filename has one of the allowed
131 // extensions.
132 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().allowed_extensions.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
133 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(extension) = fpath.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().() {
134 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().allowed_extensions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|ae| ae.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().extension) {
135 continue;
136 }
137 } else {
138 continue;
139 }
140 }
141
142 // Check filetype, ignore non-file.
143 let meta = match entry.metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]metadata().() {
144 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(m) => m,
145 _ => continue,
146 };
147 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().meta.file_typerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]file_type().().is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_file().() {
148 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(target) = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_linkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_link().(&fpath) {
149 // A devnull symlink is a special case to ignore previous file-names.
150 if target rust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`PartialEq<&Path>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`PartialEq<&Path>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`PartialEq<&Path>`]eq().Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(DEVNULLrust-analyzer cargo liboverdrop 0.1.0 DEVNULL.) {
151 tracerust-analyzer cargo log 0.4.34 macros/trace!!("Nulled config file '{}'", fpath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
152 files_map.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]remove().(&fname);
153 }
154 }
155 continue;
156 }
157
158 tracerust-analyzer cargo log 0.4.34 macros/trace!!(
159 "Found config file '{}' at '{}'",
160 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&fname).displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
161 fpath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
162 );
163 files_map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(fname, fpath);
164 }
165 }
166
167 files_map
168 }
169
170 #[cfg(test)]
171 mod testsrust-analyzer cargo liboverdrop 0.1.0 tests/ {
172 use superrust-analyzer cargo liboverdrop 0.1.0 crate/::*;
173
174 fn assert_fragments_matchrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_match().(
175 fragments: &BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>,
176 filename: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#,
177 filepath: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
178 ) {
179 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fragments.getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().(filename).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), filepath);
180 }
181
182 fn assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(fragments: &BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, filename: T) {
183 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(fragments.getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().(filename.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
184 }
185
186 fn assert_fragments_missrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_miss().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(
187 fragments: &BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>,
188 filename: T,
189 ) {
190 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(fragments.getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().(filename.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()).is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
191 }
192
193 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
194 fn basic_overriderust-analyzer cargo liboverdrop 0.1.0 tests/basic_override().() {
195 let treedir = "tests/fixtures/tree-basic";
196 let dirs = [
197 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", treedir, "usr/lib"),
198 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", treedir, "run"),
199 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", treedir, "etc"),
200 ];
201
202 let expected_fragments = [
203 (
204 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("01-config-a.toml"),
205 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(treedir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("etc/liboverdrop.d/01-config-a.toml"),
206 ),
207 (
208 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("02-config-b.toml"),
209 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(treedir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("run/liboverdrop.d/02-config-b.toml"),
210 ),
211 (
212 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("03-config-c.toml"),
213 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(treedir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("etc/liboverdrop.d/03-config-c.toml"),
214 ),
215 (
216 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("04-config-d.toml"),
217 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(treedir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("usr/lib/liboverdrop.d/04-config-d.toml"),
218 ),
219 (
220 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("05-config-e.toml"),
221 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(treedir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("etc/liboverdrop.d/05-config-e.toml"),
222 ),
223 (
224 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("06-config-f.toml"),
225 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(treedir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("run/liboverdrop.d/06-config-f.toml"),
226 ),
227 (
228 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("07-config-g.toml"),
229 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(treedir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("etc/liboverdrop.d/07-config-g.toml"),
230 ),
231 ];
232
233 let fragments = scanrust-analyzer cargo liboverdrop 0.1.0 scan().(&dirs, "liboverdrop.d", &["toml"], false);
234
235 for (name, path) in &expected_fragments {
236 assert_fragments_matchrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_match().(&fragments, &name, &path);
237 }
238
239 // Check keys are stored in the correct order.
240 let expected_keys: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = expected_fragments
241 .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().()
242 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(name, _)| name)
243 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
244 let fragments_keys: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = fragments.keysrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]keys().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
245 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fragments_keys, expected_keys);
246 }
247
248 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
249 fn basic_override_restrict_extensionsrust-analyzer cargo liboverdrop 0.1.0 tests/basic_override_restrict_extensions().() {
250 let treedir = "tests/fixtures/tree-basic";
251 let dirs = [formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", treedir, "etc")];
252
253 let fragments = scanrust-analyzer cargo liboverdrop 0.1.0 scan().(&dirs, "liboverdrop.d", &["toml"], false);
254
255 assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().(&fragments, "01-config-a.toml");
256 assert_fragments_missrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_miss().(&fragments, "08-config-h.conf");
257 assert_fragments_missrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_miss().(&fragments, "noextension");
258 }
259
260 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
261 fn basic_override_allow_all_extensionsrust-analyzer cargo liboverdrop 0.1.0 tests/basic_override_allow_all_extensions().() {
262 let treedir = "tests/fixtures/tree-basic";
263 let dirs = [formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", treedir, "etc")];
264
265 let fragments = scanrust-analyzer cargo liboverdrop 0.1.0 scan().::<_, _, _, &str>(&dirs, "liboverdrop.d", &[], false);
266
267 assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().(&fragments, "01-config-a.toml");
268 assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().(&fragments, "config.conf");
269 assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().(&fragments, "noextension");
270 }
271
272 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
273 fn basic_override_ignore_hiddenrust-analyzer cargo liboverdrop 0.1.0 tests/basic_override_ignore_hidden().() {
274 let treedir = "tests/fixtures/tree-basic";
275 let dirs = [formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", treedir, "etc")];
276
277 let fragments = scanrust-analyzer cargo liboverdrop 0.1.0 scan().::<_, _, _, &str>(&dirs, "liboverdrop.d", &[], true);
278
279 assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().(&fragments, "config.conf");
280 assert_fragments_missrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_miss().(&fragments, ".hidden.conf");
281 }
282
283 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
284 fn basic_override_allow_hiddenrust-analyzer cargo liboverdrop 0.1.0 tests/basic_override_allow_hidden().() {
285 let treedir = "tests/fixtures/tree-basic";
286 let dirs = [formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", treedir, "etc")];
287
288 let fragments = scanrust-analyzer cargo liboverdrop 0.1.0 scan().::<_, _, _, &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>(&dirs, "liboverdrop.d", &[], false);
289
290 assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().(&fragments, "config.conf");
291 assert_fragments_hitrust-analyzer cargo liboverdrop 0.1.0 tests/assert_fragments_hit().(&fragments, ".hidden.conf");
292 }
293 }