Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions internal/cli/compose_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ func (r *upRunner) buildAndExtendCompose(ctx context.Context, s composeStart, pe
if opts.omitSyntaxDirective {
syntax = ""
}
dstFolder = filepath.Join(cacheFolder(), "container-features", fmt.Sprintf("%s-%d", cliVersion(), time.Now().UnixMilli()))
if err := os.MkdirAll(dstFolder, 0o755); err != nil {
return nil, fmt.Errorf("create features folder: %w", err)
var err error
if dstFolder, err = createFeaturesFolder(); err != nil {
return nil, err
}
info = imagemeta.GenerateComposeLabelBuild(baseName, labelMetadata, syntax)
default:
Expand Down
19 changes: 16 additions & 3 deletions internal/cli/feature_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,25 @@ func (r localFeatureRoots) resolve(logger log.Logger, id string) (string, bool,

// createFeaturesFolder creates the folder the Features are staged in, TS
// createFeaturesTempFolder: <cacheFolder>/container-features/<cliVersion>-<ms>.
// The folder is this run's alone: runs started in the same millisecond would
// otherwise share it, and one run's realignFeatureDirs renames and removes the
// other's .stage- folders. A name another run holds moves to the next
// millisecond.
func createFeaturesFolder() (string, error) {
dir := filepath.Join(cacheFolder(), "container-features", fmt.Sprintf("%s-%d", cliVersion(), time.Now().UnixMilli()))
if err := os.MkdirAll(dir, 0o755); err != nil {
parent := filepath.Join(cacheFolder(), "container-features")
if err := os.MkdirAll(parent, 0o755); err != nil {
return "", fmt.Errorf("create features folder: %w", err)
}
return dir, nil
for ms := time.Now().UnixMilli(); ; ms++ {
dir := filepath.Join(parent, fmt.Sprintf("%s-%d", cliVersion(), ms))
err := os.Mkdir(dir, 0o755)
if err == nil {
return dir, nil
}
if !errors.Is(err, os.ErrExist) {
return "", fmt.Errorf("create features folder: %w", err)
}
}
}

// fetchFeatureSetsWithOrder resolves the feature dependency graph through the
Expand Down
19 changes: 19 additions & 0 deletions internal/cli/feature_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,22 @@ func TestReadConfigurationRefusesALocalFeatureOutsideDevcontainer(t *testing.T)
}
wantExitCode(t, err, 1)
}

// Runs started in the same millisecond each get a features folder of their
// own: a shared one let one run's realignFeatureDirs remove the other's
// .stage- folders ("stage feature h_0: lstat .../.stage-0: no such file or
// directory" in the parity lane).
func TestCreateFeaturesFolderIsTheRunsAlone(t *testing.T) {
t.Setenv("TMPDIR", t.TempDir())
seen := map[string]bool{}
for range 50 {
dir, err := createFeaturesFolder()
if err != nil {
t.Fatal(err)
}
if seen[dir] {
t.Fatalf("%s handed out twice", dir)
}
seen[dir] = true
}
}
Loading