Require access to Still via method

This commit adds a safeguard to accessing the still from a specific
component by requiring access via the component.GetStill method.
This commit is contained in:
Tom Wiesing 2024-04-08 22:39:32 +02:00
parent 81fa84c244
commit 8235ea9105
No known key found for this signature in database
63 changed files with 288 additions and 197 deletions

View file

@ -33,7 +33,7 @@ type Exporter struct {
// Path returns the path that contains all snapshot related data.
func (dis *Exporter) Path() string {
return filepath.Join(dis.Config.Paths.Root, "snapshots")
return filepath.Join(component.GetStill(dis).Config.Paths.Root, "snapshots")
}
// StagingPath returns the path to the directory containing a temporary staging area for snapshots.

View file

@ -36,10 +36,11 @@ func (control *Config) Backup(scontext *component.StagingContext) error {
// backupfiles lists the files to be backed up.
func (control *Config) backupFiles() []string {
config := component.GetStill(control).Config
return []string{
control.Config.ConfigPath,
control.Config.Paths.ExecutablePath(),
control.Config.Paths.OverridesJSON,
control.Config.Paths.ResolverBlocks,
config.ConfigPath,
config.Paths.ExecutablePath(),
config.Paths.OverridesJSON,
config.Paths.ResolverBlocks,
}
}

View file

@ -7,12 +7,14 @@ import (
"os"
"path/filepath"
"time"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
)
// ShouldPrune determines if a file with the provided modification time should be
// removed from the export log.
func (exporter *Exporter) ShouldPrune(modtime time.Time) bool {
return time.Since(modtime) > exporter.Config.MaxBackupAge
return time.Since(modtime) > component.GetStill(exporter).Config.MaxBackupAge
}
// Prune prunes all old exports
@ -44,7 +46,7 @@ func (exporter *Exporter) PruneExports(ctx context.Context, progress io.Writer)
// assemble path, and then remove the file!
path := filepath.Join(sPath, entry.Name())
fmt.Fprintf(progress, "Removing %s cause it is older than %d days\n", path, exporter.Config.MaxBackupAge)
fmt.Fprintf(progress, "Removing %s cause it is older than %d days\n", path, component.GetStill(exporter).Config.MaxBackupAge)
if err := os.Remove(path); err != nil {
return err