2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-29 00:06:32 +00:00
restic/object.go

28 lines
497 B
Go
Raw Normal View History

2014-08-04 18:47:04 +00:00
package khepri
func (repo *Repository) Create(t Type, data []byte) (ID, error) {
// TODO: make sure that tempfile is removed upon error
2014-08-04 18:47:04 +00:00
// create tempfile in repository
2014-08-04 20:46:14 +00:00
var err error
file, err := repo.tempFile()
2014-08-04 20:46:14 +00:00
if err != nil {
return nil, err
2014-08-04 18:47:04 +00:00
}
// write data to tempfile
_, err = file.Write(data)
if err != nil {
return nil, err
2014-08-04 18:47:04 +00:00
}
// close tempfile, return id
id := IDFromData(data)
err = repo.renameFile(file, t, id)
2014-08-04 18:47:04 +00:00
if err != nil {
return nil, err
2014-08-04 18:47:04 +00:00
}
return id, nil
2014-08-04 18:47:04 +00:00
}