refactor: Decompose tell and eject funcs
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package hardware
|
||||
|
||||
type DriveConfig struct {
|
||||
Drive string
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package hardware
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
)
|
||||
|
||||
func Eject(
|
||||
state DriveConfig,
|
||||
) error {
|
||||
f, err := os.OpenFile(state.Drive, os.O_RDONLY, os.ModeCharDevice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return controllers.EjectTape(f)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package hardware
|
||||
|
||||
type DriveConfig struct {
|
||||
Drive string
|
||||
}
|
||||
|
||||
func Eject(
|
||||
state DriveConfig,
|
||||
) error
|
||||
|
||||
func Tell(
|
||||
state DriveConfig,
|
||||
) (int, error)
|
||||
@@ -0,0 +1,19 @@
|
||||
package hardware
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/controllers"
|
||||
)
|
||||
|
||||
func Tell(
|
||||
state DriveConfig,
|
||||
) (int64, error) {
|
||||
f, err := os.OpenFile(state.Drive, os.O_RDONLY, os.ModeCharDevice)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return controllers.GetCurrentRecordFromTape(f)
|
||||
}
|
||||
Reference in New Issue
Block a user