refactor: Normalize internal and pkg packages
This commit is contained in:
@@ -27,4 +27,6 @@ var (
|
||||
ErrCompressionLevelUnknown = errors.New("unknown compression level")
|
||||
|
||||
ErrMissingTarHeader = errors.New("tar header is missing")
|
||||
|
||||
ErrDrivesUnsupported = errors.New("this system does not support tape drives")
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package hardware
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
)
|
||||
|
||||
func Eject(
|
||||
@@ -15,5 +15,5 @@ func Eject(
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return controllers.EjectTape(f)
|
||||
return mtio.EjectTape(f)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package hardware
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
)
|
||||
|
||||
func Tell(
|
||||
@@ -15,5 +15,5 @@ func Tell(
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return controllers.GetCurrentRecordFromTape(f)
|
||||
return mtio.GetCurrentRecordFromTape(f)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func Find(
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(dbhdr.Record, dbhdr.Lastknownrecord, dbhdr.Block, dbhdr.Lastknownblock, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(dbhdr.Record, dbhdr.Lastknownrecord, dbhdr.Block, dbhdr.Lastknownblock, hdr)); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func List(
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(dbhdr.Record, dbhdr.Lastknownrecord, dbhdr.Block, dbhdr.Lastknownblock, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(dbhdr.Record, dbhdr.Lastknownrecord, dbhdr.Block, dbhdr.Lastknownblock, hdr)); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,15 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/adapters"
|
||||
"github.com/pojntfx/stfs/internal/compression"
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
"github.com/pojntfx/stfs/internal/counters"
|
||||
"github.com/pojntfx/stfs/internal/converters"
|
||||
"github.com/pojntfx/stfs/internal/encryption"
|
||||
"github.com/pojntfx/stfs/internal/formatting"
|
||||
"github.com/pojntfx/stfs/internal/pax"
|
||||
"github.com/pojntfx/stfs/internal/ioext"
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
"github.com/pojntfx/stfs/internal/records"
|
||||
"github.com/pojntfx/stfs/internal/signature"
|
||||
"github.com/pojntfx/stfs/internal/statext"
|
||||
"github.com/pojntfx/stfs/internal/suffix"
|
||||
"github.com/pojntfx/stfs/internal/tape"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
@@ -72,7 +73,7 @@ func Archive(
|
||||
}
|
||||
|
||||
// Seek to the start of the tape
|
||||
if err := controllers.SeekToRecordOnTape(f, 0); err != nil {
|
||||
if err := mtio.SeekToRecordOnTape(f, 0); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ func Archive(
|
||||
return err
|
||||
}
|
||||
|
||||
if err := adapters.EnhanceHeader(path, hdr); err != nil {
|
||||
if err := statext.EnhanceHeader(path, hdr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ func Archive(
|
||||
|
||||
if info.Mode().IsRegular() {
|
||||
// Get the compressed size for the header
|
||||
fileSizeCounter := &counters.CounterWriter{
|
||||
fileSizeCounter := &ioext.CounterWriter{
|
||||
Writer: io.Discard,
|
||||
}
|
||||
|
||||
@@ -152,7 +153,7 @@ func Archive(
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
buf := make([]byte, controllers.BlockSize*recordSize)
|
||||
buf := make([]byte, mtio.BlockSize*recordSize)
|
||||
if _, err := io.CopyBuffer(compressor, signer, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -177,14 +178,14 @@ func Archive(
|
||||
if hdr.PAXRecords == nil {
|
||||
hdr.PAXRecords = map[string]string{}
|
||||
}
|
||||
hdr.PAXRecords[pax.STFSRecordUncompressedSize] = strconv.Itoa(int(hdr.Size))
|
||||
hdr.PAXRecords[records.STFSRecordUncompressedSize] = strconv.Itoa(int(hdr.Size))
|
||||
signature, err := sign()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if signature != "" {
|
||||
hdr.PAXRecords[pax.STFSRecordSignature] = signature
|
||||
hdr.PAXRecords[records.STFSRecordSignature] = signature
|
||||
}
|
||||
hdr.Size = int64(fileSizeCounter.BytesRead)
|
||||
|
||||
@@ -202,7 +203,7 @@ func Archive(
|
||||
first = false
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -252,7 +253,7 @@ func Archive(
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
buf := make([]byte, controllers.BlockSize*recordSize)
|
||||
buf := make([]byte, mtio.BlockSize*recordSize)
|
||||
if _, err := io.CopyBuffer(compressor, file, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
|
||||
"github.com/pojntfx/stfs/internal/encryption"
|
||||
"github.com/pojntfx/stfs/internal/formatting"
|
||||
"github.com/pojntfx/stfs/internal/pax"
|
||||
"github.com/pojntfx/stfs/internal/persisters"
|
||||
"github.com/pojntfx/stfs/internal/records"
|
||||
"github.com/pojntfx/stfs/internal/signature"
|
||||
"github.com/pojntfx/stfs/internal/tape"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
@@ -71,8 +71,8 @@ func Delete(
|
||||
}
|
||||
|
||||
hdr.Size = 0 // Don't try to seek after the record
|
||||
hdr.PAXRecords[pax.STFSRecordVersion] = pax.STFSRecordVersion1
|
||||
hdr.PAXRecords[pax.STFSRecordAction] = pax.STFSRecordActionDelete
|
||||
hdr.PAXRecords[records.STFSRecordVersion] = records.STFSRecordVersion1
|
||||
hdr.PAXRecords[records.STFSRecordAction] = records.STFSRecordActionDelete
|
||||
|
||||
if err := signature.SignHeader(hdr, isRegular, pipes.Signature, crypto.Identity); err != nil {
|
||||
return err
|
||||
@@ -88,7 +88,7 @@ func Delete(
|
||||
|
||||
dirty = true
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
|
||||
"github.com/pojntfx/stfs/internal/encryption"
|
||||
"github.com/pojntfx/stfs/internal/formatting"
|
||||
"github.com/pojntfx/stfs/internal/pax"
|
||||
"github.com/pojntfx/stfs/internal/persisters"
|
||||
"github.com/pojntfx/stfs/internal/records"
|
||||
"github.com/pojntfx/stfs/internal/signature"
|
||||
"github.com/pojntfx/stfs/internal/tape"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
@@ -74,9 +74,9 @@ func Move(
|
||||
|
||||
hdr.Size = 0 // Don't try to seek after the record
|
||||
hdr.Name = strings.TrimSuffix(to, "/") + strings.TrimPrefix(hdr.Name, strings.TrimSuffix(from, "/"))
|
||||
hdr.PAXRecords[pax.STFSRecordVersion] = pax.STFSRecordVersion1
|
||||
hdr.PAXRecords[pax.STFSRecordAction] = pax.STFSRecordActionUpdate
|
||||
hdr.PAXRecords[pax.STFSRecordReplacesName] = dbhdr.Name
|
||||
hdr.PAXRecords[records.STFSRecordVersion] = records.STFSRecordVersion1
|
||||
hdr.PAXRecords[records.STFSRecordAction] = records.STFSRecordActionUpdate
|
||||
hdr.PAXRecords[records.STFSRecordReplacesName] = dbhdr.Name
|
||||
|
||||
if err := signature.SignHeader(hdr, isRegular, pipes.Signature, crypto.Identity); err != nil {
|
||||
return err
|
||||
@@ -92,7 +92,7 @@ func Move(
|
||||
|
||||
dirty = true
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func Restore(
|
||||
return err
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(dbhdr.Record, dbhdr.Lastknownrecord, dbhdr.Block, dbhdr.Lastknownblock, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(dbhdr.Record, dbhdr.Lastknownrecord, dbhdr.Block, dbhdr.Lastknownblock, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,15 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/adapters"
|
||||
"github.com/pojntfx/stfs/internal/compression"
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
"github.com/pojntfx/stfs/internal/counters"
|
||||
"github.com/pojntfx/stfs/internal/converters"
|
||||
"github.com/pojntfx/stfs/internal/encryption"
|
||||
"github.com/pojntfx/stfs/internal/formatting"
|
||||
"github.com/pojntfx/stfs/internal/pax"
|
||||
"github.com/pojntfx/stfs/internal/ioext"
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
"github.com/pojntfx/stfs/internal/records"
|
||||
"github.com/pojntfx/stfs/internal/signature"
|
||||
"github.com/pojntfx/stfs/internal/statext"
|
||||
"github.com/pojntfx/stfs/internal/suffix"
|
||||
"github.com/pojntfx/stfs/internal/tape"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
@@ -57,7 +58,7 @@ func Update(
|
||||
return err
|
||||
}
|
||||
|
||||
if err := adapters.EnhanceHeader(path, hdr); err != nil {
|
||||
if err := statext.EnhanceHeader(path, hdr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -66,12 +67,12 @@ func Update(
|
||||
if hdr.PAXRecords == nil {
|
||||
hdr.PAXRecords = map[string]string{}
|
||||
}
|
||||
hdr.PAXRecords[pax.STFSRecordVersion] = pax.STFSRecordVersion1
|
||||
hdr.PAXRecords[pax.STFSRecordAction] = pax.STFSRecordActionUpdate
|
||||
hdr.PAXRecords[records.STFSRecordVersion] = records.STFSRecordVersion1
|
||||
hdr.PAXRecords[records.STFSRecordAction] = records.STFSRecordActionUpdate
|
||||
|
||||
if info.Mode().IsRegular() && overwrite {
|
||||
// Get the compressed size for the header
|
||||
fileSizeCounter := &counters.CounterWriter{
|
||||
fileSizeCounter := &ioext.CounterWriter{
|
||||
Writer: io.Discard,
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ func Update(
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
buf := make([]byte, controllers.BlockSize*recordSize)
|
||||
buf := make([]byte, mtio.BlockSize*recordSize)
|
||||
if _, err := io.CopyBuffer(compressor, signer, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -131,14 +132,14 @@ func Update(
|
||||
if hdr.PAXRecords == nil {
|
||||
hdr.PAXRecords = map[string]string{}
|
||||
}
|
||||
hdr.PAXRecords[pax.STFSRecordUncompressedSize] = strconv.Itoa(int(hdr.Size))
|
||||
hdr.PAXRecords[records.STFSRecordUncompressedSize] = strconv.Itoa(int(hdr.Size))
|
||||
signature, err := sign()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if signature != "" {
|
||||
hdr.PAXRecords[pax.STFSRecordSignature] = signature
|
||||
hdr.PAXRecords[records.STFSRecordSignature] = signature
|
||||
}
|
||||
hdr.Size = int64(fileSizeCounter.BytesRead)
|
||||
|
||||
@@ -157,9 +158,9 @@ func Update(
|
||||
}
|
||||
|
||||
if overwrite {
|
||||
hdr.PAXRecords[pax.STFSRecordReplacesContent] = pax.STFSRecordReplacesContentTrue
|
||||
hdr.PAXRecords[records.STFSRecordReplacesContent] = records.STFSRecordReplacesContentTrue
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -209,7 +210,7 @@ func Update(
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
buf := make([]byte, controllers.BlockSize*recordSize)
|
||||
buf := make([]byte, mtio.BlockSize*recordSize)
|
||||
if _, err := io.CopyBuffer(compressor, file, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -233,7 +234,7 @@ func Update(
|
||||
} else {
|
||||
hdr.Size = 0 // Don't try to seek after the record
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(-1, -1, -1, -1, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/compression"
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
"github.com/pojntfx/stfs/internal/converters"
|
||||
"github.com/pojntfx/stfs/internal/encryption"
|
||||
"github.com/pojntfx/stfs/internal/formatting"
|
||||
"github.com/pojntfx/stfs/internal/pax"
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
"github.com/pojntfx/stfs/internal/records"
|
||||
"github.com/pojntfx/stfs/internal/signature"
|
||||
"github.com/pojntfx/stfs/internal/tape"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
@@ -40,20 +41,20 @@ func Fetch(
|
||||
var tr *tar.Reader
|
||||
if isRegular {
|
||||
// Seek to record and block
|
||||
if _, err := f.Seek(int64((recordSize*controllers.BlockSize*record)+block*controllers.BlockSize), io.SeekStart); err != nil {
|
||||
if _, err := f.Seek(int64((recordSize*mtio.BlockSize*record)+block*mtio.BlockSize), io.SeekStart); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tr = tar.NewReader(f)
|
||||
} else {
|
||||
// Seek to record
|
||||
if err := controllers.SeekToRecordOnTape(f, int32(record)); err != nil {
|
||||
if err := mtio.SeekToRecordOnTape(f, int32(record)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Seek to block
|
||||
br := bufio.NewReaderSize(f, controllers.BlockSize*recordSize)
|
||||
if _, err := br.Read(make([]byte, block*controllers.BlockSize)); err != nil {
|
||||
br := bufio.NewReaderSize(f, mtio.BlockSize*recordSize)
|
||||
if _, err := br.Read(make([]byte, block*mtio.BlockSize)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ func Fetch(
|
||||
return err
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(int64(record), -1, int64(block), -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(int64(record), -1, int64(block), -1, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -122,7 +123,7 @@ func Fetch(
|
||||
|
||||
sig := ""
|
||||
if hdr.PAXRecords != nil {
|
||||
if s, ok := hdr.PAXRecords[pax.STFSRecordSignature]; ok {
|
||||
if s, ok := hdr.PAXRecords[records.STFSRecordSignature]; ok {
|
||||
sig = s
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
"github.com/pojntfx/stfs/internal/converters"
|
||||
"github.com/pojntfx/stfs/internal/counters"
|
||||
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
|
||||
"github.com/pojntfx/stfs/internal/formatting"
|
||||
"github.com/pojntfx/stfs/internal/pax"
|
||||
"github.com/pojntfx/stfs/internal/ioext"
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
"github.com/pojntfx/stfs/internal/persisters"
|
||||
"github.com/pojntfx/stfs/internal/records"
|
||||
"github.com/pojntfx/stfs/internal/suffix"
|
||||
"github.com/pojntfx/stfs/internal/tape"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
@@ -70,7 +70,7 @@ func Index(
|
||||
|
||||
if isRegular {
|
||||
// Seek to record and block
|
||||
if _, err := f.Seek(int64((recordSize*controllers.BlockSize*record)+block*controllers.BlockSize), 0); err != nil {
|
||||
if _, err := f.Seek(int64((recordSize*mtio.BlockSize*record)+block*mtio.BlockSize), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func Index(
|
||||
return err
|
||||
}
|
||||
|
||||
nextTotalBlocks := math.Ceil(float64((curr)) / float64(controllers.BlockSize))
|
||||
nextTotalBlocks := math.Ceil(float64((curr)) / float64(mtio.BlockSize))
|
||||
record = int64(nextTotalBlocks) / int64(recordSize)
|
||||
block = int64(nextTotalBlocks) - (record * int64(recordSize))
|
||||
|
||||
@@ -102,7 +102,7 @@ func Index(
|
||||
}
|
||||
|
||||
// Seek to record and block
|
||||
if _, err := f.Seek(int64((recordSize*controllers.BlockSize*int(record))+int(block)*controllers.BlockSize), io.SeekStart); err != nil {
|
||||
if _, err := f.Seek(int64((recordSize*mtio.BlockSize*int(record))+int(block)*mtio.BlockSize), io.SeekStart); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func Index(
|
||||
return err
|
||||
}
|
||||
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(controllers.BlockSize))
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(mtio.BlockSize))
|
||||
record = int64(nextTotalBlocks) / int64(recordSize)
|
||||
block = int64(nextTotalBlocks) - (record * int64(recordSize))
|
||||
|
||||
@@ -167,21 +167,21 @@ func Index(
|
||||
}
|
||||
} else {
|
||||
// Seek to record
|
||||
if err := controllers.SeekToRecordOnTape(f, int32(record)); err != nil {
|
||||
if err := mtio.SeekToRecordOnTape(f, int32(record)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Seek to block
|
||||
br := bufio.NewReaderSize(f, controllers.BlockSize*recordSize)
|
||||
if _, err := br.Read(make([]byte, block*controllers.BlockSize)); err != nil {
|
||||
br := bufio.NewReaderSize(f, mtio.BlockSize*recordSize)
|
||||
if _, err := br.Read(make([]byte, block*mtio.BlockSize)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
record := int64(record)
|
||||
block := int64(block)
|
||||
|
||||
curr := int64((recordSize * controllers.BlockSize * int(record)) + (int(block) * controllers.BlockSize))
|
||||
counter := &counters.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
curr := int64((recordSize * mtio.BlockSize * int(record)) + (int(block) * mtio.BlockSize))
|
||||
counter := &ioext.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
i := 0
|
||||
|
||||
tr := tar.NewReader(counter)
|
||||
@@ -189,21 +189,21 @@ func Index(
|
||||
hdr, err := tr.Next()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if err := controllers.GoToNextFileOnTape(f); err != nil {
|
||||
if err := mtio.GoToNextFileOnTape(f); err != nil {
|
||||
// EOD
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
record, err = controllers.GetCurrentRecordFromTape(f)
|
||||
record, err = mtio.GetCurrentRecordFromTape(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
block = 0
|
||||
|
||||
br = bufio.NewReaderSize(f, controllers.BlockSize*recordSize)
|
||||
curr = int64(int64(recordSize) * controllers.BlockSize * record)
|
||||
counter = &counters.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
br = bufio.NewReaderSize(f, mtio.BlockSize*recordSize)
|
||||
curr = int64(int64(recordSize) * mtio.BlockSize * record)
|
||||
counter = &ioext.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
tr = tar.NewReader(counter)
|
||||
|
||||
continue
|
||||
@@ -232,7 +232,7 @@ func Index(
|
||||
|
||||
currAndSize := int64(counter.BytesRead)
|
||||
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(controllers.BlockSize))
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(mtio.BlockSize))
|
||||
record = int64(nextTotalBlocks) / int64(recordSize)
|
||||
block = int64(nextTotalBlocks) - (record * int64(recordSize))
|
||||
|
||||
@@ -261,7 +261,7 @@ func indexHeader(
|
||||
}
|
||||
}
|
||||
|
||||
uncompressedSize, ok := hdr.PAXRecords[pax.STFSRecordUncompressedSize]
|
||||
uncompressedSize, ok := hdr.PAXRecords[records.STFSRecordUncompressedSize]
|
||||
if ok {
|
||||
size, err := strconv.Atoi(uncompressedSize)
|
||||
if err != nil {
|
||||
@@ -279,24 +279,24 @@ func indexHeader(
|
||||
hdr.Name = newName
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(record, -1, block, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(record, -1, block, -1, hdr)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stfsVersion, ok := hdr.PAXRecords[pax.STFSRecordVersion]
|
||||
stfsVersion, ok := hdr.PAXRecords[records.STFSRecordVersion]
|
||||
if !ok {
|
||||
stfsVersion = pax.STFSRecordVersion1
|
||||
stfsVersion = records.STFSRecordVersion1
|
||||
}
|
||||
|
||||
switch stfsVersion {
|
||||
case pax.STFSRecordVersion1:
|
||||
stfsAction, ok := hdr.PAXRecords[pax.STFSRecordAction]
|
||||
case records.STFSRecordVersion1:
|
||||
stfsAction, ok := hdr.PAXRecords[records.STFSRecordAction]
|
||||
if !ok {
|
||||
stfsAction = pax.STFSRecordActionCreate
|
||||
stfsAction = records.STFSRecordActionCreate
|
||||
}
|
||||
|
||||
switch stfsAction {
|
||||
case pax.STFSRecordActionCreate:
|
||||
case records.STFSRecordActionCreate:
|
||||
dbhdr, err := converters.TarHeaderToDBHeader(record, record, block, block, hdr)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -305,20 +305,20 @@ func indexHeader(
|
||||
if err := metadataPersister.UpsertHeader(context.Background(), dbhdr); err != nil {
|
||||
return err
|
||||
}
|
||||
case pax.STFSRecordActionDelete:
|
||||
case records.STFSRecordActionDelete:
|
||||
if _, err := metadataPersister.DeleteHeader(context.Background(), hdr.Name, record, block); err != nil {
|
||||
return err
|
||||
}
|
||||
case pax.STFSRecordActionUpdate:
|
||||
case records.STFSRecordActionUpdate:
|
||||
moveAfterEdits := false
|
||||
oldName := hdr.Name
|
||||
if _, ok := hdr.PAXRecords[pax.STFSRecordReplacesName]; ok {
|
||||
if _, ok := hdr.PAXRecords[records.STFSRecordReplacesName]; ok {
|
||||
moveAfterEdits = true
|
||||
oldName = hdr.PAXRecords[pax.STFSRecordReplacesName]
|
||||
oldName = hdr.PAXRecords[records.STFSRecordReplacesName]
|
||||
}
|
||||
|
||||
var newHdr *models.Header
|
||||
if replacesContent, ok := hdr.PAXRecords[pax.STFSRecordReplacesContent]; ok && replacesContent == pax.STFSRecordReplacesContentTrue {
|
||||
if replacesContent, ok := hdr.PAXRecords[records.STFSRecordReplacesContent]; ok && replacesContent == records.STFSRecordReplacesContentTrue {
|
||||
// Content & metadata update; use the new record & block
|
||||
h, err := converters.TarHeaderToDBHeader(record, record, block, block, hdr)
|
||||
if err != nil {
|
||||
@@ -360,10 +360,10 @@ func indexHeader(
|
||||
}
|
||||
|
||||
default:
|
||||
return pax.ErrUnsupportedAction
|
||||
return records.ErrUnsupportedAction
|
||||
}
|
||||
default:
|
||||
return pax.ErrUnsupportedVersion
|
||||
return records.ErrUnsupportedVersion
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"io/ioutil"
|
||||
"math"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
"github.com/pojntfx/stfs/internal/counters"
|
||||
"github.com/pojntfx/stfs/internal/converters"
|
||||
"github.com/pojntfx/stfs/internal/encryption"
|
||||
"github.com/pojntfx/stfs/internal/formatting"
|
||||
"github.com/pojntfx/stfs/internal/ioext"
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
"github.com/pojntfx/stfs/internal/signature"
|
||||
"github.com/pojntfx/stfs/internal/tape"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
@@ -36,7 +37,7 @@ func Query(
|
||||
|
||||
if isRegular {
|
||||
// Seek to record and block
|
||||
if _, err := f.Seek(int64((recordSize*controllers.BlockSize*record)+block*controllers.BlockSize), 0); err != nil {
|
||||
if _, err := f.Seek(int64((recordSize*mtio.BlockSize*record)+block*mtio.BlockSize), 0); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
@@ -54,7 +55,7 @@ func Query(
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
nextTotalBlocks := math.Ceil(float64((curr)) / float64(controllers.BlockSize))
|
||||
nextTotalBlocks := math.Ceil(float64((curr)) / float64(mtio.BlockSize))
|
||||
record = int64(nextTotalBlocks) / int64(recordSize)
|
||||
block = int64(nextTotalBlocks) - (record * int64(recordSize))
|
||||
|
||||
@@ -67,7 +68,7 @@ func Query(
|
||||
}
|
||||
|
||||
// Seek to record and block
|
||||
if _, err := f.Seek(int64((recordSize*controllers.BlockSize*int(record))+int(block)*controllers.BlockSize), io.SeekStart); err != nil {
|
||||
if _, err := f.Seek(int64((recordSize*mtio.BlockSize*int(record))+int(block)*mtio.BlockSize), io.SeekStart); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ func Query(
|
||||
}
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(record, -1, block, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(record, -1, block, -1, hdr)); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ func Query(
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(controllers.BlockSize))
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(mtio.BlockSize))
|
||||
record = int64(nextTotalBlocks) / int64(recordSize)
|
||||
block = int64(nextTotalBlocks) - (record * int64(recordSize))
|
||||
|
||||
@@ -139,42 +140,42 @@ func Query(
|
||||
}
|
||||
} else {
|
||||
// Seek to record
|
||||
if err := controllers.SeekToRecordOnTape(f, int32(record)); err != nil {
|
||||
if err := mtio.SeekToRecordOnTape(f, int32(record)); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
// Seek to block
|
||||
br := bufio.NewReaderSize(f, controllers.BlockSize*recordSize)
|
||||
if _, err := br.Read(make([]byte, block*controllers.BlockSize)); err != nil {
|
||||
br := bufio.NewReaderSize(f, mtio.BlockSize*recordSize)
|
||||
if _, err := br.Read(make([]byte, block*mtio.BlockSize)); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
record := int64(record)
|
||||
block := int64(block)
|
||||
|
||||
curr := int64((recordSize * controllers.BlockSize * int(record)) + (int(block) * controllers.BlockSize))
|
||||
counter := &counters.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
curr := int64((recordSize * mtio.BlockSize * int(record)) + (int(block) * mtio.BlockSize))
|
||||
counter := &ioext.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
|
||||
tr := tar.NewReader(counter)
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if err := controllers.GoToNextFileOnTape(f); err != nil {
|
||||
if err := mtio.GoToNextFileOnTape(f); err != nil {
|
||||
// EOD
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
record, err = controllers.GetCurrentRecordFromTape(f)
|
||||
record, err = mtio.GetCurrentRecordFromTape(f)
|
||||
if err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
block = 0
|
||||
|
||||
br = bufio.NewReaderSize(f, controllers.BlockSize*recordSize)
|
||||
curr := int64(int64(recordSize) * controllers.BlockSize * record)
|
||||
counter := &counters.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
br = bufio.NewReaderSize(f, mtio.BlockSize*recordSize)
|
||||
curr := int64(int64(recordSize) * mtio.BlockSize * record)
|
||||
counter := &ioext.CounterReader{Reader: br, BytesRead: int(curr)}
|
||||
tr = tar.NewReader(counter)
|
||||
|
||||
continue
|
||||
@@ -197,7 +198,7 @@ func Query(
|
||||
}
|
||||
}
|
||||
|
||||
if err := formatting.PrintCSV(formatting.GetTARHeaderAsCSV(record, -1, block, -1, hdr)); err != nil {
|
||||
if err := formatting.PrintCSV(converters.TARHeaderToCSV(record, -1, block, -1, hdr)); err != nil {
|
||||
return []*tar.Header{}, err
|
||||
}
|
||||
|
||||
@@ -209,7 +210,7 @@ func Query(
|
||||
|
||||
currAndSize := int64(counter.BytesRead)
|
||||
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(controllers.BlockSize))
|
||||
nextTotalBlocks := math.Ceil(float64(curr+(currAndSize-curr)) / float64(mtio.BlockSize))
|
||||
record = int64(nextTotalBlocks) / int64(recordSize)
|
||||
block = int64(nextTotalBlocks) - (record * int64(recordSize))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user