Commit 0decf974 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Handle EEXIST when finalizing git archive

Closes https://gitlab.com/gitlab-org/gitlab-workhorse/issues/63
parent 06632c75
...@@ -173,7 +173,11 @@ func finalizeCachedArchive(tempFile *os.File, archivePath string) error { ...@@ -173,7 +173,11 @@ func finalizeCachedArchive(tempFile *os.File, archivePath string) error {
if err := tempFile.Close(); err != nil { if err := tempFile.Close(); err != nil {
return err return err
} }
return os.Link(tempFile.Name(), archivePath) if err := os.Link(tempFile.Name(), archivePath); err != nil && !os.IsExist(err) {
return err
}
return nil
} }
func parseBasename(basename string) (string, bool) { func parseBasename(basename string) (string, bool) {
......
package git package git
import ( import (
"io/ioutil"
"testing" "testing"
) )
...@@ -27,3 +28,17 @@ func TestParseBasename(t *testing.T) { ...@@ -27,3 +28,17 @@ func TestParseBasename(t *testing.T) {
} }
} }
} }
func TestFinalizeArchive(t *testing.T) {
tempFile, err := ioutil.TempFile("", "gitlab-workhorse-test")
if err != nil {
t.Fatal(err)
}
defer tempFile.Close()
// Deliberately cause an EEXIST error: we know tempFile.Name() already exists
err = finalizeCachedArchive(tempFile, tempFile.Name())
if err != nil {
t.Fatalf("expected nil from finalizeCachedArchive, received %v", err)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment