mirror of
https://github.com/mudler/luet.git
synced 2025-07-04 19:16:50 +00:00
parent
ed63236516
commit
20d01e43c7
@ -1,5 +1,6 @@
|
|||||||
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
||||||
// Daniele Rondina <geaaru@sabayonlinux.org>
|
// Daniele Rondina <geaaru@sabayonlinux.org>
|
||||||
|
// Copyright © 2021 Ettore Di Giacinto <mudler@mocaccino.org>
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@ -24,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewRepoUpdateCommand() *cobra.Command {
|
func NewRepoUpdateCommand() *cobra.Command {
|
||||||
var ans = &cobra.Command{
|
var repoUpdate = &cobra.Command{
|
||||||
Use: "update [repo1] [repo2] [OPTIONS]",
|
Use: "update [repo1] [repo2] [OPTIONS]",
|
||||||
Short: "Update a specific cached repository or all cached repositories.",
|
Short: "Update a specific cached repository or all cached repositories.",
|
||||||
Example: `
|
Example: `
|
||||||
@ -72,8 +73,8 @@ $> luet repo update repo1 repo2
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ans.Flags().BoolP("ignore-errors", "i", false, "Ignore errors on sync repositories.")
|
repoUpdate.Flags().BoolP("ignore-errors", "i", false, "Ignore errors on sync repositories.")
|
||||||
ans.Flags().BoolP("force", "f", false, "Force resync.")
|
repoUpdate.Flags().BoolP("force", "f", true, "Force resync.")
|
||||||
|
|
||||||
return ans
|
return repoUpdate
|
||||||
}
|
}
|
||||||
|
@ -856,7 +856,20 @@ func (r *LuetSystemRepository) Sync(ctx *types.Context, force bool) (*LuetSystem
|
|||||||
var repoUpdated bool = false
|
var repoUpdated bool = false
|
||||||
var treefs, metafs string
|
var treefs, metafs string
|
||||||
|
|
||||||
|
repobasedir := ctx.Config.GetSystem().GetRepoDatabaseDirPath(r.GetName())
|
||||||
|
|
||||||
|
toTimeSync := false
|
||||||
|
dat, err := ioutil.ReadFile(filepath.Join(repobasedir, "SYNCTIME"))
|
||||||
|
if err == nil {
|
||||||
|
parsed, _ := time.Parse(time.RFC3339, string(dat))
|
||||||
|
if time.Now().After(parsed.Add(24 * time.Hour)) {
|
||||||
|
toTimeSync = true
|
||||||
|
ctx.Debug(r.Name, "is old, refresh is suggested")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Debug("Sync of the repository", r.Name, "in progress...")
|
ctx.Debug("Sync of the repository", r.Name, "in progress...")
|
||||||
|
|
||||||
c := r.Client(ctx)
|
c := r.Client(ctx)
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return nil, errors.New("no client could be generated from repository")
|
return nil, errors.New("no client could be generated from repository")
|
||||||
@ -864,20 +877,29 @@ func (r *LuetSystemRepository) Sync(ctx *types.Context, force bool) (*LuetSystem
|
|||||||
|
|
||||||
repositoryReferenceID := r.referenceID()
|
repositoryReferenceID := r.referenceID()
|
||||||
|
|
||||||
|
var downloadedRepoMeta *LuetSystemRepository
|
||||||
|
var file string
|
||||||
|
repoFile := filepath.Join(repobasedir, repositoryReferenceID)
|
||||||
|
|
||||||
|
_, repoExistsErr := os.Stat(repoFile)
|
||||||
|
if toTimeSync || force || os.IsNotExist(repoExistsErr) {
|
||||||
// Retrieve remote repository.yaml for retrieve revision and date
|
// Retrieve remote repository.yaml for retrieve revision and date
|
||||||
file, err := c.DownloadFile(repositoryReferenceID)
|
file, err = c.DownloadFile(repositoryReferenceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "while downloading "+repositoryReferenceID)
|
return nil, errors.Wrap(err, "while downloading "+repositoryReferenceID)
|
||||||
}
|
}
|
||||||
|
downloadedRepoMeta, err = r.ReadSpecFile(file)
|
||||||
repobasedir := ctx.Config.GetSystem().GetRepoDatabaseDirPath(r.GetName())
|
|
||||||
downloadedRepoMeta, err := r.ReadSpecFile(file)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Remove temporary file that contains repository.yaml
|
|
||||||
// Example: /tmp/HttpClient236052003
|
|
||||||
defer os.RemoveAll(file)
|
defer os.RemoveAll(file)
|
||||||
|
} else {
|
||||||
|
downloadedRepoMeta, err = r.ReadSpecFile(repoFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
repoUpdated = true
|
||||||
|
}
|
||||||
|
|
||||||
if r.Cached {
|
if r.Cached {
|
||||||
if !force {
|
if !force {
|
||||||
@ -968,8 +990,8 @@ func (r *LuetSystemRepository) Sync(ctx *types.Context, force bool) (*LuetSystem
|
|||||||
downloadedRepoMeta.GetRevision(),
|
downloadedRepoMeta.GetRevision(),
|
||||||
time.Unix(tsec, 0).String()))
|
time.Unix(tsec, 0).String()))
|
||||||
|
|
||||||
} else {
|
now := time.Now().Format(time.RFC3339)
|
||||||
ctx.Info("Repository", downloadedRepoMeta.GetName(), "is already up to date.")
|
ioutil.WriteFile(filepath.Join(repobasedir, "SYNCTIME"), []byte(now), os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
meta, err := NewLuetSystemRepositoryMetadata(
|
meta, err := NewLuetSystemRepositoryMetadata(
|
||||||
@ -993,11 +1015,14 @@ func (r *LuetSystemRepository) Sync(ctx *types.Context, force bool) (*LuetSystem
|
|||||||
// e.g. locally we can override the type (disk), or priority
|
// e.g. locally we can override the type (disk), or priority
|
||||||
// while remotely it could be advertized differently
|
// while remotely it could be advertized differently
|
||||||
r.fill(downloadedRepoMeta)
|
r.fill(downloadedRepoMeta)
|
||||||
|
|
||||||
|
if !repoUpdated {
|
||||||
ctx.Info(
|
ctx.Info(
|
||||||
fmt.Sprintf(":information_source: Repository: %s Priority: %d Type: %s",
|
fmt.Sprintf(":information_source: Repository: %s Priority: %d Type: %s",
|
||||||
downloadedRepoMeta.GetName(),
|
downloadedRepoMeta.GetName(),
|
||||||
downloadedRepoMeta.GetPriority(),
|
downloadedRepoMeta.GetPriority(),
|
||||||
downloadedRepoMeta.GetType()))
|
downloadedRepoMeta.GetType()))
|
||||||
|
}
|
||||||
return downloadedRepoMeta, nil
|
return downloadedRepoMeta, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user