Skip to content

Commit 10c88de

Browse files
committed
feat: remove unnecessary cleanup
1 parent cf24fb0 commit 10c88de

File tree

2 files changed

+17
-50
lines changed

2 files changed

+17
-50
lines changed

core/system.go

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
278278
partFuture.Partition.Unmount() // just in case
279279
partBoot.Unmount()
280280

281-
err = partFuture.Partition.Mount("/part-future/")
281+
futureRoot := "/part-future"
282+
err = partFuture.Partition.Mount(futureRoot)
282283
if err != nil {
283284
PrintVerboseErr("ABSystem.RunOperation", 2.3, err)
284285
return err
285286
}
286287

287-
systemNew := filepath.Join(partFuture.Partition.MountPoint)
288-
289288
cq.Add(func(args ...interface{}) error {
290289
return partFuture.Partition.Unmount()
291290
}, nil, 90, &goodies.NoErrorHandler{}, false)
@@ -367,21 +366,12 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
367366
return err
368367
}
369368

370-
if freeSpace || os.Getenv("ABROOT_FREE_SPACE") != "" {
371-
PrintVerboseInfo("ABSystemRunOperation", "Deleting future system to free space, this will render the future root temporarily unavailable")
372-
err := ClearDirectory(partFuture.Partition.MountPoint, nil)
373-
if err != nil {
374-
PrintVerboseErr("ABSystem.RunOperation", 4, err)
375-
return err
376-
}
377-
}
378-
379-
abrootTrans := filepath.Join(partFuture.Partition.MountPoint, "abroot-trans")
369+
abrootTrans := filepath.Join(futureRoot, "abroot-trans")
380370
err = OciExportRootFs(
381371
"abroot-"+uuid.New().String(),
382372
imageRecipe,
383373
abrootTrans,
384-
systemNew,
374+
futureRoot,
385375
)
386376
if err != nil {
387377
PrintVerboseErr("ABSystem.RunOperation", 4.2, err)
@@ -400,7 +390,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
400390
}
401391

402392
// Stage 4.2: Repair root integrity
403-
err = RepairRootIntegrity(systemNew)
393+
err = RepairRootIntegrity(futureRoot)
404394
if err != nil {
405395
PrintVerboseErr("ABSystem.RunOperation", 2.4, err)
406396
return err
@@ -422,7 +412,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
422412
return err
423413
}
424414

425-
err = abimage.WriteTo(systemNew)
415+
err = abimage.WriteTo(futureRoot)
426416
if err != nil {
427417
PrintVerboseErr("ABSystem.RunOperation", 5.2, err)
428418
return err
@@ -440,13 +430,13 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
440430
settings.Cnf.PartCryptVar = device
441431
}
442432

443-
err = settings.WriteConfigToFile(filepath.Join(systemNew, "/usr/share/abroot/abroot.json"))
433+
err = settings.WriteConfigToFile(filepath.Join(futureRoot, "/usr/share/abroot/abroot.json"))
444434
if err != nil {
445435
PrintVerboseErr("ABSystem.RunOperation", 5.25, err)
446436
return err
447437
}
448438

449-
err = pkgM.WriteSummaryToRoot(systemNew)
439+
err = pkgM.WriteSummaryToRoot(futureRoot)
450440
if err != nil {
451441
PrintVerboseErr("ABSystem.RunOperation", 5.26, err)
452442
return err
@@ -477,7 +467,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
477467
PrintVerboseSimple("[Stage 6] -------- ABSystemRunOperation")
478468

479469
chroot, err := NewChroot(
480-
systemNew,
470+
futureRoot,
481471
partFuture.Partition.Uuid,
482472
partFuture.Partition.Device,
483473
true,
@@ -509,7 +499,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
509499
return err
510500
}
511501

512-
newKernelVer := getKernelVersion(filepath.Join(systemNew, "boot"))
502+
newKernelVer := getKernelVersion(filepath.Join(futureRoot, "boot"))
513503
if newKernelVer == "" {
514504
err := errors.New("could not get kernel version")
515505
PrintVerboseErr("ABSystem.RunOperation", 7.26, err)
@@ -527,7 +517,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
527517
return err
528518
}
529519

530-
initMountpoint = filepath.Join(systemNew, "boot", "init")
520+
initMountpoint = filepath.Join(futureRoot, "boot", "init")
531521
err = initPartition.Mount(initMountpoint)
532522
if err != nil {
533523
PrintVerboseErr("ABSystem.RunOperation", 7.4, err)
@@ -550,31 +540,31 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
550540
}
551541

552542
err = MoveFile(
553-
filepath.Join(systemNew, "boot", "vmlinuz-"+newKernelVer),
543+
filepath.Join(futureRoot, "boot", "vmlinuz-"+newKernelVer),
554544
filepath.Join(futureInitDir, "vmlinuz-"+newKernelVer),
555545
)
556546
if err != nil {
557547
PrintVerboseErr("ABSystem.RunOperation", 7.5, err)
558548
return err
559549
}
560550
err = MoveFile(
561-
filepath.Join(systemNew, "boot", "initrd.img-"+newKernelVer),
551+
filepath.Join(futureRoot, "boot", "initrd.img-"+newKernelVer),
562552
filepath.Join(futureInitDir, "initrd.img-"+newKernelVer),
563553
)
564554
if err != nil {
565555
PrintVerboseErr("ABSystem.RunOperation", 7.6, err)
566556
return err
567557
}
568558
err = MoveFile(
569-
filepath.Join(systemNew, "boot", "config-"+newKernelVer),
559+
filepath.Join(futureRoot, "boot", "config-"+newKernelVer),
570560
filepath.Join(futureInitDir, "config-"+newKernelVer),
571561
)
572562
if err != nil {
573563
PrintVerboseErr("ABSystem.RunOperation", 7.7, err)
574564
return err
575565
}
576566
err = MoveFile(
577-
filepath.Join(systemNew, "boot", "System.map-"+newKernelVer),
567+
filepath.Join(futureRoot, "boot", "System.map-"+newKernelVer),
578568
filepath.Join(futureInitDir, "System.map-"+newKernelVer),
579569
)
580570
if err != nil {
@@ -589,7 +579,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
589579

590580
err = generateABGrubConf(
591581
newKernelVer,
592-
systemNew,
582+
futureRoot,
593583
rootUuid,
594584
partFuture.Label,
595585
generatedGrubConfigPath,
@@ -612,7 +602,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
612602
os.MkdirAll(newUpperEtc, 0o755)
613603
os.MkdirAll(newWorkEtc, 0o755)
614604

615-
err = EtcBuilder.ExtBuildCommand(oldEtc, systemNew+"/sysconf", oldUpperEtc, newUpperEtc)
605+
err = EtcBuilder.ExtBuildCommand(oldEtc, futureRoot+"/sysconf", oldUpperEtc, newUpperEtc)
616606
if err != nil {
617607
PrintVerboseErr("AbSystem.RunOperation", 8, err)
618608
return err

core/utils.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"io/fs"
2020
"os"
2121
"os/exec"
22-
"path/filepath"
23-
"slices"
2422
"syscall"
2523
)
2624

@@ -109,27 +107,6 @@ func MoveFile(source, dest string) error {
109107
return nil
110108
}
111109

112-
// ClearDirectory deletes all contents of a directory without removing the directory itself.
113-
// Skips files/directories specified in the skip list.
114-
func ClearDirectory(path string, skipList []string) error {
115-
files, err := os.ReadDir(path)
116-
if err != nil {
117-
return err
118-
}
119-
120-
for _, file := range files {
121-
if slices.Contains(skipList, file.Name()) {
122-
continue
123-
}
124-
err = os.RemoveAll(filepath.Join(path, file.Name()))
125-
if err != nil {
126-
return err
127-
}
128-
}
129-
130-
return nil
131-
}
132-
133110
// isDeviceLUKSEncrypted checks whether a device specified by devicePath is a LUKS-encrypted device
134111
func isDeviceLUKSEncrypted(devicePath string) (bool, error) {
135112
PrintVerboseInfo("isDeviceLUKSEncrypted", "Verifying if", devicePath, "is encrypted")

0 commit comments

Comments
 (0)