Refactor components
This commit is contained in:
parent
17011a277f
commit
487ce09979
7 changed files with 117 additions and 63 deletions
12
env/snapshot.go
vendored
12
env/snapshot.go
vendored
|
|
@ -16,25 +16,25 @@ import (
|
|||
)
|
||||
|
||||
// SnapshotsDir returns the path that contains all snapshot related data.
|
||||
func (dis Distillery) SnapshotsDir() string {
|
||||
func (dis *Distillery) SnapshotsDir() string {
|
||||
return filepath.Join(dis.Config.DeployRoot, "snapshots")
|
||||
}
|
||||
|
||||
// SnapshotsStagingPath returns the path to the directory containing a temporary staging area for snapshots.
|
||||
// Use NewSnapshotStagingDir to generate a new staging area.
|
||||
func (dis Distillery) SnapshotsStagingPath() string {
|
||||
func (dis *Distillery) SnapshotsStagingPath() string {
|
||||
return filepath.Join(dis.SnapshotsDir(), "staging")
|
||||
}
|
||||
|
||||
// SnapshotsArchivePath returns the path to the directory containing all exported archives.
|
||||
// Use NewSnapshotArchivePath to generate a path to a new archive in this directory.
|
||||
func (dis Distillery) SnapshotsArchivePath() string {
|
||||
func (dis *Distillery) SnapshotsArchivePath() string {
|
||||
return filepath.Join(dis.SnapshotsDir(), "archives")
|
||||
}
|
||||
|
||||
// NewSnapshotArchivePath returns the path to a new archive with the provided prefix.
|
||||
// The path is guaranteed to not exist.
|
||||
func (dis Distillery) NewSnapshotArchivePath(prefix string) (path string) {
|
||||
func (dis *Distillery) NewSnapshotArchivePath(prefix string) (path string) {
|
||||
// TODO: Consider moving these into a subdirectory with the provided prefix.
|
||||
for path == "" || fsx.Exists(path) {
|
||||
name := dis.newSnapshotName(prefix) + ".tar.gz"
|
||||
|
|
@ -45,7 +45,7 @@ func (dis Distillery) NewSnapshotArchivePath(prefix string) (path string) {
|
|||
|
||||
// newSnapshot name returns a new basename for a snapshot with the provided prefix.
|
||||
// The name is guaranteed to be unique within this process.
|
||||
func (Distillery) newSnapshotName(prefix string) string {
|
||||
func (*Distillery) newSnapshotName(prefix string) string {
|
||||
suffix, _ := password.Password(64) // silently ignore any errors!
|
||||
if prefix == "" {
|
||||
prefix = "backup"
|
||||
|
|
@ -57,7 +57,7 @@ func (Distillery) newSnapshotName(prefix string) string {
|
|||
|
||||
// NewSnapshotStagingDir returns the path to a new snapshot directory.
|
||||
// The directory is guaranteed to have been freshly created.
|
||||
func (dis Distillery) NewSnapshotStagingDir(prefix string) (path string, err error) {
|
||||
func (dis *Distillery) NewSnapshotStagingDir(prefix string) (path string, err error) {
|
||||
for path == "" || os.IsExist(err) {
|
||||
path = filepath.Join(dis.SnapshotsStagingPath(), dis.newSnapshotName(prefix))
|
||||
err = os.Mkdir(path, os.ModeDir)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue