diff --git a/cmd/stbak/cmd/archive.go b/cmd/stbak/cmd/archive.go index 65eb2c8..c33fe7b 100644 --- a/cmd/stbak/cmd/archive.go +++ b/cmd/stbak/cmd/archive.go @@ -107,7 +107,7 @@ var archiveCmd = &cobra.Command{ logging.NewLogger().PrintHeader, ) if err != nil { - return nil + return err } return recovery.Index( @@ -130,18 +130,14 @@ var archiveCmd = &cobra.Command{ int(lastIndexedRecord), int(lastIndexedBlock), viper.GetBool(overwriteFlag), + 1, // Ignore the first header, which is the last header which we already indexed func(hdr *tar.Header, i int) error { - // Ignore the first header, which is the last header which we already indexed - if i == 0 { - return nil - } - - if len(hdrs) <= i-1 { + if len(hdrs) <= i { return config.ErrTarHeaderMissing } - *hdr = *hdrs[i-1] + *hdr = *hdrs[i] return nil }, diff --git a/cmd/stbak/cmd/recovery_index.go b/cmd/stbak/cmd/recovery_index.go index 2cf542b..734ff46 100644 --- a/cmd/stbak/cmd/recovery_index.go +++ b/cmd/stbak/cmd/recovery_index.go @@ -68,6 +68,7 @@ var recoveryIndexCmd = &cobra.Command{ viper.GetInt(recordFlag), viper.GetInt(blockFlag), viper.GetBool(overwriteFlag), + 0, func(hdr *tar.Header, i int) error { return encryption.DecryptHeader(hdr, viper.GetString(encryptionFlag), identity) diff --git a/cmd/stbak/cmd/update.go b/cmd/stbak/cmd/update.go index c2cec78..fade11d 100644 --- a/cmd/stbak/cmd/update.go +++ b/cmd/stbak/cmd/update.go @@ -113,18 +113,14 @@ var updateCmd = &cobra.Command{ int(lastIndexedRecord), int(lastIndexedBlock), false, + 1, // Ignore the first header, which is the last header which we already indexed func(hdr *tar.Header, i int) error { - // Ignore the first header, which is the last header which we already indexed - if i == 0 { - return nil - } - - if len(hdrs) <= i-1 { + if len(hdrs) <= i { return config.ErrTarHeaderMissing } - *hdr = *hdrs[i-1] + *hdr = *hdrs[i] return nil }, diff --git a/internal/persisters/metadata.go b/internal/persisters/metadata.go index d900309..a8ca38a 100644 --- a/internal/persisters/metadata.go +++ b/internal/persisters/metadata.go @@ -7,7 +7,6 @@ import ( "context" "database/sql" "fmt" - "log" "strings" "github.com/pojntfx/stfs/internal/db/sqlite/migrations/metadata" @@ -138,8 +137,6 @@ func (p *MetadataPersister) GetHeaderDirectChildren(ctx context.Context, name st rootDepth = int(depth.Depth) } - log.Println(rootDepth) - if err := queries.Raw( fmt.Sprintf( `select %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, diff --git a/pkg/operations/archive.go b/pkg/operations/archive.go index 0e4b735..7164af4 100644 --- a/pkg/operations/archive.go +++ b/pkg/operations/archive.go @@ -2,11 +2,13 @@ package operations import ( "archive/tar" + "errors" "io" "io/fs" "os" "path/filepath" "strconv" + "strings" "github.com/pojntfx/stfs/internal/compression" "github.com/pojntfx/stfs/internal/converters" @@ -22,6 +24,10 @@ import ( "github.com/pojntfx/stfs/pkg/config" ) +var ( + errSocketsNotSupported = errors.New("archive/tar: sockets not supported") +) + func Archive( state config.StateConfig, pipes config.PipeConfig, @@ -107,6 +113,11 @@ func Archive( hdr, err := tar.FileInfoHeader(info, link) if err != nil { + // Skip sockets + if strings.Contains(err.Error(), errSocketsNotSupported.Error()) { + return nil + } + return err } @@ -220,6 +231,8 @@ func Archive( return err } + dirty = true + if !info.Mode().IsRegular() { return nil } @@ -273,8 +286,6 @@ func Archive( return err } - dirty = true - return nil }) } diff --git a/pkg/operations/delete.go b/pkg/operations/delete.go index 20dc4cd..5f7941b 100644 --- a/pkg/operations/delete.go +++ b/pkg/operations/delete.go @@ -106,18 +106,14 @@ func Delete( int(lastIndexedRecord), int(lastIndexedBlock), false, + 1, // Ignore the first header, which is the last header which we already indexed func(hdr *tar.Header, i int) error { - // Ignore the first header, which is the last header which we already indexed - if i == 0 { - return nil - } - - if len(hdrs) <= i-1 { + if len(hdrs) <= i { return config.ErrTarHeaderMissing } - *hdr = *hdrs[i-1] + *hdr = *hdrs[i] return nil }, diff --git a/pkg/operations/move.go b/pkg/operations/move.go index 7b11649..d5d5539 100644 --- a/pkg/operations/move.go +++ b/pkg/operations/move.go @@ -110,18 +110,14 @@ func Move( int(lastIndexedRecord), int(lastIndexedBlock), false, + 1, // Ignore the first header, which is the last header which we already indexed func(hdr *tar.Header, i int) error { - // Ignore the first header, which is the last header which we already indexed - if i == 0 { - return nil - } - - if len(hdrs) <= i-1 { + if len(hdrs) <= i { return config.ErrTarHeaderMissing } - *hdr = *hdrs[i-1] + *hdr = *hdrs[i] return nil }, diff --git a/pkg/recovery/index.go b/pkg/recovery/index.go index 515caf1..8d10d9e 100644 --- a/pkg/recovery/index.go +++ b/pkg/recovery/index.go @@ -31,6 +31,7 @@ func Index( record int, block int, overwrite bool, + offset int, decryptHeader func( hdr *tar.Header, @@ -129,16 +130,18 @@ func Index( break } - if err := decryptHeader(hdr, i); err != nil { - return err - } + if i >= offset { + if err := decryptHeader(hdr, i-offset); err != nil { + return err + } - if err := verifyHeader(hdr, isRegular); err != nil { - return err - } + if err := verifyHeader(hdr, isRegular); err != nil { + return err + } - if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil { - return err + if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil { + return err + } } curr, err := f.Seek(0, io.SeekCurrent) @@ -213,16 +216,18 @@ func Index( } } - if err := decryptHeader(hdr, i); err != nil { - return err - } + if i >= offset { + if err := decryptHeader(hdr, i-offset); err != nil { + return err + } - if err := verifyHeader(hdr, isRegular); err != nil { - return err - } + if err := verifyHeader(hdr, isRegular); err != nil { + return err + } - if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil { - return err + if err := indexHeader(record, block, hdr, metadataPersister, pipes.Compression, pipes.Encryption, onHeader); err != nil { + return err + } } curr = int64(counter.BytesRead)