refactor: Inject metadata persister

This commit is contained in:
Felicitas Pojtinger
2021-12-15 00:41:23 +01:00
parent 263a4e05d7
commit 71d28c8184
17 changed files with 98 additions and 85 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/pojntfx/stfs/internal/compression" "github.com/pojntfx/stfs/internal/compression"
"github.com/pojntfx/stfs/internal/keys" "github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations" "github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/tape" "github.com/pojntfx/stfs/pkg/tape"
@@ -69,6 +70,11 @@ var archiveCmd = &cobra.Command{
viper.GetBool(overwriteFlag), viper.GetBool(overwriteFlag),
) )
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
ops := operations.NewOperations( ops := operations.NewOperations(
tm.GetWriter, tm.GetWriter,
tm.Close, tm.Close,
@@ -78,12 +84,11 @@ var archiveCmd = &cobra.Command{
tm.GetDrive, tm.GetDrive,
tm.Close, tm.Close,
metadataPersister,
) )
if _, err := ops.Archive( if _, err := ops.Archive(
config.MetadataConfig{
Metadata: viper.GetString(metadataFlag),
},
config.PipeConfig{ config.PipeConfig{
Compression: viper.GetString(compressionFlag), Compression: viper.GetString(compressionFlag),
Encryption: viper.GetString(encryptionFlag), Encryption: viper.GetString(encryptionFlag),

View File

@@ -3,6 +3,7 @@ package cmd
import ( import (
"github.com/pojntfx/stfs/internal/keys" "github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations" "github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/tape" "github.com/pojntfx/stfs/pkg/tape"
@@ -56,6 +57,11 @@ var deleteCmd = &cobra.Command{
false, false,
) )
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
ops := operations.NewOperations( ops := operations.NewOperations(
tm.GetWriter, tm.GetWriter,
tm.Close, tm.Close,
@@ -65,12 +71,11 @@ var deleteCmd = &cobra.Command{
tm.GetDrive, tm.GetDrive,
tm.Close, tm.Close,
metadataPersister,
) )
return ops.Delete( return ops.Delete(
config.MetadataConfig{
Metadata: viper.GetString(metadataFlag),
},
config.PipeConfig{ config.PipeConfig{
Compression: viper.GetString(compressionFlag), Compression: viper.GetString(compressionFlag),
Encryption: viper.GetString(encryptionFlag), Encryption: viper.GetString(encryptionFlag),

View File

@@ -2,6 +2,7 @@ package cmd
import ( import (
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/inventory" "github.com/pojntfx/stfs/pkg/inventory"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -21,9 +22,14 @@ var findCmd = &cobra.Command{
return err return err
} }
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
if _, err := inventory.Find( if _, err := inventory.Find(
config.MetadataConfig{ config.MetadataConfig{
Metadata: viper.GetString(metadataFlag), Metadata: metadataPersister,
}, },
viper.GetString(expressionFlag), viper.GetString(expressionFlag),

View File

@@ -2,6 +2,7 @@ package cmd
import ( import (
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/inventory" "github.com/pojntfx/stfs/pkg/inventory"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -17,9 +18,14 @@ var listCmd = &cobra.Command{
return err return err
} }
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
if _, err := inventory.List( if _, err := inventory.List(
config.MetadataConfig{ config.MetadataConfig{
Metadata: viper.GetString(metadataFlag), Metadata: metadataPersister,
}, },
viper.GetString(nameFlag), viper.GetString(nameFlag),

View File

@@ -3,6 +3,7 @@ package cmd
import ( import (
"github.com/pojntfx/stfs/internal/keys" "github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations" "github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/tape" "github.com/pojntfx/stfs/pkg/tape"
@@ -52,6 +53,11 @@ var moveCmd = &cobra.Command{
false, false,
) )
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
ops := operations.NewOperations( ops := operations.NewOperations(
tm.GetWriter, tm.GetWriter,
tm.Close, tm.Close,
@@ -61,12 +67,11 @@ var moveCmd = &cobra.Command{
tm.GetDrive, tm.GetDrive,
tm.Close, tm.Close,
metadataPersister,
) )
return ops.Move( return ops.Move(
config.MetadataConfig{
Metadata: viper.GetString(metadataFlag),
},
config.PipeConfig{ config.PipeConfig{
Compression: viper.GetString(compressionFlag), Compression: viper.GetString(compressionFlag),
Encryption: viper.GetString(encryptionFlag), Encryption: viper.GetString(encryptionFlag),

View File

@@ -6,6 +6,7 @@ import (
"github.com/pojntfx/stfs/internal/encryption" "github.com/pojntfx/stfs/internal/encryption"
"github.com/pojntfx/stfs/internal/keys" "github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/internal/signature" "github.com/pojntfx/stfs/internal/signature"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/recovery" "github.com/pojntfx/stfs/pkg/recovery"
@@ -57,6 +58,11 @@ var recoveryIndexCmd = &cobra.Command{
} }
defer reader.Close() defer reader.Close()
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
return recovery.Index( return recovery.Index(
config.DriveReaderConfig{ config.DriveReaderConfig{
Drive: reader, Drive: reader,
@@ -67,7 +73,7 @@ var recoveryIndexCmd = &cobra.Command{
DriveIsRegular: readerIsRegular, DriveIsRegular: readerIsRegular,
}, },
config.MetadataConfig{ config.MetadataConfig{
Metadata: viper.GetString(metadataFlag), Metadata: metadataPersister,
}, },
config.PipeConfig{ config.PipeConfig{
Compression: viper.GetString(compressionFlag), Compression: viper.GetString(compressionFlag),

View File

@@ -3,6 +3,7 @@ package cmd
import ( import (
"github.com/pojntfx/stfs/internal/keys" "github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations" "github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/tape" "github.com/pojntfx/stfs/pkg/tape"
@@ -56,6 +57,11 @@ var restoreCmd = &cobra.Command{
false, false,
) )
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
ops := operations.NewOperations( ops := operations.NewOperations(
tm.GetWriter, tm.GetWriter,
tm.Close, tm.Close,
@@ -65,12 +71,11 @@ var restoreCmd = &cobra.Command{
tm.GetDrive, tm.GetDrive,
tm.Close, tm.Close,
metadataPersister,
) )
return ops.Restore( return ops.Restore(
config.MetadataConfig{
Metadata: viper.GetString(metadataFlag),
},
config.PipeConfig{ config.PipeConfig{
Compression: viper.GetString(compressionFlag), Compression: viper.GetString(compressionFlag),
Encryption: viper.GetString(encryptionFlag), Encryption: viper.GetString(encryptionFlag),

View File

@@ -6,6 +6,7 @@ import (
"github.com/pojntfx/stfs/internal/compression" "github.com/pojntfx/stfs/internal/compression"
"github.com/pojntfx/stfs/internal/keys" "github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging" "github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations" "github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/tape" "github.com/pojntfx/stfs/pkg/tape"
@@ -59,6 +60,11 @@ var updateCmd = &cobra.Command{
false, false,
) )
metadataPersister := persisters.NewMetadataPersister(viper.GetString(metadataFlag))
if err := metadataPersister.Open(); err != nil {
return err
}
ops := operations.NewOperations( ops := operations.NewOperations(
tm.GetWriter, tm.GetWriter,
tm.Close, tm.Close,
@@ -68,12 +74,11 @@ var updateCmd = &cobra.Command{
tm.GetDrive, tm.GetDrive,
tm.Close, tm.Close,
metadataPersister,
) )
if _, err := ops.Update( if _, err := ops.Update(
config.MetadataConfig{
Metadata: viper.GetString(metadataFlag),
},
config.PipeConfig{ config.PipeConfig{
Compression: viper.GetString(compressionFlag), Compression: viper.GetString(compressionFlag),
Encryption: viper.GetString(encryptionFlag), Encryption: viper.GetString(encryptionFlag),

View File

@@ -3,6 +3,8 @@ package config
import ( import (
"io" "io"
"os" "os"
"github.com/pojntfx/stfs/internal/persisters"
) )
type DriveReaderConfig struct { type DriveReaderConfig struct {
@@ -21,7 +23,7 @@ type DriveConfig struct {
} }
type MetadataConfig struct { type MetadataConfig struct {
Metadata string Metadata *persisters.MetadataPersister
} }
type PipeConfig struct { type PipeConfig struct {

View File

@@ -7,23 +7,17 @@ import (
"github.com/pojntfx/stfs/internal/converters" "github.com/pojntfx/stfs/internal/converters"
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata" models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
) )
func Find( func Find(
state config.MetadataConfig, metadata config.MetadataConfig,
expression string, expression string,
onHeader func(hdr *models.Header), onHeader func(hdr *models.Header),
) ([]*tar.Header, error) { ) ([]*tar.Header, error) {
metadataPersister := persisters.NewMetadataPersister(state.Metadata) dbHdrs, err := metadata.Metadata.GetHeaders(context.Background())
if err := metadataPersister.Open(); err != nil {
return []*tar.Header{}, err
}
dbHdrs, err := metadataPersister.GetHeaders(context.Background())
if err != nil { if err != nil {
return []*tar.Header{}, err return []*tar.Header{}, err
} }

View File

@@ -6,23 +6,17 @@ import (
"github.com/pojntfx/stfs/internal/converters" "github.com/pojntfx/stfs/internal/converters"
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata" models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
) )
func List( func List(
state config.MetadataConfig, metadata config.MetadataConfig,
name string, name string,
onHeader func(hdr *models.Header), onHeader func(hdr *models.Header),
) ([]*tar.Header, error) { ) ([]*tar.Header, error) {
metadataPersister := persisters.NewMetadataPersister(state.Metadata) dbHdrs, err := metadata.Metadata.GetHeaderDirectChildren(context.Background(), name)
if err := metadataPersister.Open(); err != nil {
return []*tar.Header{}, err
}
dbHdrs, err := metadataPersister.GetHeaderDirectChildren(context.Background(), name)
if err != nil { if err != nil {
return []*tar.Header{}, err return []*tar.Header{}, err
} }

View File

@@ -17,7 +17,6 @@ import (
"github.com/pojntfx/stfs/internal/encryption" "github.com/pojntfx/stfs/internal/encryption"
"github.com/pojntfx/stfs/internal/ioext" "github.com/pojntfx/stfs/internal/ioext"
"github.com/pojntfx/stfs/internal/mtio" "github.com/pojntfx/stfs/internal/mtio"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/internal/records" "github.com/pojntfx/stfs/internal/records"
"github.com/pojntfx/stfs/internal/signature" "github.com/pojntfx/stfs/internal/signature"
"github.com/pojntfx/stfs/internal/statext" "github.com/pojntfx/stfs/internal/statext"
@@ -32,7 +31,6 @@ var (
) )
func (o *Operations) Archive( func (o *Operations) Archive(
metadata config.MetadataConfig,
pipes config.PipeConfig, pipes config.PipeConfig,
crypto config.CryptoConfig, crypto config.CryptoConfig,
@@ -57,15 +55,10 @@ func (o *Operations) Archive(
return []*tar.Header{}, err return []*tar.Header{}, err
} }
metadataPersister := persisters.NewMetadataPersister(metadata.Metadata)
if err := metadataPersister.Open(); err != nil {
return []*tar.Header{}, err
}
lastIndexedRecord := int64(0) lastIndexedRecord := int64(0)
lastIndexedBlock := int64(0) lastIndexedBlock := int64(0)
if !overwrite { if !overwrite {
lastIndexedRecord, lastIndexedBlock, err = metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize) lastIndexedRecord, lastIndexedBlock, err = o.metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize)
if err != nil { if err != nil {
return []*tar.Header{}, err return []*tar.Header{}, err
} }
@@ -292,7 +285,9 @@ func (o *Operations) Archive(
return hdrs, recovery.Index( return hdrs, recovery.Index(
reader, reader,
drive, drive,
metadata, config.MetadataConfig{
Metadata: o.metadataPersister,
},
pipes, pipes,
crypto, crypto,

View File

@@ -7,7 +7,6 @@ import (
"github.com/pojntfx/stfs/internal/converters" "github.com/pojntfx/stfs/internal/converters"
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata" models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
"github.com/pojntfx/stfs/internal/encryption" "github.com/pojntfx/stfs/internal/encryption"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/internal/records" "github.com/pojntfx/stfs/internal/records"
"github.com/pojntfx/stfs/internal/signature" "github.com/pojntfx/stfs/internal/signature"
"github.com/pojntfx/stfs/internal/tarext" "github.com/pojntfx/stfs/internal/tarext"
@@ -16,7 +15,6 @@ import (
) )
func (o *Operations) Delete( func (o *Operations) Delete(
metadata config.MetadataConfig,
pipes config.PipeConfig, pipes config.PipeConfig,
crypto config.CryptoConfig, crypto config.CryptoConfig,
@@ -39,18 +37,13 @@ func (o *Operations) Delete(
return err return err
} }
metadataPersister := persisters.NewMetadataPersister(metadata.Metadata) lastIndexedRecord, lastIndexedBlock, err := o.metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize)
if err := metadataPersister.Open(); err != nil {
return err
}
lastIndexedRecord, lastIndexedBlock, err := metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize)
if err != nil { if err != nil {
return err return err
} }
headersToDelete := []*models.Header{} headersToDelete := []*models.Header{}
dbhdr, err := metadataPersister.GetHeader(context.Background(), name) dbhdr, err := o.metadataPersister.GetHeader(context.Background(), name)
if err != nil { if err != nil {
return err return err
} }
@@ -58,7 +51,7 @@ func (o *Operations) Delete(
// If the header refers to a directory, get it's children // If the header refers to a directory, get it's children
if dbhdr.Typeflag == tar.TypeDir { if dbhdr.Typeflag == tar.TypeDir {
dbhdrs, err := metadataPersister.GetHeaderChildren(context.Background(), name) dbhdrs, err := o.metadataPersister.GetHeaderChildren(context.Background(), name)
if err != nil { if err != nil {
return err return err
} }
@@ -127,7 +120,9 @@ func (o *Operations) Delete(
return recovery.Index( return recovery.Index(
reader, reader,
drive, drive,
metadata, config.MetadataConfig{
Metadata: o.metadataPersister,
},
pipes, pipes,
crypto, crypto,

View File

@@ -8,7 +8,6 @@ import (
"github.com/pojntfx/stfs/internal/converters" "github.com/pojntfx/stfs/internal/converters"
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata" models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
"github.com/pojntfx/stfs/internal/encryption" "github.com/pojntfx/stfs/internal/encryption"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/internal/records" "github.com/pojntfx/stfs/internal/records"
"github.com/pojntfx/stfs/internal/signature" "github.com/pojntfx/stfs/internal/signature"
"github.com/pojntfx/stfs/internal/tarext" "github.com/pojntfx/stfs/internal/tarext"
@@ -17,7 +16,6 @@ import (
) )
func (o *Operations) Move( func (o *Operations) Move(
metadata config.MetadataConfig,
pipes config.PipeConfig, pipes config.PipeConfig,
crypto config.CryptoConfig, crypto config.CryptoConfig,
@@ -41,18 +39,13 @@ func (o *Operations) Move(
return err return err
} }
metadataPersister := persisters.NewMetadataPersister(metadata.Metadata) lastIndexedRecord, lastIndexedBlock, err := o.metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize)
if err := metadataPersister.Open(); err != nil {
return err
}
lastIndexedRecord, lastIndexedBlock, err := metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize)
if err != nil { if err != nil {
return err return err
} }
headersToMove := []*models.Header{} headersToMove := []*models.Header{}
dbhdr, err := metadataPersister.GetHeader(context.Background(), from) dbhdr, err := o.metadataPersister.GetHeader(context.Background(), from)
if err != nil { if err != nil {
return err return err
} }
@@ -60,7 +53,7 @@ func (o *Operations) Move(
// If the header refers to a directory, get it's children // If the header refers to a directory, get it's children
if dbhdr.Typeflag == tar.TypeDir { if dbhdr.Typeflag == tar.TypeDir {
dbhdrs, err := metadataPersister.GetHeaderChildren(context.Background(), from) dbhdrs, err := o.metadataPersister.GetHeaderChildren(context.Background(), from)
if err != nil { if err != nil {
return err return err
} }
@@ -131,7 +124,9 @@ func (o *Operations) Move(
return recovery.Index( return recovery.Index(
reader, reader,
drive, drive,
metadata, config.MetadataConfig{
Metadata: o.metadataPersister,
},
pipes, pipes,
crypto, crypto,

View File

@@ -3,6 +3,7 @@ package operations
import ( import (
"sync" "sync"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
) )
@@ -16,6 +17,8 @@ type Operations struct {
getDrive func() (config.DriveConfig, error) getDrive func() (config.DriveConfig, error)
closeDrive func() error closeDrive func() error
metadataPersister *persisters.MetadataPersister
diskOperationLock sync.Mutex diskOperationLock sync.Mutex
} }
@@ -28,6 +31,8 @@ func NewOperations(
getDrive func() (config.DriveConfig, error), getDrive func() (config.DriveConfig, error),
closeDrive func() error, closeDrive func() error,
metadataPersister *persisters.MetadataPersister,
) *Operations { ) *Operations {
return &Operations{ return &Operations{
getWriter: getWriter, getWriter: getWriter,
@@ -38,5 +43,7 @@ func NewOperations(
getDrive: getDrive, getDrive: getDrive,
closeDrive: closeDrive, closeDrive: closeDrive,
metadataPersister: metadataPersister,
} }
} }

View File

@@ -9,13 +9,11 @@ import (
"strings" "strings"
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata" models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/recovery" "github.com/pojntfx/stfs/pkg/recovery"
) )
func (o *Operations) Restore( func (o *Operations) Restore(
metadata config.MetadataConfig,
pipes config.PipeConfig, pipes config.PipeConfig,
crypto config.CryptoConfig, crypto config.CryptoConfig,
@@ -29,19 +27,14 @@ func (o *Operations) Restore(
o.diskOperationLock.Lock() o.diskOperationLock.Lock()
defer o.diskOperationLock.Unlock() defer o.diskOperationLock.Unlock()
metadataPersister := persisters.NewMetadataPersister(metadata.Metadata)
if err := metadataPersister.Open(); err != nil {
return err
}
headersToRestore := []*models.Header{} headersToRestore := []*models.Header{}
src := strings.TrimSuffix(from, "/") src := strings.TrimSuffix(from, "/")
dbhdr, err := metadataPersister.GetHeader(context.Background(), src) dbhdr, err := o.metadataPersister.GetHeader(context.Background(), src)
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
src = src + "/" src = src + "/"
dbhdr, err = metadataPersister.GetHeader(context.Background(), src) dbhdr, err = o.metadataPersister.GetHeader(context.Background(), src)
if err != nil { if err != nil {
return err return err
} }
@@ -53,7 +46,7 @@ func (o *Operations) Restore(
// If the header refers to a directory, get it's children // If the header refers to a directory, get it's children
if dbhdr.Typeflag == tar.TypeDir { if dbhdr.Typeflag == tar.TypeDir {
dbhdrs, err := metadataPersister.GetHeaderChildren(context.Background(), src) dbhdrs, err := o.metadataPersister.GetHeaderChildren(context.Background(), src)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -15,7 +15,6 @@ import (
"github.com/pojntfx/stfs/internal/encryption" "github.com/pojntfx/stfs/internal/encryption"
"github.com/pojntfx/stfs/internal/ioext" "github.com/pojntfx/stfs/internal/ioext"
"github.com/pojntfx/stfs/internal/mtio" "github.com/pojntfx/stfs/internal/mtio"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/internal/records" "github.com/pojntfx/stfs/internal/records"
"github.com/pojntfx/stfs/internal/signature" "github.com/pojntfx/stfs/internal/signature"
"github.com/pojntfx/stfs/internal/statext" "github.com/pojntfx/stfs/internal/statext"
@@ -26,7 +25,6 @@ import (
) )
func (o *Operations) Update( func (o *Operations) Update(
metadata config.MetadataConfig,
pipes config.PipeConfig, pipes config.PipeConfig,
crypto config.CryptoConfig, crypto config.CryptoConfig,
@@ -51,12 +49,7 @@ func (o *Operations) Update(
return []*tar.Header{}, err return []*tar.Header{}, err
} }
metadataPersister := persisters.NewMetadataPersister(metadata.Metadata) lastIndexedRecord, lastIndexedBlock, err := o.metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize)
if err := metadataPersister.Open(); err != nil {
return []*tar.Header{}, err
}
lastIndexedRecord, lastIndexedBlock, err := metadataPersister.GetLastIndexedRecordAndBlock(context.Background(), recordSize)
if err != nil { if err != nil {
return []*tar.Header{}, err return []*tar.Header{}, err
} }
@@ -307,7 +300,9 @@ func (o *Operations) Update(
return hdrs, recovery.Index( return hdrs, recovery.Index(
reader, reader,
drive, drive,
metadata, config.MetadataConfig{
Metadata: o.metadataPersister,
},
pipes, pipes,
crypto, crypto,