file_names — functions and constants
The rule the SDK names its own files by, for an application that names its files the same way. Added in 12.0.35.
An alarm's snapshot or recording, and every still of a time-lapse,
is named from a pattern such as {rule}_{timestamp}. These are the
very functions the SDK uses for them, so a manual snapshot named
here looks like an alarm's and stays that way when the rule changes.
The placeholders are {rule}, {region}, {serial}, {model},
{sequence} (six digits), {timestamp} (the local date and time as
YYYYmmdd_HHMMSS, read when the name is made) and {timestamp_us}.
Each value goes in once, so a rule named {timestamp} is named
that; {{ and }} write a literal brace, and a name in braces that
is none of these is written as it stands.
# fn main() -> optris_sdk::Result<()> {
use optris_sdk::file_names::{self, FileNameContext};
let context = FileNameContext::new().rule("over temp").sequence(7);
let stem = file_names::expand("{rule}_{sequence}", &context, "")?;
assert_eq!(stem, "over_temp_000007");
# Ok(())
# }
pub fn expand(pattern: &str, context: &FileNameContext, fallback: &str) -> Result<String>
pattern with its placeholders filled in from context, then
cleaned as sanitize cleans. Each value is cleaned on its own
first, so a rule named ../../etc cannot walk out of a directory.
fallback is returned when nothing is left; the SDK's alarm
actions use "alarm".
Errors
crate::Status::InvalidArgument for a string with an interior
NUL byte.
pub fn sanitize(text: &str, fallback: &str) -> Result<String>
text as one part of a file name: a slash, a backslash, a colon,
*, ?, ", <, >, |, a control character and a space each
become _. fallback is returned when text is empty.
Errors
crate::Status::InvalidArgument for a string with an interior
NUL byte.
pub fn unique(directory: &str, stem: &str, extension: &str) -> Result<String>
directory/stem + extension, or, when that exists, the first of
stem-1, stem-2 ... up to stem-9999 that does not. Nothing is
created, so two programs asking at once can be told the same name.
An empty directory is the current one; extension carries its
dot, for example ".png".
Errors
crate::Status::InvalidArgument for a string with an interior
NUL byte.