Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo: Use ? when traversing directories #23

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 25 additions & 36 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,30 +438,23 @@ impl Repository {

fn walk_symlinkdir(fd: OwnedFd, objects: &mut HashSet<Sha256HashValue>) -> Result<()> {
for item in Dir::read_from(&fd)? {
match item {
Err(x) => Err(x)?,
Ok(entry) => {
// NB: the underlying filesystem must support returning filetype via direntry
// that's a reasonable assumption, since it must also support fsverity...
match entry.file_type() {
FileType::Directory => {
let filename = entry.file_name();
if filename != c"." && filename != c".." {
let dirfd = openat(&fd, filename, OFlags::RDONLY, Mode::empty())?;
Repository::walk_symlinkdir(dirfd, objects)?;
}
}
FileType::Symlink => {
objects.insert(Repository::read_symlink_hashvalue(
&fd,
entry.file_name(),
)?);
}
_ => {
bail!("Unexpected file type encountered");
}
let entry = item?;
// NB: the underlying filesystem must support returning filetype via direntry
// that's a reasonable assumption, since it must also support fsverity...
match entry.file_type() {
FileType::Directory => {
let filename = entry.file_name();
if filename != c"." && filename != c".." {
let dirfd = openat(&fd, filename, OFlags::RDONLY, Mode::empty())?;
Repository::walk_symlinkdir(dirfd, objects)?;
}
}
FileType::Symlink => {
objects.insert(Repository::read_symlink_hashvalue(&fd, entry.file_name())?);
}
_ => {
bail!("Unexpected file type encountered");
}
}
}

Expand All @@ -486,21 +479,17 @@ impl Repository {
Repository::walk_symlinkdir(refs, &mut objects)?;

for item in Dir::read_from(&category_fd)? {
match item {
Err(x) => Err(x)?,
Ok(entry) => {
let filename = entry.file_name();
if filename != c"refs" && filename != c"." && filename != c".." {
if entry.file_type() != FileType::Symlink {
bail!("category directory contains non-symlink");
}
let mut value = Sha256HashValue::EMPTY;
hex::decode_to_slice(filename.to_bytes(), &mut value)?;
let entry = item?;
let filename = entry.file_name();
if filename != c"refs" && filename != c"." && filename != c".." {
if entry.file_type() != FileType::Symlink {
bail!("category directory contains non-symlink");
}
let mut value = Sha256HashValue::EMPTY;
hex::decode_to_slice(filename.to_bytes(), &mut value)?;

if !objects.contains(&value) {
println!("rm {}/{:?}", category, filename);
}
}
if !objects.contains(&value) {
println!("rm {}/{:?}", category, filename);
}
}
}
Expand Down