component: Automatically determine names

This commit is contained in:
Tom Wiesing 2022-10-17 20:39:53 +02:00
parent 10df1c3243
commit e320bb37bb
No known key found for this signature in database
31 changed files with 84 additions and 113 deletions

View file

@ -27,8 +27,6 @@ type Exporter struct {
Backupable []component.Backupable
}
func (Exporter) Name() string { return "snapshots" }
// Path returns the path that contains all snapshot related data.
func (dis *Exporter) Path() string {
return filepath.Join(dis.Config.DeployRoot, "snapshots")
@ -74,7 +72,7 @@ func (*Exporter) newSnapshotName(prefix string) string {
func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) {
for path == "" || environment.IsExist(err) {
path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix))
err = dis.Core.Environment.Mkdir(path, environment.DefaultFilePerm)
err = dis.Still.Environment.Mkdir(path, environment.DefaultFilePerm)
}
if err != nil {
path = ""

View file

@ -12,8 +12,6 @@ type Bookkeeping struct {
component.ComponentBase
}
func (Bookkeeping) Name() string { return "bookkeeping" }
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
func (Bookkeeping) SnapshotNeedsRunning() bool { return false }

View file

@ -11,8 +11,6 @@ type Config struct {
component.ComponentBase
}
func (Config) Name() string { return "config" }
func (*Config) BackupName() string {
return "config"
}

View file

@ -10,8 +10,6 @@ type Filesystem struct {
component.ComponentBase
}
func (Filesystem) Name() string { return "filesystem" }
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
func (Filesystem) SnapshotNeedsRunning() bool { return false }

View file

@ -13,8 +13,6 @@ type Pathbuilders struct {
Instances *instances.Instances
}
func (Pathbuilders) Name() string { return "pathbuilders" }
func (Pathbuilders) SnapshotNeedsRunning() bool { return true }
func (Pathbuilders) SnapshotName() string { return "pathbuilders" }

View file

@ -15,8 +15,6 @@ type Logger struct {
SQL *sql.SQL
}
func (*Logger) Name() string { return "snapshots-log" }
// For retrieves (and prunes) the ExportLog.
// Slug determines if entries for Backups (empty slug)
// or a specific Instance (non-empty slug) are returned.
@ -48,7 +46,7 @@ func (log *Logger) Log() ([]models.Export, error) {
// partition out the exports that have been deleted!
parts := collection.Partition(exports, func(s models.Export) bool {
_, err := log.Core.Environment.Stat(s.Path)
_, err := log.Still.Environment.Stat(s.Path)
return !environment.IsNotExist(err)
})

View file

@ -18,7 +18,7 @@ func (exporter *Exporter) PruneExports(io stream.IOStream) error {
sPath := exporter.ArchivePath()
// list all the files
entries, err := exporter.Core.Environment.ReadDir(sPath)
entries, err := exporter.Still.Environment.ReadDir(sPath)
if err != nil {
return err
}
@ -44,7 +44,7 @@ func (exporter *Exporter) PruneExports(io stream.IOStream) error {
path := filepath.Join(sPath, entry.Name())
io.Printf("Removing %s cause it is older than %d days", path, exporter.Config.MaxBackupAge)
if err := exporter.Core.Environment.Remove(path); err != nil {
if err := exporter.Still.Environment.Remove(path); err != nil {
return err
}
}