Skip to content

Commit 9e41509

Browse files
committed
Repository: Handle non-existing directories in garbage collection
For example, if there has been no streams created, we don't want to fail with some random ENOENT. Signed-off-by: Alexander Larsson <[email protected]>
1 parent 7263032 commit 9e41509

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

crates/composefs/src/repository.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,30 @@ impl<ObjectID: FsVerityHashValue> Repository<ObjectID> {
513513
fn gc_category(&self, category: &str) -> Result<HashSet<ObjectID>> {
514514
let mut objects = HashSet::new();
515515

516-
let category_fd = self.openat(category, OFlags::RDONLY | OFlags::DIRECTORY)?;
516+
let category_fd = match self.openat(category, OFlags::RDONLY | OFlags::DIRECTORY) {
517+
Ok(fd) => fd,
518+
Err(Errno::NOENT) => {
519+
return Ok(objects);
520+
}
521+
Err(other) => {
522+
return Err(other).context("Opening {category} dir in repository")?;
523+
}
524+
};
517525

518-
let refs = openat(
526+
match openat(
519527
&category_fd,
520528
"refs",
521529
OFlags::RDONLY | OFlags::DIRECTORY,
522530
Mode::empty(),
523-
)?;
524-
Self::walk_symlinkdir(refs, &mut objects)?;
531+
) {
532+
Ok(refs) => {
533+
Self::walk_symlinkdir(refs, &mut objects)?;
534+
}
535+
Err(Errno::NOENT) => {}
536+
Err(other) => {
537+
return Err(other).context("Opening {category}/refs dir in repository")?;
538+
}
539+
};
525540

526541
for item in Dir::read_from(&category_fd)? {
527542
let entry = item?;

0 commit comments

Comments
 (0)