feat: Add io.Writer-based API to restore and fetch cmds
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user