Accept safe overlay work residue after unmount
This commit is contained in:
parent
e60baad993
commit
d38357a65d
1 changed files with 80 additions and 12 deletions
|
|
@ -210,7 +210,14 @@ pub(super) fn remove_directory_contents(directory: impl AsFd) -> Result<(), Stat
|
|||
}
|
||||
|
||||
fn directory_names(directory: impl AsFd) -> Result<Vec<OsString>, StateAnchorError> {
|
||||
let descriptor = rustix::io::dup(directory.as_fd()).map_err(io::Error::from)?;
|
||||
let descriptor = openat2(
|
||||
directory.as_fd(),
|
||||
".",
|
||||
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC,
|
||||
Mode::empty(),
|
||||
confined_resolve_flags(),
|
||||
)
|
||||
.map_err(io::Error::from)?;
|
||||
let mut buffer = [std::mem::MaybeUninit::uninit(); 8192];
|
||||
let mut raw = RawDir::new(descriptor, &mut buffer);
|
||||
let mut names = Vec::new();
|
||||
|
|
@ -228,6 +235,31 @@ pub(super) fn directory_has_entries(directory: impl AsFd) -> Result<bool, StateA
|
|||
Ok(!directory_names(directory)?.is_empty())
|
||||
}
|
||||
|
||||
pub(super) fn require_maintenance_work_shape(directory: impl AsFd) -> Result<(), StateAnchorError> {
|
||||
let names = directory_names(&directory)?;
|
||||
if names.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
if names.as_slice() != [OsString::from("work")] {
|
||||
return Err(StateAnchorError::InvalidLayout(
|
||||
"State Anchor work directory has unsupported entries",
|
||||
));
|
||||
}
|
||||
let nested = open_directory(&directory, Path::new("work"))?;
|
||||
let parent = rustix::fs::fstat(&directory).map_err(io::Error::from)?;
|
||||
let child = rustix::fs::fstat(&nested).map_err(io::Error::from)?;
|
||||
if child.st_mode & 0o7777 != 0o700
|
||||
|| child.st_uid != parent.st_uid
|
||||
|| child.st_gid != parent.st_gid
|
||||
|| directory_has_entries(&nested)?
|
||||
{
|
||||
return Err(StateAnchorError::InvalidLayout(
|
||||
"State Anchor work directory has unsupported entries",
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn validate_relative_path(path: &Path) -> Result<(), StateAnchorError> {
|
||||
if path.as_os_str().is_empty()
|
||||
|| path
|
||||
|
|
|
|||
Loading…
Reference in a new issue