Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not try to create file shares for non-directories #11738

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
milas committed Apr 17, 2024
commit 7390df7b11d0de8176e20d933f178a29de11d43c
25 changes: 18 additions & 7 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}
Expand Down
Loading