Skip to content

Commit 66fe5bf

Browse files
committed
adds flag to free up space if necessary
1 parent 72a3a59 commit 66fe5bf

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

cmd/kargs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func kargs(cmd *cobra.Command, args []string) error {
6363
cmdr.Error.Println(err)
6464
return err
6565
}
66-
err = aBsys.RunOperation(core.APPLY)
66+
err = aBsys.RunOperation(core.APPLY, false)
6767
if err != nil {
6868
cmdr.Error.Println(abroot.Trans("pkg.applyFailed"))
6969
return err

cmd/pkg.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ func NewPkgCommand() *cmdr.Command {
4949
abroot.Trans("pkg.forceEnableUserAgreementFlag"),
5050
false))
5151

52+
cmd.WithBoolFlag(
53+
cmdr.NewBoolFlag(
54+
"delete-old-system",
55+
"",
56+
abroot.Trans("upgrade.deleteOld"),
57+
false))
58+
5259
cmd.Args = cobra.MinimumNArgs(1)
5360
cmd.ValidArgs = validPkgArgs
5461
cmd.Example = "abroot pkg add <pkg>"
@@ -68,6 +75,12 @@ func pkg(cmd *cobra.Command, args []string) error {
6875
return err
6976
}
7077

78+
freeSpace, err := cmd.Flags().GetBool("delete-old-system")
79+
if err != nil {
80+
cmdr.Error.Println(err)
81+
return err
82+
}
83+
7184
forceEnableUserAgreement, err := cmd.Flags().GetBool("force-enable-user-agreement")
7285
if err != nil {
7386
cmdr.Error.Println(err)
@@ -173,9 +186,9 @@ func pkg(cmd *cobra.Command, args []string) error {
173186
}
174187

175188
if dryRun {
176-
err = aBsys.RunOperation(core.DRY_RUN_APPLY)
189+
err = aBsys.RunOperation(core.DRY_RUN_APPLY, freeSpace)
177190
} else {
178-
err = aBsys.RunOperation(core.APPLY)
191+
err = aBsys.RunOperation(core.APPLY, freeSpace)
179192
}
180193
if err != nil {
181194
cmdr.Error.Printf(abroot.Trans("pkg.applyFailed"), err)

cmd/update-initramfs.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ func NewUpdateInitfsCommand() *cmdr.Command {
3535
abroot.Trans("updateInitramfs.dryRunFlag"),
3636
false))
3737

38+
cmd.WithBoolFlag(
39+
cmdr.NewBoolFlag(
40+
"delete-old-system",
41+
"",
42+
abroot.Trans("upgrade.deleteOld"),
43+
false))
44+
3845
cmd.Example = "abroot update-initramfs"
3946

4047
return cmd
@@ -52,16 +59,22 @@ func updateInitramfs(cmd *cobra.Command, args []string) error {
5259
return err
5360
}
5461

62+
freeSpace, err := cmd.Flags().GetBool("delete-old-system")
63+
if err != nil {
64+
cmdr.Error.Println(err)
65+
return err
66+
}
67+
5568
aBsys, err := core.NewABSystem()
5669
if err != nil {
5770
cmdr.Error.Println(err)
5871
return err
5972
}
6073

6174
if dryRun {
62-
err = aBsys.RunOperation(core.DRY_RUN_INITRAMFS)
75+
err = aBsys.RunOperation(core.DRY_RUN_INITRAMFS, freeSpace)
6376
} else {
64-
err = aBsys.RunOperation(core.INITRAMFS)
77+
err = aBsys.RunOperation(core.INITRAMFS, freeSpace)
6578
}
6679
if err != nil {
6780
cmdr.Error.Printf(abroot.Trans("updateInitramfs.updateFailed"), err)

cmd/upgrade.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func NewUpgradeCommand() *cmdr.Command {
5555
abroot.Trans("upgrade.forceFlag"),
5656
false))
5757

58+
cmd.WithBoolFlag(
59+
cmdr.NewBoolFlag(
60+
"delete-old-system",
61+
"",
62+
abroot.Trans("upgrade.deleteOld"),
63+
false))
64+
5865
cmd.Example = "abroot upgrade"
5966

6067
return cmd
@@ -73,6 +80,12 @@ func upgrade(cmd *cobra.Command, args []string) error {
7380
return err
7481
}
7582

83+
freeSpace, err := cmd.Flags().GetBool("delete-old-system")
84+
if err != nil {
85+
cmdr.Error.Println(err)
86+
return err
87+
}
88+
7689
aBsys, err := core.NewABSystem()
7790
if err != nil {
7891
cmdr.Error.Println(err)
@@ -185,7 +198,7 @@ func upgrade(cmd *cobra.Command, args []string) error {
185198
}
186199

187200
cmdr.Info.Println(abroot.Trans("upgrade.checkingSystemUpdate"))
188-
err = aBsys.RunOperation(operation)
201+
err = aBsys.RunOperation(operation, freeSpace)
189202
if err != nil {
190203
if err == core.ErrNoUpdate {
191204
cmdr.Info.Println(abroot.Trans("upgrade.noUpdateAvailable"))

core/system.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (s *ABSystem) CreateRootSymlinks(systemNewPath string) error {
170170
// Applies package changes, but doesn't update the system.
171171
// INITRAMFS:
172172
// Updates the initramfs for the future root, but doesn't update the system.
173-
func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
173+
func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) error {
174174
PrintVerboseInfo("ABSystem.RunOperation", "starting", operation)
175175

176176
cq := goodies.NewCleanupQueue()
@@ -374,8 +374,8 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
374374
abrootTrans := filepath.Join(partFuture.Partition.MountPoint, "abroot-trans")
375375
systemOld := filepath.Join(partFuture.Partition.MountPoint, ".system")
376376
systemNew := filepath.Join(partFuture.Partition.MountPoint, ".system.new")
377-
if os.Getenv("ABROOT_FREE_SPACE") != "" {
378-
PrintVerboseInfo("ABSystemRunOperation", "ABROOT_FREE_SPACE is set, deleting future system to free space, this is potentially harmful, assuming we are in a test environment")
377+
if freeSpace || os.Getenv("ABROOT_FREE_SPACE") != "" {
378+
PrintVerboseInfo("ABSystemRunOperation", "Deleting future system to free space, this will render the future root temporarily unavailable")
379379
err := os.RemoveAll(systemOld)
380380
if err != nil {
381381
PrintVerboseErr("ABSystemRunOperation", 4, err)

locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ upgrade:
106106
long: "Check for a new system image and apply it."
107107
short: "Upgrade the system"
108108
forceFlag: "force update even if the system is up to date"
109+
deleteOld: "Delete old image to free up space, will make future root temporarily unusable."
109110
rootRequired: "You must be root to run this command."
110111
checkingSystemUpdate: "Checking for system updates..."
111112
checkingPackageUpdate: "Checking for package updates..."

0 commit comments

Comments
 (0)