Skip to content

Commit 922422a

Browse files
milasndeloof
authored andcommitted
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]>
1 parent d239f0f commit 922422a

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

pkg/compose/create.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,25 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type
167167
if !filepath.IsAbs(p) {
168168
return fmt.Errorf("file share path is not absolute: %s", p)
169169
}
170-
if _, err := os.Stat(p); errors.Is(err, fs.ErrNotExist) {
170+
if fi, err := os.Stat(p); errors.Is(err, fs.ErrNotExist) {
171+
// actual directory will be implicitly created when the
172+
// file share is initialized if it doesn't exist, so
173+
// need to filter out any that should not be auto-created
171174
if vol.Bind != nil && !vol.Bind.CreateHostPath {
172-
return fmt.Errorf("service %s: host path %q does not exist and `create_host_path` is false", svcName, vol.Source)
173-
}
174-
if err := os.MkdirAll(p, 0o755); err != nil {
175-
return fmt.Errorf("creating host path: %w", err)
175+
logrus.Debugf("Skipping creating file share for %q: does not exist and `create_host_path` is false", p)
176+
continue
176177
}
178+
} else if err != nil {
179+
// if we can't read the path, we won't be able ot make
180+
// a file share for it
181+
logrus.Debugf("Skipping creating file share for %q: %v", p, err)
182+
continue
183+
} else if !fi.IsDir() {
184+
// ignore files & special types (e.g. Unix sockets)
185+
logrus.Debugf("Skipping creating file share for %q: not a directory", p)
186+
continue
177187
}
188+
178189
paths = append(paths, p)
179190
}
180191
}
@@ -185,14 +196,14 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type
185196

186197
fileShareManager := desktop.NewFileShareManager(s.desktopCli, project.Name, paths)
187198
if err := fileShareManager.EnsureExists(ctx); err != nil {
188-
return fmt.Errorf("initializing: %w", err)
199+
return fmt.Errorf("initializing file shares: %w", err)
189200
}
190201
}
191202
return nil
192203
}()
193204

194205
if err != nil {
195-
progress.ContextWriter(ctx).TailMsgf("Failed to prepare Synchronized File Shares: %v", err)
206+
progress.ContextWriter(ctx).TailMsgf("Failed to prepare Synchronized file shares: %v", err)
196207
}
197208
return nil
198209
}

0 commit comments

Comments
 (0)