stub cmd.asses
parent
64c4d1908a
commit
137fdf07ed
|
|
@ -2,15 +2,51 @@ package asses
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io/fs"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"show-rss/src/asses"
|
"show-rss/src/asses"
|
||||||
"show-rss/src/cron"
|
"show-rss/src/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var rootDs = []string{
|
||||||
|
"/volume1/video/Bel/Anime",
|
||||||
|
"/volume1/video/QT/TV",
|
||||||
|
}
|
||||||
|
|
||||||
|
type CB func(context.Context, string) error
|
||||||
|
|
||||||
func Main(ctx context.Context) error {
|
func Main(ctx context.Context) error {
|
||||||
return cron.Cron(ctx, asses.Next, One)
|
return cron.Cron(ctx, asses.Next, One)
|
||||||
}
|
}
|
||||||
|
|
||||||
func One(ctx context.Context) error {
|
func One(ctx context.Context) error {
|
||||||
return io.EOF
|
return OneWith(ctx, rootDs, asses.One)
|
||||||
|
}
|
||||||
|
|
||||||
|
func OneWith(ctx context.Context, rootds []string, cb CB) error {
|
||||||
|
for _, rootd := range rootds {
|
||||||
|
if err := one(ctx, rootd, cb); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func one(ctx context.Context, rootd string, cb CB) error {
|
||||||
|
return filepath.WalkDir(rootd, func(p string, d fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if path.Ext(p) != ".mkv" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb(ctx, p)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,28 @@
|
||||||
package asses_test
|
package asses_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"show-rss/src/cmd/asses"
|
||||||
|
"show-rss/src/db"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOne(t *testing.T) {
|
func TestOneWith(t *testing.T) {
|
||||||
|
ctx := db.Test(t, context.Background())
|
||||||
|
|
||||||
|
d := t.TempDir()
|
||||||
|
os.MkdirAll(path.Join(d, "a", "b", "c"), os.ModePerm)
|
||||||
|
os.WriteFile(path.Join(d, "a", "f.mkv"), []byte{}, os.ModePerm)
|
||||||
|
|
||||||
|
if err := asses.OneWith(ctx, []string{d}, func(_ context.Context, p string) error {
|
||||||
|
t.Logf("%q", p)
|
||||||
|
if _, err := os.Stat(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue