feat: Add io.Writer-based API to restore and fetch cmds

This commit is contained in:
Felicitas Pojtinger
2021-12-17 15:30:09 +01:00
parent e11a3bffcc
commit 2a67c243fd
4 changed files with 59 additions and 8 deletions
+20
View File
@@ -1,6 +1,10 @@
package cmd
import (
"io"
"io/fs"
"os"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
@@ -93,6 +97,22 @@ var operationRestoreCmd = &cobra.Command{
)
return ops.Restore(
func(path string, mode fs.FileMode) (io.WriteCloser, error) {
dstFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, mode)
if err != nil {
return nil, err
}
if err := dstFile.Truncate(0); err != nil {
return nil, err
}
return dstFile, nil
},
func(path string, mode fs.FileMode) error {
return os.MkdirAll(path, mode)
},
viper.GetString(fromFlag),
viper.GetString(toFlag),
viper.GetBool(flattenFlag),
+20
View File
@@ -1,6 +1,10 @@
package cmd
import (
"io"
"io/fs"
"os"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/pkg/config"
@@ -80,6 +84,22 @@ var recoveryFetchCmd = &cobra.Command{
Password: viper.GetString(passwordFlag),
},
func(path string, mode fs.FileMode) (io.WriteCloser, error) {
dstFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, mode)
if err != nil {
return nil, err
}
if err := dstFile.Truncate(0); err != nil {
return nil, err
}
return dstFile, nil
},
func(path string, mode fs.FileMode) error {
return os.MkdirAll(path, mode)
},
viper.GetInt(recordSizeFlag),
viper.GetInt(recordFlag),
viper.GetInt(blockFlag),