mirror of https://github.com/dirtbags/moth.git
Some stuff on my laptop
This commit is contained in:
parent
5f221b466e
commit
cbc69f5647
|
@ -40,10 +40,11 @@ func main() {
|
|||
|
||||
stateFs := afero.NewBasePathFs(afero.NewOsFs(), *statePath)
|
||||
themeFs := afero.NewBasePathFs(afero.NewOsFs(), *themePath)
|
||||
mothballFs := afero.NewBasePathFs(afero.NewOsFs(), *mothballPath)
|
||||
|
||||
theme := NewTheme(themeFs)
|
||||
state := NewState(stateFs)
|
||||
puzzles := NewMothballs(*puzzlePath)
|
||||
puzzles := NewMothballs(mothballFs)
|
||||
|
||||
go state.Run(*refreshInterval)
|
||||
go puzzles.Run(*refreshInterval)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/afero"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
|
@ -8,22 +9,20 @@ import (
|
|||
)
|
||||
|
||||
type Mothballs struct {
|
||||
Component
|
||||
fs afero.Fs
|
||||
categories map[string]*Zipfs
|
||||
}
|
||||
|
||||
func NewMothballs(baseDir string) *Mothballs {
|
||||
func NewMothballs(fs afero.Fs) *Mothballs {
|
||||
return &Mothballs{
|
||||
Component: Component{
|
||||
baseDir: baseDir,
|
||||
},
|
||||
fs: fs,
|
||||
categories: make(map[string]*Zipfs),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mothballs) update() {
|
||||
// Any new categories?
|
||||
files, err := ioutil.ReadDir(m.path())
|
||||
files, err := afero.ReadDir(m.fs, "/")
|
||||
if err != nil {
|
||||
log.Print("Error listing mothballs: ", err)
|
||||
return
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
type Zipfs struct {
|
||||
zf *zip.ReadCloser
|
||||
fs afero.Fs
|
||||
filename string
|
||||
mtime time.Time
|
||||
}
|
||||
|
@ -111,9 +112,10 @@ func (zfsf *ZipfsFile) Close() error {
|
|||
return zfsf.f.Close()
|
||||
}
|
||||
|
||||
func OpenZipfs(filename string) (*Zipfs, error) {
|
||||
func OpenZipfs(fs afero.fs, filename string) (*Zipfs, error) {
|
||||
var zfs Zipfs
|
||||
|
||||
zfs.fs = fs
|
||||
zfs.filename = filename
|
||||
|
||||
err := zfs.Refresh()
|
||||
|
@ -129,7 +131,7 @@ func (zfs *Zipfs) Close() error {
|
|||
}
|
||||
|
||||
func (zfs *Zipfs) Refresh() error {
|
||||
info, err := os.Stat(zfs.filename)
|
||||
info, err := zfs.fs.Stat(zfs.filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -139,6 +141,11 @@ func (zfs *Zipfs) Refresh() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
f, err := zfs.fs.Open(zfs.filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
zf, err := zip.OpenReader(zfs.filename)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue