Skip to content

Commit

Permalink
Avoid removing entries during read_dir (#7151)
Browse files Browse the repository at this point in the history
I think this is the source of the test flakiness.
  • Loading branch information
charliermarsh authored Sep 7, 2024
1 parent 7d49fbc commit 6179b65
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions crates/uv-distribution/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,19 +1620,18 @@ pub fn prune(cache: &Cache) -> Result<Removal, Error> {
for entry in walkdir::WalkDir::new(bucket) {
let entry = entry.map_err(Error::CacheWalk)?;

if !entry.file_type().is_dir() {
continue;
}

// If we find a `revision.http` file, read the pointer, and remove any extraneous
// directories.
if entry.file_name() == "revision.http" {
let pointer = HttpRevisionPointer::read_from(entry.path())?;
let revision = entry.path().join("revision.http");
if revision.is_file() {
let pointer = HttpRevisionPointer::read_from(revision)?;
if let Some(pointer) = pointer {
// Remove all sibling directories that are not referenced by the pointer.
for sibling in entry
.path()
.parent()
.unwrap()
.read_dir()
.map_err(Error::CacheRead)?
{
for sibling in entry.path().read_dir().map_err(Error::CacheRead)? {
let sibling = sibling.map_err(Error::CacheRead)?;
if sibling.file_type().map_err(Error::CacheRead)?.is_dir() {
let sibling_name = sibling.file_name();
Expand All @@ -1647,21 +1646,18 @@ pub fn prune(cache: &Cache) -> Result<Removal, Error> {
}
}
}

continue;
}

// If we find a `revision.rev` file, read the pointer, and remove any extraneous
// directories.
if entry.file_name() == "revision.rev" {
let pointer = LocalRevisionPointer::read_from(entry.path())?;
let revision = entry.path().join("revision.rev");
if revision.is_file() {
let pointer = LocalRevisionPointer::read_from(revision)?;
if let Some(pointer) = pointer {
// Remove all sibling directories that are not referenced by the pointer.
for sibling in entry
.path()
.parent()
.unwrap()
.read_dir()
.map_err(Error::CacheRead)?
{
for sibling in entry.path().read_dir().map_err(Error::CacheRead)? {
let sibling = sibling.map_err(Error::CacheRead)?;
if sibling.file_type().map_err(Error::CacheRead)?.is_dir() {
let sibling_name = sibling.file_name();
Expand All @@ -1676,6 +1672,8 @@ pub fn prune(cache: &Cache) -> Result<Removal, Error> {
}
}
}

continue;
}
}
}
Expand Down

0 comments on commit 6179b65

Please sign in to comment.