From 42f5210764e1783e397404a49bafb79850380b2e Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 7 Mar 2021 11:39:19 +0100 Subject: [PATCH] Add DownloadOnly option It allows to download only the packages, without installing/upgrading/replacing them Fixes #179 --- cmd/install.go | 3 + cmd/replace.go | 3 + cmd/upgrade.go | 3 + pkg/installer/installer.go | 8 +++ tests/integration/01_simple_downloadonly.sh | 80 +++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100755 tests/integration/01_simple_downloadonly.sh diff --git a/cmd/install.go b/cmd/install.go index 74fa7f95..9d8500d7 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -89,6 +89,7 @@ To force install a package: onlydeps := LuetCfg.Viper.GetBool("onlydeps") concurrent, _ := cmd.Flags().GetBool("solver-concurrent") yes := LuetCfg.Viper.GetBool("yes") + downloadOnly, _ := cmd.Flags().GetBool("download-only") dbpath := LuetCfg.Viper.GetString("system.database_path") rootfs := LuetCfg.Viper.GetString("system.rootfs") @@ -121,6 +122,7 @@ To force install a package: Force: force, OnlyDeps: onlydeps, PreserveSystemEssentialData: true, + DownloadOnly: downloadOnly, Ask: !yes, }) inst.Repositories(repos) @@ -147,6 +149,7 @@ func init() { installCmd.Flags().Bool("force", false, "Skip errors and keep going (potentially harmful)") installCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)") installCmd.Flags().BoolP("yes", "y", false, "Don't ask questions") + installCmd.Flags().Bool("download-only", false, "Download only") RootCmd.AddCommand(installCmd) } diff --git a/cmd/replace.go b/cmd/replace.go index 19f0afe4..ffaa44f4 100644 --- a/cmd/replace.go +++ b/cmd/replace.go @@ -66,6 +66,7 @@ var replaceCmd = &cobra.Command{ dbpath := LuetCfg.Viper.GetString("system.database_path") rootfs := LuetCfg.Viper.GetString("system.rootfs") engine := LuetCfg.Viper.GetString("system.database_engine") + downloadOnly, _ := cmd.Flags().GetBool("download-only") LuetCfg.System.DatabaseEngine = engine LuetCfg.System.DatabasePath = dbpath @@ -121,6 +122,7 @@ var replaceCmd = &cobra.Command{ OnlyDeps: onlydeps, PreserveSystemEssentialData: true, Ask: !yes, + DownloadOnly: downloadOnly, }) inst.Repositories(repos) @@ -148,6 +150,7 @@ func init() { replaceCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)") replaceCmd.Flags().BoolP("yes", "y", false, "Don't ask questions") replaceCmd.Flags().StringSlice("for", []string{}, "Packages that has to be installed in place of others") + replaceCmd.Flags().Bool("download-only", false, "Download only") RootCmd.AddCommand(replaceCmd) } diff --git a/cmd/upgrade.go b/cmd/upgrade.go index d0fe9b01..e8540fe4 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -66,6 +66,7 @@ var upgradeCmd = &cobra.Command{ dbpath := LuetCfg.Viper.GetString("system.database_path") rootfs := LuetCfg.Viper.GetString("system.rootfs") engine := LuetCfg.Viper.GetString("system.database_engine") + downloadOnly, _ := cmd.Flags().GetBool("download-only") LuetCfg.System.DatabaseEngine = engine LuetCfg.System.DatabasePath = dbpath @@ -96,6 +97,7 @@ var upgradeCmd = &cobra.Command{ UpgradeNewRevisions: sync, PreserveSystemEssentialData: true, Ask: !yes, + DownloadOnly: downloadOnly, }) inst.Repositories(repos) @@ -123,6 +125,7 @@ func init() { upgradeCmd.Flags().Bool("sync", false, "Upgrade packages with new revisions (experimental)") upgradeCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)") upgradeCmd.Flags().BoolP("yes", "y", false, "Don't ask questions") + upgradeCmd.Flags().Bool("download-only", false, "Download only") RootCmd.AddCommand(upgradeCmd) } diff --git a/pkg/installer/installer.go b/pkg/installer/installer.go index a485104e..48b25f14 100644 --- a/pkg/installer/installer.go +++ b/pkg/installer/installer.go @@ -47,6 +47,7 @@ type LuetInstallerOptions struct { CheckConflicts bool SolverUpgrade, RemoveUnavailableOnUpgrade, UpgradeNewRevisions bool Ask bool + DownloadOnly bool } type LuetInstaller struct { @@ -304,6 +305,9 @@ func (l *LuetInstaller) swap(syncedRepos Repositories, toRemove pkg.Packages, to if err := l.download(syncedRepos, match); err != nil { return errors.Wrap(err, "Pre-downloading packages") } + if l.Options.DownloadOnly { + return nil + } err = l.Uninstall(s, toRemove...) if err != nil && !l.Options.Force { @@ -530,6 +534,10 @@ func (l *LuetInstaller) install(syncedRepos Repositories, toInstall map[string]A return errors.Wrap(err, "Downloading packages") } + if l.Options.DownloadOnly { + return nil + } + all := make(chan ArtifactMatch) wg := new(sync.WaitGroup) diff --git a/tests/integration/01_simple_downloadonly.sh b/tests/integration/01_simple_downloadonly.sh new file mode 100755 index 00000000..b4eb11a5 --- /dev/null +++ b/tests/integration/01_simple_downloadonly.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +export LUET_NOLOCK=true + +oneTimeSetUp() { +export tmpdir="$(mktemp -d)" +} + +oneTimeTearDown() { + rm -rf "$tmpdir" +} + +testBuild() { + mkdir $tmpdir/testbuild + luet build --tree "$ROOT_DIR/tests/fixtures/buildableseed" --destination $tmpdir/testbuild --compression gzip test/c > /dev/null + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package dep B' "[ -e '$tmpdir/testbuild/b-test-1.0.package.tar.gz' ]" + assertTrue 'create package' "[ -e '$tmpdir/testbuild/c-test-1.0.package.tar.gz' ]" +} + +testRepo() { + assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]" + luet create-repo --tree "$ROOT_DIR/tests/fixtures/buildableseed" \ + --output $tmpdir/testbuild \ + --packages $tmpdir/testbuild \ + --name "test" \ + --descr "Test Repo" \ + --urls $tmpdir/testrootfs \ + --type disk > /dev/null + + createst=$? + assertEquals 'create repo successfully' "$createst" "0" + assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]" +} + +testConfig() { + mkdir $tmpdir/testrootfs + cat < $tmpdir/luet.yaml +general: + debug: true +system: + rootfs: $tmpdir/testrootfs + database_engine: "memory" +config_from_host: true +repositories: + - name: "main" + type: "disk" + enable: true + urls: + - "$tmpdir/testbuild" +EOF + luet config --config $tmpdir/luet.yaml + res=$? + assertEquals 'config test successfully' "$res" "0" +} + +testDownloadOnly() { + luet install -y --download-only --config $tmpdir/luet.yaml test/c > /dev/null + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package not installed' "[ ! -e '$tmpdir/testrootfs/c' ]" + assertTrue 'cache populated' "[ -e '$tmpdir/testrootfs/var/cache/luet/packages/c-test-1.0.package.tar.gz' ]" + + luet install -y --config $tmpdir/luet.yaml test/c > /dev/null + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package installed' "[ -e '$tmpdir/testrootfs/c' ]" +} + +testCleanup() { + luet cleanup --config $tmpdir/luet.yaml > /dev/null + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package installed' "[ ! -e '$tmpdir/testrootfs/packages/c-test-1.0.package.tar.gz' ]" +} + +# Load shUnit2. +. "$ROOT_DIR/tests/integration/shunit2"/shunit2 +