Browse Source

Start using appdir

pull/8/head
Daniel Martí 11 years ago
parent
commit
b9f09874a1
  1. 27
      cmd/fdroidcl/main.go

27
cmd/fdroidcl/main.go

@ -8,8 +8,11 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"path/filepath"
"strings" "strings"
"github.com/mvdan/appdir"
"github.com/mvdan/fdroidcl" "github.com/mvdan/fdroidcl"
"github.com/mvdan/fdroidcl/adb" "github.com/mvdan/fdroidcl/adb"
) )
@ -157,22 +160,34 @@ func init() {
} }
} }
func appSubdir(appdir string) string {
p := filepath.Join(appdir, "fdroidcl")
if err := os.MkdirAll(p, 0755); err != nil {
log.Fatalf("Could not create app dir: %v", err)
}
return p
}
func indexPath(repoName string) string { func indexPath(repoName string) string {
return repoName + ".jar" cache, err := appdir.Cache()
if err != nil {
log.Fatalf("Could not determine cache dir: %v", err)
}
return filepath.Join(appSubdir(cache), repoName + ".jar")
} }
func updateIndex(repoName, repoURL string) error { func updateIndex(repoName, repoURL string) error {
path := indexPath(repoName) p := indexPath(repoName)
url := fmt.Sprintf("%s/%s", repoURL, path) url := fmt.Sprintf("%s/%s", repoURL, "index.jar")
if err := downloadEtag(url, path); err != nil { if err := downloadEtag(url, p); err != nil {
return err return err
} }
return nil return nil
} }
func mustLoadIndex(repoName string) *fdroidcl.Index { func mustLoadIndex(repoName string) *fdroidcl.Index {
path := indexPath(repoName) p := indexPath(repoName)
f, err := os.Open(path) f, err := os.Open(p)
if err != nil { if err != nil {
log.Fatalf("Could not open index file: %v", err) log.Fatalf("Could not open index file: %v", err)
} }

Loading…
Cancel
Save