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