mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
40 lines
877 B
Go
40 lines
877 B
Go
package repo
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path"
|
|
"time"
|
|
)
|
|
|
|
const historyRepoJSONPrefix = "contentserver-repo-"
|
|
const historyRepoJSONSuffix = ".json"
|
|
|
|
type history struct {
|
|
varDir string
|
|
}
|
|
|
|
func newHistory(varDir string) *history {
|
|
return &history{
|
|
varDir: varDir,
|
|
}
|
|
}
|
|
|
|
func (h *history) add(jsonBytes []byte) error {
|
|
// historic file name
|
|
filename := path.Join(h.varDir, historyRepoJSONPrefix+time.Now().Format(time.RFC3339Nano)+historyRepoJSONSuffix)
|
|
err := ioutil.WriteFile(filename, jsonBytes, 0644)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// current filename
|
|
return ioutil.WriteFile(h.getCurrentFilename(), jsonBytes, 0644)
|
|
}
|
|
|
|
func (h *history) getCurrentFilename() string {
|
|
return path.Join(h.varDir, historyRepoJSONPrefix+"current"+historyRepoJSONSuffix)
|
|
}
|
|
|
|
func (h *history) getCurrent() (jsonBytes []byte, err error) {
|
|
return ioutil.ReadFile(h.getCurrentFilename())
|
|
}
|