in xar/clean_xar_mounts/src/main.rs [302:360]
fn get_lockfile_path(logger: &slog::Logger, mount: &MountedFilesystem) -> Vec<PathBuf> {
// Strip off the dir the mountpoint is inside (only from a list of
// valid prefixes). If the mount isn't prefixed by our list, do
// not unmount.
let mount_suffix_opt = ["/mnt/xarfuse/", "/dev/shm/"]
.iter()
.filter_map(|candidate| {
if mount.mountpoint.starts_with(candidate) {
Some(&mount.mountpoint[candidate.len()..])
} else {
None
}
})
.next();
let mount_suffix = match mount_suffix_opt {
Some(mnt) => mnt,
None => {
info!(
logger,
"Skipping unmount of {}, incorrect prefix", mount.mountpoint
);
return vec![];
}
};
debug!(logger, "Mount suffix: {}", mount_suffix);
// Mounts are of the form /prefix/uid-N/UUID-ns-NSID/... or
// /prefix/uid-N/UUID-seed-SEED-ns-NSID/... -- we need to extract
// the UUID portion.
lazy_static! {
static ref UUID_REGEX: Regex =
Regex::new(r"^uid-\d+/([^/-]+)(?:-seed-(?:[^/]+))?-ns-([^-/]+)$").unwrap();
}
// Validate our filename looks like a mountpoint we care about,
// and extract the UUID for the legacy lockfile.
let captures = match UUID_REGEX.captures(&mount_suffix) {
Some(captures) => captures,
None => return vec![],
};
let uuid = captures.get(1).unwrap();
// Look for the lockfile for the mountpoint; there are two cases,
// one of just a lockfile.UUID (old style) and one of
// lockfile.MOUNT_DIR (new style, which includes the UUID, seed,
// and namespace).
let mut lockfile_base = mount.chroot.clone();
lockfile_base.push(&mount.mountpoint[1..]); // strip leading slash
lockfile_base.set_file_name("lockfile");
let mut old_lockfile = lockfile_base.clone();
old_lockfile.set_extension(uuid.as_str());
let mut new_lockfile = lockfile_base.clone();
new_lockfile.set_extension(PathBuf::from(mount_suffix).file_name().unwrap());
vec![new_lockfile, old_lockfile]
}