From 922422a53922e21e4e3e5717b81066a74d065dc1 Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Tue, 16 Apr 2024 16:57:34 -0400 Subject: [PATCH] fix: do not try to create file shares for non-directories When creating automatic file shares, ignore any non-directory bind mounts, e.g. for an individual (normal) file or a special type like a Unix socket (`/var/run/docker.sock`). Additionally, there's no need to create a directory if one does not exist, the API will handle that. However, the check for existence remains so that `create_host_path: false` mounts can be ignored. Signed-off-by: Milas Bowman --- pkg/compose/create.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pkg/compose/create.go b/pkg/compose/create.go index b815cb66..a5aa9f9e 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -167,14 +167,25 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type if !filepath.IsAbs(p) { return fmt.Errorf("file share path is not absolute: %s", p) } - if _, err := os.Stat(p); errors.Is(err, fs.ErrNotExist) { + if fi, err := os.Stat(p); errors.Is(err, fs.ErrNotExist) { + // actual directory will be implicitly created when the + // file share is initialized if it doesn't exist, so + // need to filter out any that should not be auto-created if vol.Bind != nil && !vol.Bind.CreateHostPath { - return fmt.Errorf("service %s: host path %q does not exist and `create_host_path` is false", svcName, vol.Source) - } - if err := os.MkdirAll(p, 0o755); err != nil { - return fmt.Errorf("creating host path: %w", err) + logrus.Debugf("Skipping creating file share for %q: does not exist and `create_host_path` is false", p) + continue } + } else if err != nil { + // if we can't read the path, we won't be able ot make + // a file share for it + logrus.Debugf("Skipping creating file share for %q: %v", p, err) + continue + } else if !fi.IsDir() { + // ignore files & special types (e.g. Unix sockets) + logrus.Debugf("Skipping creating file share for %q: not a directory", p) + continue } + paths = append(paths, p) } } @@ -185,14 +196,14 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type fileShareManager := desktop.NewFileShareManager(s.desktopCli, project.Name, paths) if err := fileShareManager.EnsureExists(ctx); err != nil { - return fmt.Errorf("initializing: %w", err) + return fmt.Errorf("initializing file shares: %w", err) } } return nil }() if err != nil { - progress.ContextWriter(ctx).TailMsgf("Failed to prepare Synchronized File Shares: %v", err) + progress.ContextWriter(ctx).TailMsgf("Failed to prepare Synchronized file shares: %v", err) } return nil }