fix: ensure we migrate data for all golang plugins

This commit is contained in:
Jose Diaz-Gonzalez
2023-01-28 15:50:31 -05:00
parent a8283824a5
commit af84293c3e
4 changed files with 14 additions and 5 deletions

View File

@@ -139,7 +139,7 @@ func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
// TriggerPostAppRename removes the old app data
func TriggerPostAppRename(oldAppName string, newAppName string) error {
return common.RemoveAppDataDirectory("app-json", oldAppName)
return common.MigrateAppDataDirectory("app-json", oldAppName, newAppName)
}
// TriggerPostAppRenameSetup renames app-json files
@@ -162,7 +162,7 @@ func TriggerPostCreate(appName string) error {
// TriggerPostDelete destroys the app-json data for a given app container
func TriggerPostDelete(appName string) error {
dataErr := os.RemoveAll(common.GetAppDataDirectory("app-json", appName))
dataErr := common.RemoveAppDataDirectory("app-json", appName)
propertyErr := common.PropertyDestroy("app-json", appName)
if dataErr != nil {

View File

@@ -46,6 +46,15 @@ func GetDataDirectory(pluginName string) string {
return filepath.Join(MustGetEnv("DOKKU_LIB_ROOT"), "data", pluginName)
}
// MigrateAppDataDirectory migrates the data directory for one app to another
func MigrateAppDataDirectory(pluginName string, oldAppName string, newAppName string) error {
if err := CloneAppData(pluginName, oldAppName, newAppName); err != nil {
return err
}
return RemoveAppDataDirectory(pluginName, oldAppName)
}
// RemoveAppDataDirectory removes the path to the data directory for the given plugin/app combination
func RemoveAppDataDirectory(pluginName, appName string) error {
return os.RemoveAll(GetAppDataDirectory(pluginName, appName))

View File

@@ -118,7 +118,7 @@ func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
// TriggerPostAppRename removes the old app data
func TriggerPostAppRename(oldAppName string, newAppName string) error {
return common.RemoveAppDataDirectory("logs", oldAppName)
return common.MigrateAppDataDirectory("logs", oldAppName, newAppName)
}
// TriggerPostAppRenameSetup renames logs files
@@ -141,7 +141,7 @@ func TriggerPostCreate(appName string) error {
// TriggerPostDelete destroys the logs property for a given app container
func TriggerPostDelete(appName string) error {
dataErr := os.RemoveAll(common.GetAppDataDirectory("logs", appName))
dataErr := common.RemoveAppDataDirectory("logs", appName)
propertyErr := common.PropertyDestroy("logs", appName)
if dataErr != nil {

View File

@@ -182,7 +182,7 @@ func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
// TriggerPostAppRename rebuilds the renamed app
func TriggerPostAppRename(oldAppName string, newAppName string) error {
if err := common.RemoveAppDataDirectory("ps", oldAppName); err != nil {
if err := common.MigrateAppDataDirectory("ps", oldAppName, newAppName); err != nil {
return err
}