mirror of
https://github.com/mudler/luet.git
synced 2025-06-29 08:46:51 +00:00
parent
9cb6e65bb6
commit
9aa3159787
10
pkg/helpers/slice.go
Normal file
10
pkg/helpers/slice.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package helpers
|
||||||
|
|
||||||
|
func Contains(s []string, e string) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if a == e {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/mudler/luet/pkg/bus"
|
"github.com/mudler/luet/pkg/bus"
|
||||||
artifact "github.com/mudler/luet/pkg/compiler/types/artifact"
|
artifact "github.com/mudler/luet/pkg/compiler/types/artifact"
|
||||||
"github.com/mudler/luet/pkg/config"
|
"github.com/mudler/luet/pkg/config"
|
||||||
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
||||||
"github.com/mudler/luet/pkg/helpers/match"
|
"github.com/mudler/luet/pkg/helpers/match"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
@ -755,12 +756,61 @@ func (l *LuetInstaller) getFinalizers(allRepos pkg.PackageDatabase, solution sol
|
|||||||
return toFinalize, nil
|
return toFinalize, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LuetInstaller) checkFileconflicts(toInstall map[string]ArtifactMatch, s *System) error {
|
||||||
|
Info("Checking for file conflicts..")
|
||||||
|
filesToInstall := []string{}
|
||||||
|
for _, m := range toInstall {
|
||||||
|
a, err := l.downloadPackage(m)
|
||||||
|
if err != nil && !l.Options.Force {
|
||||||
|
return errors.Wrap(err, "Failed downloading package")
|
||||||
|
}
|
||||||
|
files, err := a.FileList()
|
||||||
|
if err != nil && !l.Options.Force {
|
||||||
|
return errors.Wrapf(err, "Could not get filelist for %s", a.CompileSpec.Package.HumanReadableString())
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
if helpers.Contains(filesToInstall, f) {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"file conflict between packages to be installed",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, p, err := s.ExistsPackageFile(f)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed checking into system db")
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"file conflict between '%s' and '%s' ( file: %s )",
|
||||||
|
p.HumanReadableString(),
|
||||||
|
m.Package.HumanReadableString(),
|
||||||
|
f,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filesToInstall = append(filesToInstall, files...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (l *LuetInstaller) install(o Option, syncedRepos Repositories, toInstall map[string]ArtifactMatch, p pkg.Packages, solution solver.PackagesAssertions, allRepos pkg.PackageDatabase, s *System) error {
|
func (l *LuetInstaller) install(o Option, syncedRepos Repositories, toInstall map[string]ArtifactMatch, p pkg.Packages, solution solver.PackagesAssertions, allRepos pkg.PackageDatabase, s *System) error {
|
||||||
// Install packages into rootfs in parallel.
|
|
||||||
|
// Download packages in parallel first
|
||||||
if err := l.download(syncedRepos, toInstall); err != nil {
|
if err := l.download(syncedRepos, toInstall); err != nil {
|
||||||
return errors.Wrap(err, "Downloading packages")
|
return errors.Wrap(err, "Downloading packages")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check file conflicts
|
||||||
|
if err := l.checkFileconflicts(toInstall, s); err != nil {
|
||||||
|
if !l.Options.Force {
|
||||||
|
return errors.Wrap(err, "file conflict found")
|
||||||
|
} else {
|
||||||
|
Warning("file conflict found", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if l.Options.DownloadOnly {
|
if l.Options.DownloadOnly {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -52,3 +52,18 @@ func (s *System) ExecuteFinalizers(packs []pkg.Package) error {
|
|||||||
}
|
}
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *System) ExistsPackageFile(file string) (bool, pkg.Package, error) {
|
||||||
|
for _, p := range s.Database.World() {
|
||||||
|
files, err := s.Database.GetPackageFiles(p)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, err
|
||||||
|
}
|
||||||
|
for _, f := range files {
|
||||||
|
if f == file {
|
||||||
|
return true, p, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user