mirror of https://github.com/docker/docs.git
Merge pull request #2450 from askb/1931_full_disk
Fixes #1931 - config.json integrity when disk is full
This commit is contained in:
commit
d7d6ca205a
|
@ -31,7 +31,31 @@ func (s Filestore) GetMachinesDir() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Filestore) saveToFile(data []byte, file string) error {
|
func (s Filestore) saveToFile(data []byte, file string) error {
|
||||||
return ioutil.WriteFile(file, data, 0600)
|
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||||
|
return ioutil.WriteFile(file, data, 0600)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpfi, err := ioutil.TempFile(filepath.Dir(file), "config.json.tmp")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.Remove(tmpfi.Name())
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(tmpfi.Name(), data, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Remove(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Rename(tmpfi.Name(), file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Filestore) Save(host *host.Host) error {
|
func (s Filestore) Save(host *host.Host) error {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/machine/commands/mcndirs"
|
"github.com/docker/machine/commands/mcndirs"
|
||||||
|
@ -52,6 +53,17 @@ func TestStoreSave(t *testing.T) {
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
t.Fatalf("Host path doesn't exist: %s", path)
|
t.Fatalf("Host path doesn't exist: %s", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files, _ := ioutil.ReadDir(path)
|
||||||
|
for _, f := range files {
|
||||||
|
r, err := regexp.Compile("config.json.tmp*")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to compile regexp string")
|
||||||
|
}
|
||||||
|
if r.MatchString(f.Name()) {
|
||||||
|
t.Fatalf("Failed to remove temp filestore:%s", f.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStoreSaveOmitRawDriver(t *testing.T) {
|
func TestStoreSaveOmitRawDriver(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue