From 145c017e4da92705f4b9cf16c309ed0affd06386 Mon Sep 17 00:00:00 2001 From: txthinking Date: Sat, 19 Feb 2022 12:24:42 +0000 Subject: [PATCH] nami do not copy again if command in copied dir --- main.go | 2 +- nami.go | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 5093d60..641794a 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( func main() { app := cli.NewApp() app.Name = "nami" - app.Version = "20220128" + app.Version = "20220219" app.Usage = "The easy way to download command from anywhere" app.Authors = []*cli.Author{ { diff --git a/nami.go b/nami.go index 21962db..5f245f1 100644 --- a/nami.go +++ b/nami.go @@ -30,10 +30,11 @@ import ( ) type Nami struct { - DenoDir string - CacheDir string - BinDir string - DB *bbolt.DB + DenoDir string + CacheDir string + BinDir string + DB *bbolt.DB + CopiedDir string } type Package struct { @@ -79,10 +80,11 @@ func NewNami() (*Nami, error) { } } return &Nami{ - CacheDir: filepath.Join(s, ".nami", "cache"), - DenoDir: filepath.Join(s, ".nami", "deno"), - BinDir: bin, - DB: db, + CacheDir: filepath.Join(s, ".nami", "cache"), + DenoDir: filepath.Join(s, ".nami", "deno"), + CopiedDir: filepath.Join(s, ".nami", "copied"), + BinDir: bin, + DB: db, }, nil } @@ -93,6 +95,12 @@ func (n *Nami) CleanCache() error { if err := os.MkdirAll(n.CacheDir, 0777); err != nil { return err } + if err := os.RemoveAll(n.CopiedDir); err != nil { + return err + } + if err := os.MkdirAll(n.CopiedDir, 0777); err != nil { + return err + } return nil } @@ -146,6 +154,19 @@ func (n *Nami) Install(name string) (func(), error) { } continue } + l, err := os.ReadDir(n.CopiedDir) + if err != nil { + return nil, err + } + got := false + for _, v := range l { + if v.Name() == file.Name() { + got = true + } + } + if got { + continue + } r, err := os.Open(filepath.Join(n.CacheDir, file.Name())) if err != nil { return nil, err