refactor: Inject mtio package to allow for remote implementation
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
type TapeManager struct {
|
||||
drive string
|
||||
mt config.MagneticTapeIO
|
||||
recordSize int
|
||||
overwrite bool
|
||||
|
||||
@@ -26,11 +27,13 @@ type TapeManager struct {
|
||||
|
||||
func NewTapeManager(
|
||||
drive string,
|
||||
mt config.MagneticTapeIO,
|
||||
recordSize int,
|
||||
overwrite bool,
|
||||
) *TapeManager {
|
||||
return &TapeManager{
|
||||
drive: drive,
|
||||
mt: mt,
|
||||
recordSize: recordSize,
|
||||
overwrite: overwrite,
|
||||
}
|
||||
@@ -47,6 +50,7 @@ func (m *TapeManager) GetWriter() (config.DriveWriterConfig, error) {
|
||||
|
||||
writer, writerIsRegular, err := OpenTapeWriteOnly(
|
||||
m.drive,
|
||||
m.mt,
|
||||
m.recordSize,
|
||||
overwrite,
|
||||
)
|
||||
|
||||
+9
-4
@@ -3,10 +3,15 @@ package tape
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/mtio"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
)
|
||||
|
||||
func OpenTapeWriteOnly(drive string, recordSize int, overwrite bool) (f *os.File, isRegular bool, err error) {
|
||||
func OpenTapeWriteOnly(
|
||||
drive string,
|
||||
mt config.MagneticTapeIO,
|
||||
recordSize int,
|
||||
overwrite bool,
|
||||
) (f *os.File, isRegular bool, err error) {
|
||||
stat, err := os.Stat(drive)
|
||||
if err == nil {
|
||||
isRegular = stat.Mode().IsRegular()
|
||||
@@ -40,7 +45,7 @@ func OpenTapeWriteOnly(drive string, recordSize int, overwrite bool) (f *os.File
|
||||
}
|
||||
|
||||
// Seek to the start of the tape
|
||||
if err := mtio.SeekToRecordOnTape(f.Fd(), 0); err != nil {
|
||||
if err := mt.SeekToRecordOnTape(f.Fd(), 0); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
@@ -65,7 +70,7 @@ func OpenTapeWriteOnly(drive string, recordSize int, overwrite bool) (f *os.File
|
||||
|
||||
if !overwrite {
|
||||
// Go to end of tape
|
||||
if err := mtio.GoToEndOfTape(f.Fd()); err != nil {
|
||||
if err := mt.GoToEndOfTape(f.Fd()); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user