mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-28 11:46:20 -04:00
Implement moveFile to move the generated index
os.Rename only works across the same mountpoint, since it creates a new hardlink and unlinks the old one. Since we generated the index in /tmp, which is most likely not the final endpoint, this often does not work. Fixes: #8 Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
This commit is contained in:
parent
399112fe36
commit
c082ae5104
1 changed files with 26 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -42,6 +43,30 @@ func preload(c *cli.Context) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moveFile(src, dst string) (err error) {
|
||||||
|
in, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer in.Close()
|
||||||
|
tmp, err := ioutil.TempFile(filepath.Dir(dst), "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = io.Copy(tmp, in)
|
||||||
|
if err != nil {
|
||||||
|
tmp.Close()
|
||||||
|
os.Remove(tmp.Name())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = tmp.Close(); err != nil {
|
||||||
|
os.Remove(tmp.Name())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.Remove(src)
|
||||||
|
return os.Rename(tmp.Name(), dst)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "reg-server"
|
app.Name = "reg-server"
|
||||||
|
@ -278,7 +303,7 @@ func createStaticIndex(r *registry.Registry, staticDir, clairURI string) error {
|
||||||
|
|
||||||
index := filepath.Join(staticDir, "index.html")
|
index := filepath.Join(staticDir, "index.html")
|
||||||
logrus.Infof("renaming the temporary file %s to %s", f.Name(), index)
|
logrus.Infof("renaming the temporary file %s to %s", f.Name(), index)
|
||||||
if err := os.Rename(f.Name(), index); err != nil {
|
if err := moveFile(f.Name(), index); err != nil {
|
||||||
return fmt.Errorf("renaming result from %s to %s failed: %v", f.Name(), index, err)
|
return fmt.Errorf("renaming result from %s to %s failed: %v", f.Name(), index, err)
|
||||||
}
|
}
|
||||||
updating = false
|
updating = false
|
||||||
|
|
Loading…
Reference in a new issue