Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek committed Apr 22, 2024
1 parent 6cde3b2 commit 4352446
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ type Options struct {
// DevcontainerDir is a path to the folder containing
// the devcontainer.json file that will be used to build the
// workspace and can either be an absolute path or a path
// relative to the workspace folder.
// If not provided, it defaults to `.devcontainer`.
// relative to the workspace folder. If not provided, defaults to
// `.devcontainer`.
DevcontainerDir string `env:"DEVCONTAINER_DIR"`

// DevcontainerJSONPath is a path to a devcontainer.json file
Expand Down Expand Up @@ -1197,9 +1197,8 @@ func (fs *osfsWithChmod) Chmod(name string, mode os.FileMode) error {
}

func findDevcontainerJSON(options Options) (string, string, error) {
// 0. Check provided options.
// 0. Check if custom devcontainer directory or path is provided.
if options.DevcontainerDir != "" || options.DevcontainerJSONPath != "" {
// Locate .devcontainer directory.
devcontainerDir := options.DevcontainerDir
if devcontainerDir == "" {
devcontainerDir = ".devcontainer"
Expand All @@ -1209,14 +1208,11 @@ func findDevcontainerJSON(options Options) (string, string, error) {
devcontainerDir = filepath.Join(options.WorkspaceFolder, devcontainerDir)
}

// Locate devcontainer.json manifest.
devcontainerPath := options.DevcontainerJSONPath

// An absolute location always takes a precedence.
devcontainerPath := options.DevcontainerJSONPath
if filepath.IsAbs(devcontainerPath) {
return options.DevcontainerJSONPath, devcontainerDir, nil
}

// If an override is not provided, assume it is just `devcontainer.json`.
if devcontainerPath == "" {
devcontainerPath = "devcontainer.json"
Expand All @@ -1230,15 +1226,13 @@ func findDevcontainerJSON(options Options) (string, string, error) {

// 1. Check `options.WorkspaceFolder`/.devcontainer/devcontainer.json.
location := filepath.Join(options.WorkspaceFolder, ".devcontainer", "devcontainer.json")
_, err := options.Filesystem.Stat(location)
if err == nil {
if _, err := options.Filesystem.Stat(location); err == nil {
return location, filepath.Dir(location), nil
}

// 2. Check `options.WorkspaceFolder`/devcontainer.json.
location = filepath.Join(options.WorkspaceFolder, "devcontainer.json")
_, err = options.Filesystem.Stat(location)
if err == nil {
if _, err := options.Filesystem.Stat(location); err == nil {
return location, filepath.Dir(location), nil
}

Expand All @@ -1258,8 +1252,7 @@ func findDevcontainerJSON(options Options) (string, string, error) {
}

location := filepath.Join(devcontainerDir, fileInfo.Name(), "devcontainer.json")
_, err := options.Filesystem.Stat(location)
if err != nil {
if _, err := options.Filesystem.Stat(location); err != nil {
logf(codersdk.LogLevelDebug, `stat %s failed: %s`, location, err.Error())
continue
}
Expand Down

0 comments on commit 4352446

Please sign in to comment.