Compare commits

..

No commits in common. "bf5a670f80a2cdd2f2fd3ff21495dd685a29a8f2" and "00a56fa985750bbd5df15f3b038bdbb9fe81df43" have entirely different histories.

6 changed files with 31 additions and 73 deletions

View File

@ -1,5 +1,5 @@
{
"repo": "https://xn--80abmlgju2eo3byb.xn--p1ai/repo.json",
"repositories": [],
"packages": {}
"repositories": [
"https://xn--80abmlgju2eo3byb.xn--p1ai/repo"
]
}

View File

@ -43,8 +43,10 @@ func BuildNewBinary(tarballURL string) (buildDir string, newBinPath string, err
return "", "", fmt.Errorf("failed to unpack tarball: %w", err)
}
// Пытаемся найти go.mod в корне распакованного архива
goModPath := filepath.Join(tmpDir, "go.mod")
if _, err := os.Stat(goModPath); os.IsNotExist(err) {
// Если не найден, проверяем, есть ли ровно один подкаталог
entries, err := ioutil.ReadDir(tmpDir)
if err != nil {
os.RemoveAll(tmpDir)

View File

@ -2,35 +2,33 @@ package config
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
)
type Config struct {
Repo string `json:"repo"`
Repositories []string `json:"repositories"`
Packages map[string]string `json:"packages"`
}
"train/pkg/paths"
)
var configFile string
func init() {
home, err := os.UserHomeDir()
if err == nil {
railsConfig := filepath.Join(home, ".rails", "config", "config.json")
if _, err := os.Stat(railsConfig); err == nil {
configFile = railsConfig
return
}
railsConfig := filepath.Join(paths.BaseDir(), "config", "config.json")
if _, err := os.Stat(railsConfig); err == nil {
configFile = railsConfig
} else {
configFile = "./config.json"
}
configFile = "./config.json"
}
type Config struct {
Repositories []string `json:"repositories"`
Packages map[string]string `json:"packages"`
}
func LoadConfig() (*Config, error) {
if _, err := os.Stat(configFile); os.IsNotExist(err) {
cfg := &Config{
Repo: "",
Repositories: []string{},
Packages: make(map[string]string),
}
@ -65,7 +63,7 @@ func AddRepository(repo string) error {
}
for _, r := range cfg.Repositories {
if r == repo {
return nil
return errors.New("репозиторий уже добавлен")
}
}
cfg.Repositories = append(cfg.Repositories, repo)
@ -78,10 +76,16 @@ func RemoveRepository(repo string) error {
return err
}
newRepos := []string{}
found := false
for _, r := range cfg.Repositories {
if r != repo {
newRepos = append(newRepos, r)
if r == repo {
found = true
continue
}
newRepos = append(newRepos, r)
}
if !found {
return errors.New("репозиторий не найден")
}
cfg.Repositories = newRepos
return SaveConfig(cfg)

View File

@ -249,4 +249,4 @@ func GetPackageInfo(name string) (string, error) {
return "", err
}
return string(data), nil
}
}

View File

@ -31,12 +31,6 @@ func FetchManifest(name string) (*Manifest, error) {
if err != nil {
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 {
return fetchManifestFromURL(url)
}
@ -50,7 +44,7 @@ func FetchManifest(name string) (*Manifest, error) {
lastErr = err
}
if lastErr == nil {
lastErr = errors.New("no repository found")
lastErr = errors.New("не найден ни один репозиторий")
}
return nil, lastErr
}
@ -62,7 +56,7 @@ func fetchManifestFromURL(url string) (*Manifest, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, errors.New("manifest not found at " + url)
return nil, errors.New("манифест пакета не найден по ссылке " + url)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
@ -73,4 +67,4 @@ func fetchManifestFromURL(url string) (*Manifest, error) {
return nil, err
}
return &m, nil
}
}

View File

@ -1,42 +0,0 @@
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)
}