MCPcopy Create free account
hub / github.com/exercism/cli / ExerciseDir

Method ExerciseDir

workspace/workspace.go:101–127  ·  view source on GitHub ↗

ExerciseDir determines the root directory of an exercise. This is the directory that contains the exercise metadata file.

(s string)

Source from the content-addressed store, hash-verified

99// ExerciseDir determines the root directory of an exercise.
100// This is the directory that contains the exercise metadata file.
101func (ws Workspace) ExerciseDir(s string) (string, error) {
102 if !strings.HasPrefix(s, ws.Dir) {
103 var err = fmt.Errorf("not in workspace")
104 if runtime.GOOS == "darwin" {
105 err = fmt.Errorf("%w: directory location may be case sensitive: workspace directory: %s, "+
106 "submit path: %s", err, ws.Dir, s)
107 }
108 return "", err
109 }
110
111 path := s
112 for {
113 if path == ws.Dir {
114 return "", errMissingMetadata
115 }
116 if _, err := os.Lstat(path); os.IsNotExist(err) {
117 return "", err
118 }
119 if _, err := os.Lstat(filepath.Join(path, metadataFilepath)); err == nil {
120 return path, nil
121 }
122 if _, err := os.Lstat(filepath.Join(path, legacyMetadataFilename)); err == nil {
123 return path, nil
124 }
125 path = filepath.Dir(path)
126 }
127}

Callers 4

TestExerciseDirFunction · 0.80
exerciseMethod · 0.80

Calls

no outgoing calls

Tested by 2

TestExerciseDirFunction · 0.64