aboutsummaryrefslogtreecommitdiff
path: root/backup
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2017-08-08 08:05:52 +0200
committerLaria Carolin Chabowski <laria@laria.me>2017-09-26 21:35:40 +0200
commitbab0697f0e8a98cfa28c7527ee616e954c7afe91 (patch)
tree33c602bf39c4707ab4826ed6ba25c403cb07fe70 /backup
parenta845956238e6a41479a7abd59f5c39e71f3f85f4 (diff)
downloadpetrific-bab0697f0e8a98cfa28c7527ee616e954c7afe91.tar.gz
petrific-bab0697f0e8a98cfa28c7527ee616e954c7afe91.tar.bz2
petrific-bab0697f0e8a98cfa28c7527ee616e954c7afe91.zip
Add OpenWritable to fs interfaces
Diffstat (limited to 'backup')
-rw-r--r--backup/backup_test.go6
-rw-r--r--backup/restore.go12
2 files changed, 10 insertions, 8 deletions
diff --git a/backup/backup_test.go b/backup/backup_test.go
index 67fbb6a..da14117 100644
--- a/backup/backup_test.go
+++ b/backup/backup_test.go
@@ -49,13 +49,13 @@ func mkfile(t *testing.T, d fs.Dir, name string, exec bool, content []byte) {
t.Fatalf("Could not create file %s: %s", name, err)
}
- rwc, err := f.Open()
+ wc, err := f.OpenWritable()
if err != nil {
t.Fatalf("Could not create file %s: %s", name, err)
}
- defer rwc.Close()
+ defer wc.Close()
- if _, err := rwc.Write(content); err != nil {
+ if _, err := wc.Write(content); err != nil {
t.Fatalf("Could not create file %s: %s", name, err)
}
}
diff --git a/backup/restore.go b/backup/restore.go
index 6a03200..3a384a9 100644
--- a/backup/restore.go
+++ b/backup/restore.go
@@ -7,6 +7,7 @@ import (
"code.laria.me/petrific/storage"
"fmt"
"io"
+ "math/rand"
"os"
)
@@ -48,21 +49,22 @@ func RestoreDir(s storage.Storage, id objects.ObjectId, root fs.Dir) error {
for name, file_info := range tree {
switch file_info.Type() {
case objects.TETFile:
- tmpname := fmt.Sprintf(".petrific-%d-%s", os.Getpid(), id)
+ tmpname := fmt.Sprintf(".petrific-%d-%08x%08x%08x%08x", os.Getpid(), rand.Uint32(), rand.Uint32(), rand.Uint32(), rand.Uint32())
new_file, err := root.CreateChildFile(tmpname, execBitFromACL(file_info.ACL()))
if err != nil {
return err
}
- rwc, err := new_file.Open()
+
+ wc, err := new_file.OpenWritable()
if err != nil {
return err
}
- if err := RestoreFile(s, file_info.(objects.TreeEntryFile).Ref, rwc); err != nil {
- rwc.Close()
+ if err := RestoreFile(s, file_info.(objects.TreeEntryFile).Ref, wc); err != nil {
+ wc.Close()
return err
}
- rwc.Close()
+ wc.Close()
if err := root.RenameChild(tmpname, name); err != nil {
return err