Skip to content

Commit f8e987d

Browse files
committed
🐛 Fix jsonl format ignoring -@ and -e flags
The jsonl format was always outputting `acl` and `xattr` fields as empty arrays regardless of whether -e (acl) or -@ (xattr) flags were specified. This was inconsistent with the `fflags` field behavior. Now these fields use `skip_serializing_if` to omit them entirely when not requested, matching the expected behavior. Also added tests to verify that: - `-e` flag includes acl field in jsonl output - `-@` flag includes xattr field in jsonl output
1 parent 0368929 commit f8e987d

3 files changed

Lines changed: 141 additions & 63 deletions

File tree

cli/src/command/list.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,10 @@ struct FileInfo<'a> {
11231123
accessed: String,
11241124
#[serde(skip_serializing_if = "Option::is_none")]
11251125
fflags: Option<&'a [String]>,
1126-
acl: Vec<AclEntry>,
1127-
xattr: Vec<XAttr<'a>>,
1126+
#[serde(skip_serializing_if = "Option::is_none")]
1127+
acl: Option<Vec<AclEntry>>,
1128+
#[serde(skip_serializing_if = "Option::is_none")]
1129+
xattr: Option<Vec<XAttr<'a>>>,
11281130
}
11291131

11301132
#[derive(Serialize, Debug)]
@@ -1145,6 +1147,8 @@ fn json_line_entries_to(
11451147
mut out: impl Write,
11461148
) -> anyhow::Result<()> {
11471149
let show_fflags = options.show_fflags;
1150+
let show_acl = options.show_acl;
1151+
let show_xattr = options.show_xattr;
11481152
let entries = entries
11491153
.par_iter()
11501154
.map(|it| {
@@ -1180,27 +1184,25 @@ fn json_line_entries_to(
11801184
accessed: it
11811185
.accessed
11821186
.map_or_else(String::new, |d| datetime(TimeFormat::Long, d)),
1183-
fflags: if show_fflags {
1184-
Some(it.fflags.as_slice())
1185-
} else {
1186-
None
1187-
},
1188-
acl: it
1189-
.acl
1190-
.iter()
1191-
.map(|(platform, ace)| AclEntry {
1192-
platform: platform.to_string(),
1193-
entries: ace.iter().map(|it| it.to_string()).collect(),
1194-
})
1195-
.collect(),
1196-
xattr: it
1197-
.xattrs
1198-
.iter()
1199-
.map(|x| XAttr {
1200-
key: x.name(),
1201-
value: base64::engine::general_purpose::STANDARD.encode(x.value()),
1202-
})
1203-
.collect(),
1187+
fflags: show_fflags.then(|| it.fflags.as_slice()),
1188+
acl: show_acl.then(|| {
1189+
it.acl
1190+
.iter()
1191+
.map(|(platform, ace)| AclEntry {
1192+
platform: platform.to_string(),
1193+
entries: ace.iter().map(|it| it.to_string()).collect(),
1194+
})
1195+
.collect()
1196+
}),
1197+
xattr: show_xattr.then(|| {
1198+
it.xattrs
1199+
.iter()
1200+
.map(|x| XAttr {
1201+
key: x.name(),
1202+
value: base64::engine::general_purpose::STANDARD.encode(x.value()),
1203+
})
1204+
.collect()
1205+
}),
12041206
}
12051207
})
12061208
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)