ExerciseDir determines the root directory of an exercise. This is the directory that contains the exercise metadata file.
(s string)
| 99 | // ExerciseDir determines the root directory of an exercise. |
| 100 | // This is the directory that contains the exercise metadata file. |
| 101 | func (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 | } |
no outgoing calls