upd repo.json
This commit is contained in:
parent
00a56fa985
commit
b9fe96e56c
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"repositories": [
|
"repo": "https://xn--80abmlgju2eo3byb.xn--p1ai/repo.json",
|
||||||
"https://xn--80abmlgju2eo3byb.xn--p1ai/repo"
|
"repositories": [],
|
||||||
]
|
"packages": {}
|
||||||
}
|
}
|
||||||
|
BIN
pkg/.DS_Store
vendored
Normal file
BIN
pkg/.DS_Store
vendored
Normal file
Binary file not shown.
@ -43,10 +43,8 @@ func BuildNewBinary(tarballURL string) (buildDir string, newBinPath string, err
|
|||||||
return "", "", fmt.Errorf("failed to unpack tarball: %w", err)
|
return "", "", fmt.Errorf("failed to unpack tarball: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Пытаемся найти go.mod в корне распакованного архива
|
|
||||||
goModPath := filepath.Join(tmpDir, "go.mod")
|
goModPath := filepath.Join(tmpDir, "go.mod")
|
||||||
if _, err := os.Stat(goModPath); os.IsNotExist(err) {
|
if _, err := os.Stat(goModPath); os.IsNotExist(err) {
|
||||||
// Если не найден, проверяем, есть ли ровно один подкаталог
|
|
||||||
entries, err := ioutil.ReadDir(tmpDir)
|
entries, err := ioutil.ReadDir(tmpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(tmpDir)
|
os.RemoveAll(tmpDir)
|
||||||
|
@ -2,33 +2,35 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"train/pkg/paths"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Repo string `json:"repo"`
|
||||||
|
Repositories []string `json:"repositories"`
|
||||||
|
Packages map[string]string `json:"packages"`
|
||||||
|
}
|
||||||
|
|
||||||
var configFile string
|
var configFile string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
railsConfig := filepath.Join(paths.BaseDir(), "config", "config.json")
|
home, err := os.UserHomeDir()
|
||||||
if _, err := os.Stat(railsConfig); err == nil {
|
if err == nil {
|
||||||
configFile = railsConfig
|
railsConfig := filepath.Join(home, ".rails", "config", "config.json")
|
||||||
} else {
|
if _, err := os.Stat(railsConfig); err == nil {
|
||||||
configFile = "./config.json"
|
configFile = railsConfig
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
configFile = "./config.json"
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
Repositories []string `json:"repositories"`
|
|
||||||
Packages map[string]string `json:"packages"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig() (*Config, error) {
|
func LoadConfig() (*Config, error) {
|
||||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
|
Repo: "",
|
||||||
Repositories: []string{},
|
Repositories: []string{},
|
||||||
Packages: make(map[string]string),
|
Packages: make(map[string]string),
|
||||||
}
|
}
|
||||||
@ -63,7 +65,7 @@ func AddRepository(repo string) error {
|
|||||||
}
|
}
|
||||||
for _, r := range cfg.Repositories {
|
for _, r := range cfg.Repositories {
|
||||||
if r == repo {
|
if r == repo {
|
||||||
return errors.New("репозиторий уже добавлен")
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg.Repositories = append(cfg.Repositories, repo)
|
cfg.Repositories = append(cfg.Repositories, repo)
|
||||||
@ -76,16 +78,10 @@ func RemoveRepository(repo string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newRepos := []string{}
|
newRepos := []string{}
|
||||||
found := false
|
|
||||||
for _, r := range cfg.Repositories {
|
for _, r := range cfg.Repositories {
|
||||||
if r == repo {
|
if r != repo {
|
||||||
found = true
|
newRepos = append(newRepos, r)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
newRepos = append(newRepos, r)
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
return errors.New("репозиторий не найден")
|
|
||||||
}
|
}
|
||||||
cfg.Repositories = newRepos
|
cfg.Repositories = newRepos
|
||||||
return SaveConfig(cfg)
|
return SaveConfig(cfg)
|
||||||
|
@ -31,6 +31,12 @@ func FetchManifest(name string) (*Manifest, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if cfg.Repo != "" {
|
||||||
|
m, err := FetchManifestFromRepo(cfg.Repo, name)
|
||||||
|
if err == nil {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
if url, ok := cfg.Packages[name]; ok {
|
if url, ok := cfg.Packages[name]; ok {
|
||||||
return fetchManifestFromURL(url)
|
return fetchManifestFromURL(url)
|
||||||
}
|
}
|
||||||
@ -44,7 +50,7 @@ func FetchManifest(name string) (*Manifest, error) {
|
|||||||
lastErr = err
|
lastErr = err
|
||||||
}
|
}
|
||||||
if lastErr == nil {
|
if lastErr == nil {
|
||||||
lastErr = errors.New("не найден ни один репозиторий")
|
lastErr = errors.New("no repository found")
|
||||||
}
|
}
|
||||||
return nil, lastErr
|
return nil, lastErr
|
||||||
}
|
}
|
||||||
@ -56,7 +62,7 @@ func fetchManifestFromURL(url string) (*Manifest, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return nil, errors.New("манифест пакета не найден по ссылке " + url)
|
return nil, errors.New("manifest not found at " + url)
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
42
pkg/manifest/repo.go
Normal file
42
pkg/manifest/repo.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package manifest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RepoPackage struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Manifest string `json:"manifest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepoFile struct {
|
||||||
|
Packages []RepoPackage `json:"packages"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func FetchManifestFromRepo(repoURL, pkgName string) (*Manifest, error) {
|
||||||
|
resp, err := http.Get(repoURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, fmt.Errorf("repo file not found at %s", repoURL)
|
||||||
|
}
|
||||||
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var rf RepoFile
|
||||||
|
if err := json.Unmarshal(data, &rf); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, rp := range rf.Packages {
|
||||||
|
if rp.Name == pkgName {
|
||||||
|
return fetchManifestFromURL(rp.Manifest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("package %s not found in repo", pkgName)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user