Skip to content

Commit 799c2ea

Browse files
committed
✨ Add reserved and private enum variants
1 parent 82b7983 commit 799c2ea

7 files changed

Lines changed: 205 additions & 31 deletions

File tree

cli/src/command/chmod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const fn default_permission_mode(kind: DataKind) -> u16 {
137137
match kind {
138138
DataKind::Directory => 0o755,
139139
DataKind::File | DataKind::SymbolicLink | DataKind::HardLink => 0o644,
140+
DataKind::Reserved(_) | DataKind::Private(_) => 0,
140141
}
141142
}
142143

cli/src/command/diff.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ fn compare_entry<T: AsRef<[u8]>>(
341341
DataKind::HardLink => {
342342
println!("{}", DiffKind::TypeMismatch.display(path_str));
343343
}
344+
_ => {
345+
println!("{}", DiffKind::TypeMismatch.display(path_str));
346+
}
344347
}
345348
Ok(())
346349
}

cli/src/command/list.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ enum EntryType {
288288
Directory(String),
289289
SymbolicLink(String, String),
290290
HardLink(String, String),
291+
Unknown(String, DataKind),
291292
}
292293

293294
impl EntryType {
@@ -297,7 +298,8 @@ impl EntryType {
297298
EntryType::File(name)
298299
| EntryType::Directory(name)
299300
| EntryType::SymbolicLink(name, _)
300-
| EntryType::HardLink(name, _) => name,
301+
| EntryType::HardLink(name, _)
302+
| EntryType::Unknown(name, _) => name,
301303
}
302304
}
303305

@@ -322,6 +324,7 @@ impl Display for EntryTypeBsdLongStyleDisplay<'_> {
322324
EntryType::HardLink(name, link_to) => {
323325
write!(f, "{name} link to {link_to}")
324326
}
327+
EntryType::Unknown(name, _) => Display::fmt(&name, f),
325328
}
326329
}
327330
}
@@ -451,6 +454,7 @@ impl TableRow {
451454
),
452455
DataKind::Directory => EntryType::Directory(entry.name().to_string()),
453456
DataKind::File => EntryType::File(entry.name().to_string()),
457+
kind => EntryType::Unknown(entry.name().to_string(), kind),
454458
},
455459
// Only collect xattrs if needed
456460
xattrs: if collect.xattrs {
@@ -1081,7 +1085,7 @@ fn detailed_format_name(entry: EntryType, options: &ListOptions) -> String {
10811085
EntryType::SymbolicLink(name, link_to) if options.classify => {
10821086
format!("{name}@ -> {link_to}")
10831087
}
1084-
EntryType::File(path) | EntryType::Directory(path) => path,
1088+
EntryType::File(path) | EntryType::Directory(path) | EntryType::Unknown(path, _) => path,
10851089
EntryType::SymbolicLink(path, link_to) | EntryType::HardLink(path, link_to) => {
10861090
format!("{path} -> {link_to}")
10871091
}
@@ -1200,6 +1204,7 @@ fn kind_paint(kind: &EntryType) -> impl Display + 'static {
12001204
EntryType::File(_) | EntryType::HardLink(_, _) => STYLE_HYPHEN.paint('.'),
12011205
EntryType::Directory(_) => STYLE_DIR.paint('d'),
12021206
EntryType::SymbolicLink(_, _) => STYLE_LINK.paint('l'),
1207+
EntryType::Unknown(_, _) => STYLE_HYPHEN.paint('?'),
12031208
}
12041209
}
12051210

@@ -1239,6 +1244,7 @@ const fn kind_char(kind: &EntryType) -> char {
12391244
EntryType::File(_) | EntryType::HardLink(_, _) => '-',
12401245
EntryType::Directory(_) => 'd',
12411246
EntryType::SymbolicLink(_, _) => 'l',
1247+
EntryType::Unknown(_, _) => '?',
12421248
}
12431249
}
12441250

@@ -1272,6 +1278,7 @@ impl PermissionDisplay {
12721278
EntryType::HardLink(_, _) => 'h',
12731279
EntryType::Directory(_) => 'd',
12741280
EntryType::SymbolicLink(_, _) => 'l',
1281+
EntryType::Unknown(_, _) => '?',
12751282
},
12761283
permission,
12771284
indicator: if has_acl { '+' } else { ' ' },
@@ -1526,6 +1533,7 @@ fn tree_entries_to(
15261533
EntryType::Directory(name) => (name.as_str(), DataKind::Directory),
15271534
EntryType::SymbolicLink(name, _) => (name.as_str(), DataKind::SymbolicLink),
15281535
EntryType::HardLink(name, _) => (name.as_str(), DataKind::HardLink),
1536+
EntryType::Unknown(name, kind) => (name.as_str(), *kind),
15291537
});
15301538
let map = build_tree_map(entries);
15311539
let tree = build_term_tree(&map, Cow::Borrowed(""), None, DataKind::Directory, options);
@@ -1648,6 +1656,26 @@ mod tests {
16481656
);
16491657
}
16501658

1659+
#[test]
1660+
fn unknown_entry_type_does_not_render_as_file() {
1661+
let entry_type = EntryType::Unknown("private-entry".into(), DataKind::Private(128));
1662+
1663+
assert_eq!(entry_type.name(), "private-entry");
1664+
assert_eq!(
1665+
entry_type.bsd_long_style_display().to_string(),
1666+
"private-entry"
1667+
);
1668+
assert_eq!(kind_char(&entry_type), '?');
1669+
assert_eq!(
1670+
PermissionDisplay::new(&entry_type, 0o644, false, false).to_string(),
1671+
"?rw-r--r-- "
1672+
);
1673+
assert_eq!(
1674+
PermissionDisplay::bsdtar(&entry_type, 0o644, false).to_string(),
1675+
"?rw-r--r-- "
1676+
);
1677+
}
1678+
16511679
#[test]
16521680
fn i64_max_seconds_exceed_jiff_window() {
16531681
assert!(unix_timestamp_to_local_opt(&TimeZone::UTC, i64::MAX, 0).is_none());

lib/src/entry/header.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ impl EntryHeader {
122122
let mut data = Vec::with_capacity(6 + name.len());
123123
data.push(self.major);
124124
data.push(self.minor);
125-
data.push(self.data_kind as u8);
126-
data.push(self.compression as u8);
127-
data.push(self.encryption as u8);
128-
data.push(self.cipher_mode as u8);
125+
data.push(self.data_kind.to_byte());
126+
data.push(self.compression.to_byte());
127+
data.push(self.encryption.to_byte());
128+
data.push(self.cipher_mode.to_byte());
129129
data.extend_from_slice(name);
130130
data
131131
}
@@ -272,9 +272,9 @@ impl SolidHeader {
272272
[
273273
self.major,
274274
self.minor,
275-
self.compression as u8,
276-
self.encryption as u8,
277-
self.cipher_mode as u8,
275+
self.compression.to_byte(),
276+
self.encryption.to_byte(),
277+
self.cipher_mode.to_byte(),
278278
]
279279
}
280280

0 commit comments

Comments
 (0)