Skip to content

Commit 360ff46

Browse files
committed
🐛 Fixed missing support hard link character printing in bsdtar format
1 parent 6bfb621 commit 360ff46

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

cli/src/command/list.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ fn bsd_tar_list_entries_to(
784784
let permission = row.permission_mode();
785785
let has_xattr = !row.xattrs.is_empty();
786786
let has_acl = !row.acl.is_empty();
787-
let perm = permission_string(&row.entry_type, permission, has_xattr, has_acl);
787+
let perm = bsdtar_permission_string(&row.entry_type, permission, has_acl);
788788
let size = row.raw_size.unwrap_or(0);
789789
let mtime = bsd_tar_time(now, row.modified.unwrap_or(now));
790790
let (uname, gname) = match &row.permission {
@@ -1155,6 +1155,15 @@ const fn kind_char(kind: &EntryType) -> char {
11551155
}
11561156
}
11571157

1158+
const fn bsdtar_kind_char(kind: &EntryType) -> char {
1159+
match kind {
1160+
EntryType::File(_) => '-',
1161+
EntryType::HardLink(_, _) => 'h',
1162+
EntryType::Directory(_) => 'd',
1163+
EntryType::SymbolicLink(_, _) => 'l',
1164+
}
1165+
}
1166+
11581167
fn permission_string(kind: &EntryType, permission: u16, has_xattr: bool, has_acl: bool) -> String {
11591168
#[inline(always)]
11601169
const fn paint(permission: u16, c: char, bit: u16) -> char {
@@ -1183,6 +1192,28 @@ fn permission_string(kind: &EntryType, permission: u16, has_xattr: bool, has_acl
11831192
)
11841193
}
11851194

1195+
fn bsdtar_permission_string(kind: &EntryType, permission: u16, has_acl: bool) -> String {
1196+
#[inline(always)]
1197+
const fn paint(permission: u16, c: char, bit: u16) -> char {
1198+
if permission & bit != 0 { c } else { '-' }
1199+
}
1200+
1201+
format!(
1202+
"{}{}{}{}{}{}{}{}{}{}{}",
1203+
bsdtar_kind_char(kind),
1204+
paint(permission, 'r', 0b100000000),
1205+
paint(permission, 'w', 0b010000000),
1206+
paint(permission, 'x', 0b001000000),
1207+
paint(permission, 'r', 0b000100000),
1208+
paint(permission, 'w', 0b000010000),
1209+
paint(permission, 'x', 0b000001000),
1210+
paint(permission, 'r', 0b000000100),
1211+
paint(permission, 'w', 0b000000010),
1212+
paint(permission, 'x', 0b000000001),
1213+
if has_acl { '+' } else { ' ' },
1214+
)
1215+
}
1216+
11861217
#[derive(Serialize, Debug)]
11871218
struct FileInfo<'a> {
11881219
filename: &'a str,

0 commit comments

Comments
 (0)