Skip to content

Commit 16396b8

Browse files
authored
Minor tweaks (#71)
* satisfy clippy, cleanup format strings and formatting * build on macos-latest * update workflow versions
1 parent 56ba689 commit 16396b8

7 files changed

Lines changed: 142 additions & 168 deletions

File tree

.github/workflows/build.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
os:
15-
- macos-11
15+
- macos-latest
1616
- ubuntu-latest
1717

1818
runs-on: ${{ matrix.os }}
@@ -30,7 +30,7 @@ jobs:
3030
fi
3131
3232
- name: Checkout code
33-
uses: actions/checkout@v2
33+
uses: actions/checkout@v4
3434

3535
- name: Build ffs/pack/unpack and run unit tests
3636
run: |
@@ -46,7 +46,7 @@ jobs:
4646
run: PATH="$(pwd)/target/release:$PATH" ./run_tests.sh unpack
4747

4848
- name: Upload macOS release build
49-
uses: actions/upload-artifact@v2
49+
uses: actions/upload-artifact@v4
5050
if: contains(matrix.os, 'macos')
5151
with:
5252
name: ffs.macos
@@ -56,7 +56,7 @@ jobs:
5656
target/release/unpack
5757
5858
- name: Upload Linux release build
59-
uses: actions/upload-artifact@v2
59+
uses: actions/upload-artifact@v4
6060
if: contains(matrix.os, 'ubuntu')
6161
with:
6262
name: ffs.linux
@@ -80,10 +80,10 @@ jobs:
8080
fi
8181
8282
- name: Checkout code
83-
uses: actions/checkout@v2
83+
uses: actions/checkout@v4
8484

8585
- name: Download binaries
86-
uses: actions/download-artifact@v2
86+
uses: actions/download-artifact@v4
8787

8888
- name: Install R
8989
uses: r-lib/actions/setup-r@v2
@@ -103,7 +103,7 @@ jobs:
103103
done
104104
105105
- name: Upload Linux benchmark data
106-
uses: actions/upload-artifact@v2
106+
uses: actions/upload-artifact@v4
107107
if: contains(matrix.os, 'ubuntu')
108108
with:
109109
name: benchmarks.linux
@@ -116,7 +116,7 @@ jobs:
116116

117117
steps:
118118
- name: Download binaries
119-
uses: actions/download-artifact@v2
119+
uses: actions/download-artifact@v4
120120

121121
- name: Rename binaries
122122
run: |

src/bin/ffs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,44 @@ fn main() {
3434
Format::Json => {
3535
let fs: FS<format::json::Value> = FS::new(config);
3636

37-
info!("mounting on {:?} with options {:?}", mount, options);
37+
info!("mounting on {} with options {options:?}", mount.display());
3838
match fuser::mount2(fs, &mount, &options) {
3939
Ok(()) => {
4040
info!("unmounted");
4141
0
4242
}
4343
Err(e) => {
44-
error!("I/O error: {}", e);
44+
error!("I/O error: {e}");
4545
ERROR_STATUS_FUSE
4646
}
4747
}
4848
}
4949
Format::Toml => {
5050
let fs: FS<format::toml::Value> = FS::new(config);
5151

52-
info!("mounting on {:?} with options {:?}", mount, options);
52+
info!("mounting on {} with options {options:?}", mount.display());
5353
match fuser::mount2(fs, &mount, &options) {
5454
Ok(()) => {
5555
info!("unmounted");
5656
0
5757
}
5858
Err(e) => {
59-
error!("I/O error: {}", e);
59+
error!("I/O error: {e}");
6060
ERROR_STATUS_FUSE
6161
}
6262
}
6363
}
6464
Format::Yaml => {
6565
let fs: FS<format::yaml::Value> = FS::new(config);
6666

67-
info!("mounting on {:?} with options {:?}", mount, options);
67+
info!("mounting on {} with options {options:?}", mount.display());
6868
match fuser::mount2(fs, &mount, &options) {
6969
Ok(()) => {
7070
info!("unmounted");
7171
0
7272
}
7373
Err(e) => {
74-
error!("I/O error: {}", e);
74+
error!("I/O error: {e}");
7575
ERROR_STATUS_FUSE
7676
}
7777
}
@@ -81,7 +81,7 @@ fn main() {
8181
if cleanup_mount {
8282
if mount.exists() {
8383
if let Err(e) = std::fs::remove_dir(&mount) {
84-
warn!("Unable to clean up mountpoint '{}': {}", mount.display(), e);
84+
warn!("Unable to clean up mountpoint '{}': {e}", mount.display());
8585
}
8686
} else {
8787
warn!(

src/bin/pack.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use std::str;
1010
use std::str::FromStr;
1111

12-
use tracing::{debug, error, info, warn};
12+
use tracing::{error, info, warn};
1313

1414
use ffs::config::Config;
1515
use ffs::config::Symlink;
@@ -40,6 +40,12 @@ pub struct Pack {
4040
regex: Regex,
4141
}
4242

43+
impl Default for Pack {
44+
fn default() -> Self {
45+
Self::new()
46+
}
47+
}
48+
4349
impl Pack {
4450
pub fn new() -> Self {
4551
Self {
@@ -75,7 +81,7 @@ impl Pack {
7581
let mut link_follower = path.clone();
7682
while link_follower.is_symlink() {
7783
if link_trail.contains(&link_follower) {
78-
error!("Symlink loop detected at {:?}.", link_follower);
84+
error!("Symlink loop detected at {}.", link_follower.display());
7985
std::process::exit(ERROR_STATUS_FUSE);
8086
}
8187
link_trail.push(link_follower.clone());
@@ -92,8 +98,8 @@ impl Pack {
9298
// Err(_) => {
9399
// // Cannot call xattr::get on ._ file
94100
// warn!(
95-
// "._ files, like {:?}, prevent xattr calls. It will be encoded in base64.",
96-
// link_follower
101+
// "._ files, like {}, prevent xattr calls. It will be encoded in base64.",
102+
// link_follower.display()
97103
// );
98104
// path_type = b"bytes".to_vec()
99105
// }
@@ -130,8 +136,8 @@ impl Pack {
130136
{
131137
// the symlink is broken, so don't pack this file.
132138
warn!(
133-
"The symlink at the end of the chain starting from '{:?}' is broken.",
134-
path
139+
"The symlink at the end of the chain starting from '{}' is broken.",
140+
path.display()
135141
);
136142
for link in link_trail {
137143
let symlink_map_data = &self.symlinks[&link];
@@ -150,16 +156,16 @@ impl Pack {
150156
let canonicalized = link_follower.canonicalize()?;
151157
if path.starts_with(&canonicalized) {
152158
error!(
153-
"The symlink {:?} points to some ancestor directory: {:?}, causing an infinite loop.",
154-
path, canonicalized
159+
"The symlink {} points to some ancestor directory: {}, causing an infinite loop.",
160+
path.display(), canonicalized.display(),
155161
);
156162
std::process::exit(ERROR_STATUS_FUSE);
157163
}
158164
if !config.allow_symlink_escape
159165
&& !canonicalized.starts_with(config.mount.as_ref().unwrap())
160166
{
161-
warn!("The symlink {:?} points to some file outside of the directory being packed. \
162-
Specify --allow-symlink-escape to allow pack to follow this symlink.", path);
167+
warn!("The symlink {} points to some file outside of the directory being packed. \
168+
Specify --allow-symlink-escape to allow pack to follow this symlink.", path.display());
163169
return Ok(None);
164170
}
165171
}
@@ -170,14 +176,14 @@ impl Pack {
170176
// none of the symlinks on the chain have an xattr. Use the actual file's xattr
171177
if path_type.is_empty() {
172178
let canonicalized = path.canonicalize()?;
173-
path_type = match xattr::get(&canonicalized, "user.type") {
179+
path_type = match xattr::get(canonicalized, "user.type") {
174180
Ok(Some(xattr_type)) if config.allow_xattr => xattr_type,
175181
Ok(_) => b"auto".to_vec(),
176182
Err(_) => {
177183
// Cannot call xattr::get on ._ file
178184
warn!(
179-
"._ files, like {:?}, prevent xattr calls. It will be encoded in base64.",
180-
path
185+
"._ files, like {}, prevent xattr calls. It will be encoded in base64.",
186+
path.display(),
181187
);
182188
b"bytes".to_vec()
183189
}
@@ -191,19 +197,18 @@ impl Pack {
191197
if path.is_dir() && (path_type == "auto" || path_type != "named" && path_type != "list") {
192198
if path_type != "auto" {
193199
warn!(
194-
"Unknown directory type '{}'. Possible types are 'named' or 'list'. \
195-
Resolving type automatically.",
196-
path_type
200+
"Unknown directory type '{path_type}'. Possible types are 'named' or 'list'. \
201+
Resolving type automatically."
197202
);
198203
}
199204
let all_files_begin_with_num = fs::read_dir(path.clone())?
200205
.map(|res| res.map(|e| e.path()))
201206
.map(|e| e.unwrap().file_name().unwrap().to_str().unwrap().to_owned())
202207
.all(|filename| {
203-
filename.chars().nth(0).unwrap().is_digit(10)
208+
filename.chars().nth(0).unwrap().is_ascii_digit()
204209
|| filename.len() > 1
205210
&& filename.chars().nth(0).unwrap() == '-'
206-
&& filename.chars().nth(1).unwrap().is_digit(10)
211+
&& filename.chars().nth(1).unwrap().is_ascii_digit()
207212
});
208213
if all_files_begin_with_num {
209214
path_type = "list"
@@ -212,8 +217,6 @@ impl Pack {
212217
};
213218
}
214219

215-
info!("type of {:?} is {}", path, path_type);
216-
217220
// return the value based on determined type
218221
match path_type {
219222
"named" => {
@@ -227,11 +230,11 @@ impl Pack {
227230
for child in &children {
228231
let child_name = child.file_name().unwrap().to_str().unwrap();
229232
if config.ignored_file(child_name) {
230-
warn!("skipping ignored file {:?}", child_name);
233+
warn!("skipping ignored file {}", child.display());
231234
continue;
232235
}
233236
let name: String;
234-
match xattr::get(&child, "user.original_name") {
237+
match xattr::get(child, "user.original_name") {
235238
Ok(Some(original_name)) if config.allow_xattr => {
236239
let old_name = str::from_utf8(&original_name).unwrap();
237240
if !config.valid_name(old_name) {
@@ -250,14 +253,14 @@ impl Pack {
250253
}
251254
}
252255
self.depth += 1;
253-
let value = self.pack(child.clone(), &config)?;
256+
let value = self.pack(child.clone(), config)?;
254257
self.depth -= 1;
255258
if let Some(value) = value {
256259
entries.insert(name, value);
257260
}
258261
}
259262

260-
Ok(Some(V::from_named_dir(entries, &config)))
263+
Ok(Some(V::from_named_dir(entries, config)))
261264
}
262265
"list" => {
263266
let mut numbers_filenames_paths = fs::read_dir(path.clone())?
@@ -296,23 +299,21 @@ impl Pack {
296299
.collect::<Vec<_>>();
297300
numbers_filenames_paths.sort();
298301

299-
info!("parsed numbers and filenames {:?}", numbers_filenames_paths);
300-
301302
let mut entries = Vec::with_capacity(numbers_filenames_paths.len());
302303
for (_, filename, child) in numbers_filenames_paths {
303304
if config.ignored_file(&filename) {
304-
warn!("skipping ignored file {:?}", child);
305+
warn!("skipping ignored file {}", child.display());
305306
continue;
306307
}
307308
self.depth += 1;
308-
let value = self.pack(child, &config)?;
309+
let value = self.pack(child, config)?;
309310
self.depth -= 1;
310311
if let Some(value) = value {
311312
entries.push(value);
312313
}
313314
}
314315

315-
Ok(Some(V::from_list_dir(entries, &config)))
316+
Ok(Some(V::from_list_dir(entries, config)))
316317
}
317318
typ => {
318319
if let Ok(t) = Typ::from_str(typ) {
@@ -325,14 +326,13 @@ impl Pack {
325326
if config.add_newlines && contents.ends_with('\n') {
326327
contents.truncate(contents.len() - 1);
327328
}
328-
Ok(Some(V::from_string(t, contents, &config)))
329+
Ok(Some(V::from_string(t, contents, config)))
329330
}
330-
Ok(_) | Err(_) => Ok(Some(V::from_bytes(contents, &config))),
331+
Ok(_) | Err(_) => Ok(Some(V::from_bytes(contents, config))),
331332
}
332333
} else {
333334
error!(
334-
"This error should never be called. Received undetected and unknown type '{}' for file '{}'",
335-
typ,
335+
"Received undetected and unknown type '{typ}' for file '{}'",
336336
path.display()
337337
);
338338
std::process::exit(ERROR_STATUS_FUSE);
@@ -344,12 +344,11 @@ impl Pack {
344344

345345
fn main() -> std::io::Result<()> {
346346
let config = Config::from_pack_args();
347-
debug!("received config: {:?}", config);
348347

349348
let mount = match &config.mount {
350349
Some(mount) => mount,
351350
None => {
352-
error!("Cannot pack unspecified directory.");
351+
error!("You must specify a directory to pack.");
353352
std::process::exit(ERROR_STATUS_CLI);
354353
}
355354
};

0 commit comments

Comments
 (0)