MCPcopy Create free account
hub / github.com/archlinux/alpm / property

Function property

alpm-mtree/src/parser.rs:242–289  ·  view source on GitHub ↗

Parse a single property.

(input: &mut &'s str)

Source from the content-addressed store, hash-verified

240
241/// Parse a single property.
242fn property<'s>(input: &mut &'s str) -> ModalResult<PathProperty<'s>> {
243 // First off, get the type of the property.
244 let keywords = [
245 "type",
246 "uid",
247 "gid",
248 "mode",
249 "size",
250 "link",
251 "md5digest",
252 "sha256digest",
253 "time",
254 ];
255 let property_type = cut_err(alt(keywords))
256 .context(StrContext::Label("file property type"))
257 .context_with(iter_str_context!([keywords]))
258 .parse_next(input)?;
259
260 // Expect the `=` separator between the key-value pair
261 let _ = "=".parse_next(input)?;
262
263 // Now we continue parsing based on the type of the property.
264 let property = match property_type {
265 "type" => alt(("dir", "file", "link"))
266 .map(|value| match value {
267 "dir" => PathProperty::Type(PathType::Dir),
268 "file" => PathProperty::Type(PathType::File),
269 "link" => PathProperty::Type(PathType::Link),
270 _ => unreachable!(),
271 })
272 .context(StrContext::Label("property file type"))
273 .context(StrContext::Expected(StrContextValue::Description(
274 "'dir', 'file' or 'link'",
275 )))
276 .parse_next(input)?,
277 "uid" => PathProperty::Uid(system_id("user id", input)?),
278 "gid" => PathProperty::Gid(system_id("group id", input)?),
279 "mode" => PathProperty::Mode(mode(input)?),
280 "size" => PathProperty::Size(size.parse_next(input)?),
281 "link" => PathProperty::Link(PathBuf::from(link.parse_next(input)?)),
282 "md5digest" => PathProperty::Md5Digest(md5(input)?),
283 "sha256digest" => PathProperty::Sha256Digest(sha256(input)?),
284 "time" => PathProperty::Time(timestamp(input)?),
285 _ => unreachable!(),
286 };
287
288 Ok(property)
289}
290
291/// Parse all path related properties that follow after a path declaration.
292///

Callers

nothing calls this directly

Calls 6

system_idFunction · 0.85
modeFunction · 0.85
LinkClass · 0.85
md5Function · 0.85
sha256Function · 0.85
timestampFunction · 0.85

Tested by

no test coverage detected