the file should be written to a tmp location first

This commit is contained in:
Daniel Barney 2015-10-07 11:24:38 -06:00
parent 7e68364fd4
commit 9a5e133820

View File

@ -114,14 +114,20 @@ func (d *Driver) write(trans Transaction) error {
return err return err
} }
finalPath := dir + "/" + trans.ResourceID + ".json"
tmpPath := finalPath + "~"
// write marshaled data to a file, named by the resourceID // write marshaled data to a file, named by the resourceID
if err := ioutil.WriteFile(dir+"/"+trans.ResourceID, b, 0666); err != nil { if err := ioutil.WriteFile(tmpPath, b, 0666); err != nil {
return err return err
} }
// move final file into place
err = os.Rename(tmpPath, finalPath)
mutex.Unlock() mutex.Unlock()
return nil return err
} }
// read does the opposite operation as write. Reading a record from the database // read does the opposite operation as write. Reading a record from the database