aboutsummaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2023-01-14 12:52:56 +0100
committerMichael Muré <batolettre@gmail.com>2023-01-14 12:52:56 +0100
commitcfec9e38e6519e80e1e3ac3de224ffd33997bcea (patch)
tree2365448c2071346ec6ecf6151e838c3be6fcc2c9 /storage
parent5dabd83e3712e2554745c736b55df405a0ba4f33 (diff)
downloadgo-git-cfec9e38e6519e80e1e3ac3de224ffd33997bcea.tar.gz
dotgit: fix a filesystem race in Refs/walkReferencesTree
In walkReferencesTree(), the filesystem is browsed recursively. After a folder is listed, each child element (directory, file) are inspected. What can happen is that by the time we get to operate on the child element, it might have been deleted from the filesystem and we would get a PathError. In the case of directories there was already a case to avoid bubbling up the error (we consider that there is no ref there, which is correct), but that was missing for files. This commit just apply the same logic.
Diffstat (limited to 'storage')
-rw-r--r--storage/filesystem/dotgit/dotgit.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go
index 6c386f7..2be2bae 100644
--- a/storage/filesystem/dotgit/dotgit.go
+++ b/storage/filesystem/dotgit/dotgit.go
@@ -943,6 +943,7 @@ func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath []strin
files, err := d.fs.ReadDir(d.fs.Join(relPath...))
if err != nil {
if os.IsNotExist(err) {
+ // a race happened, and our directory is gone now
return nil
}
@@ -960,6 +961,10 @@ func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath []strin
}
ref, err := d.readReferenceFile(".", strings.Join(newRelPath, "/"))
+ if os.IsNotExist(err) {
+ // a race happened, and our file is gone now
+ continue
+ }
if err != nil {
return err
}