Skip to content

Commit

Permalink
fix: do not remove mounted files directory, fixes ddev#6188 (ddev#6199)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay authored May 20, 2024
1 parent 8fa0962 commit 17abdad
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 38 deletions.
8 changes: 4 additions & 4 deletions pkg/ddevapp/backdrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/output"
"github.com/ddev/ddev/pkg/util"
copy2 "github.com/otiai10/copy"
)

// BackdropSettings holds database connection details for Backdrop.
Expand Down Expand Up @@ -179,9 +180,9 @@ func backdropImportFilesAction(app *DdevApp, uploadDir, importPath, extPath stri
return err
}

// If the destination path exists, remove it as was warned
// If the destination path exists, purge it
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -202,8 +203,7 @@ func backdropImportFilesAction(app *DdevApp, uploadDir, importPath, extPath stri
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy2.Copy(importPath, destPath); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/ddevapp/craftcms.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/util"
copy2 "github.com/otiai10/copy"
)

// isCraftCmsApp returns true if the app is of type craftcms
Expand All @@ -31,9 +32,9 @@ func craftCmsImportFilesAction(app *DdevApp, uploadDir, importPath, extPath stri
return err
}

// If the destination path exists, remove it as was warned
// If the destination path exists, purge it as was warned
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -54,8 +55,7 @@ func craftCmsImportFilesAction(app *DdevApp, uploadDir, importPath, extPath stri
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy2.Copy(importPath, destPath); err != nil {
return err
}

Expand Down
11 changes: 5 additions & 6 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2081,8 +2081,8 @@ func (app *DdevApp) DockerEnv() {
"DDEV_COMPOSER_ROOT": app.GetComposerRoot(true, false),
"DDEV_DATABASE_FAMILY": dbFamily,
"DDEV_DATABASE": app.Database.Type + ":" + app.Database.Version,
"DDEV_FILES_DIR": app.getContainerUploadDir(),
"DDEV_FILES_DIRS": strings.Join(app.getContainerUploadDirs(), ","),
"DDEV_FILES_DIR": app.GetContainerUploadDir(),
"DDEV_FILES_DIRS": strings.Join(app.GetContainerUploadDirs(), ","),

"DDEV_HOST_DB_PORT": dbPortStr,
"DDEV_HOST_MAILHOG_PORT": app.HostMailpitPort,
Expand Down Expand Up @@ -2966,9 +2966,9 @@ func genericImportFilesAction(app *DdevApp, uploadDir, importPath, extPath strin
return err
}

// If the destination path exists, remove it as was warned
// If the destination path exists, purge it as was warned
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -2989,8 +2989,7 @@ func genericImportFilesAction(app *DdevApp, uploadDir, importPath, extPath strin
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy.Copy(importPath, destPath); err != nil {
return err
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/ddevapp/ddevapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,9 @@ func TestDdevImportFiles(t *testing.T) {

app.Hooks = map[string][]ddevapp.YAMLTask{"post-import-files": {{"exec-host": "touch hello-post-import-files-" + app.Name}}, "pre-import-files": {{"exec-host": "touch hello-pre-import-files-" + app.Name}}}

err = app.Start()
require.NoError(t, err)

if site.FilesTarballURL != "" && app.GetUploadDir() != "" {
_, tarballPath, err := testcommon.GetCachedArchive(site.Name, "local-tarballs-files", "", site.FilesTarballURL)
assert.NoError(err)
Expand Down Expand Up @@ -2505,6 +2508,12 @@ func TestDdevImportFiles(t *testing.T) {
continue
}
assert.FileExists(filepath.Join(app.GetHostUploadDirFullPath(), ext+".txt"))

// Make sure the imported file also appears inside the container
stdout, stderr, err := app.Exec(&ddevapp.ExecOpts{
Cmd: fmt.Sprintf("file %s", app.GetContainerUploadDir()),
})
require.NoError(t, err, "Expected file not found inside container, err='%v', stdout='%s', stderr='%s'", err, stdout, stderr)
}
assert.FileExists("hello-pre-import-files-" + app.Name)
assert.FileExists("hello-post-import-files-" + app.Name)
Expand Down
10 changes: 6 additions & 4 deletions pkg/ddevapp/drupal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/output"
"github.com/ddev/ddev/pkg/util"
copy2 "github.com/otiai10/copy"
)

// DrupalSettings encapsulates all the configurations for a Drupal site.
Expand Down Expand Up @@ -572,9 +573,11 @@ func drupalImportFilesAction(app *DdevApp, uploadDir, importPath, extPath string
return err
}

// If the destination path exists, remove it as was warned
// If the destination path exists, remove contents as was warned
// We do not remove the directory as it may be a docker bind-mount in
// various situations, especially when mutagen is in use.
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -595,8 +598,7 @@ func drupalImportFilesAction(app *DdevApp, uploadDir, importPath, extPath string
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy2.Copy(importPath, destPath); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/ddevapp/magento.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/output"
"github.com/ddev/ddev/pkg/util"
copy2 "github.com/otiai10/copy"
)

// isMagentoApp returns true if the app is of type magento
Expand Down Expand Up @@ -83,7 +84,7 @@ func magentoImportFilesAction(app *DdevApp, uploadDir, importPath, extPath strin

// If the destination path exists, remove it as was warned
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -104,8 +105,7 @@ func magentoImportFilesAction(app *DdevApp, uploadDir, importPath, extPath strin
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy2.Copy(importPath, destPath); err != nil {
return err
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/ddevapp/shopware6.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package ddevapp
import (
"errors"
"fmt"
"github.com/ddev/ddev/pkg/util"
"os"
"path/filepath"

"github.com/ddev/ddev/pkg/util"

"github.com/ddev/ddev/pkg/archive"
"github.com/ddev/ddev/pkg/fileutil"
copy2 "github.com/otiai10/copy"
)

// isShopware6App returns true if the app is of type shopware6
Expand Down Expand Up @@ -39,9 +41,9 @@ func shopware6ImportFilesAction(app *DdevApp, uploadDir, importPath, extPath str
return err
}

// If the destination path exists, remove it as was warned
// If the destination path exists, purge it as was warned
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -62,8 +64,7 @@ func shopware6ImportFilesAction(app *DdevApp, uploadDir, importPath, extPath str
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy2.Copy(importPath, destPath); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/ddevapp/typo3.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/output"
"github.com/ddev/ddev/pkg/util"
copy2 "github.com/otiai10/copy"
)

// createTypo3SettingsFile creates the app's settings.php and
Expand Down Expand Up @@ -180,9 +181,9 @@ func typo3ImportFilesAction(app *DdevApp, uploadDir, importPath, extPath string)
return err
}

// If the destination path exists, remove it as was warned
// If the destination path exists, purge it as was warned
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -203,8 +204,7 @@ func typo3ImportFilesAction(app *DdevApp, uploadDir, importPath, extPath string)
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy2.Copy(importPath, destPath); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/ddevapp/upload_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func (app *DdevApp) calculateContainerUploadDirFullPath(uploadDir string) string
return ""
}

// getContainerUploadDir returns the full path to the first upload
// GetContainerUploadDir returns the full path to the first upload
// directory in container or "" if there is none.
func (app *DdevApp) getContainerUploadDir() string {
func (app *DdevApp) GetContainerUploadDir() string {
uploadDirs := app.GetUploadDirs()
if len(uploadDirs) > 0 {
return app.calculateContainerUploadDirFullPath(uploadDirs[0])
Expand All @@ -115,9 +115,9 @@ func (app *DdevApp) getContainerUploadDir() string {
return ""
}

// getContainerUploadDirs returns a slice of the full path to the upload
// GetContainerUploadDirs returns a slice of the full path to the upload
// directories in container.
func (app *DdevApp) getContainerUploadDirs() []string {
func (app *DdevApp) GetContainerUploadDirs() []string {
uploadDirs := app.GetUploadDirs()
containerUploadDirs := make([]string, 0, len(uploadDirs))

Expand Down
8 changes: 4 additions & 4 deletions pkg/ddevapp/wordpress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/util"
copy2 "github.com/otiai10/copy"
)

// WordpressConfig encapsulates all the configurations for a WordPress site.
Expand Down Expand Up @@ -274,9 +275,9 @@ func wordpressImportFilesAction(app *DdevApp, target, importPath, extPath string
return err
}

// If the destination path exists, remove it as was warned
// If the destination path exists, purge it as was warned
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
if err := fileutil.PurgeDirectory(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
Expand All @@ -297,8 +298,7 @@ func wordpressImportFilesAction(app *DdevApp, target, importPath, extPath string
return nil
}

//nolint: revive
if err := fileutil.CopyDir(importPath, destPath); err != nil {
if err := copy2.Copy(importPath, destPath); err != nil {
return err
}

Expand Down

0 comments on commit 17abdad

Please sign in to comment.