Skip to content

Commit

Permalink
nami do not copy again if command in copied dir
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Feb 19, 2022
1 parent 67f9bff commit 145c017
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
37 changes: 29 additions & 8 deletions nami.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 145c017

Please sign in to comment.