admin: implement write and append commands

master
S.J.R. van Schaik 7 years ago
parent e611220f47
commit 42813ee82b
  1. 48
      admin/main.go

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
"os"
)
type CommandFunc func(tbm *TBM, args []string) error
@ -23,6 +24,8 @@ var (
"date": cmd_date,
"set-date": cmd_set_date,
"time": cmd_time,
"write": cmd_write,
"append": cmd_append,
}
)
@ -79,6 +82,51 @@ func cmd_time(tbm *TBM, args []string) error {
return cmd_generic(tbm, "time", args, nil)
}
func cmd_write(tbm *TBM, args []string) error {
f, _ := os.Open(args[0])
defer f.Close()
buf := make([]byte, 256)
n, err := f.Read(buf)
if n == 0 {
return err
}
cmd_generic(tbm, "mufs write", []string{args[1]}, buf)
for {
n, err = f.Read(buf)
if n == 0 {
return err
}
cmd_generic(tbm, "mufs append", []string{args[1]}, buf)
}
}
func cmd_append(tbm *TBM, args []string) error {
var n int
var err error
f, _ := os.Open(args[0])
defer f.Close()
buf := make([]byte, 256)
for {
n, err = f.Read(buf)
if n == 0 {
return err
}
cmd_generic(tbm, "mufs append", []string{args[1]}, buf)
}
}
func main() {
flag.Parse()

Loading…
Cancel
Save