From 17e58b8d0a55b0f173c9a60d06fb6edfdd2df337 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Wed, 20 Jan 2016 18:26:26 -0700 Subject: [PATCH] Allow for exercises in 'exercises' subdirectory --- .../track/{ => exercises}/amethyst/.keep | 0 .../{ => exercises}/amethyst/example.txt | 0 configlet/track.go | 22 +++++++++---------- 3 files changed, 11 insertions(+), 11 deletions(-) rename configlet/fixtures/track/{ => exercises}/amethyst/.keep (100%) rename configlet/fixtures/track/{ => exercises}/amethyst/example.txt (100%) diff --git a/configlet/fixtures/track/amethyst/.keep b/configlet/fixtures/track/exercises/amethyst/.keep similarity index 100% rename from configlet/fixtures/track/amethyst/.keep rename to configlet/fixtures/track/exercises/amethyst/.keep diff --git a/configlet/fixtures/track/amethyst/example.txt b/configlet/fixtures/track/exercises/amethyst/example.txt similarity index 100% rename from configlet/fixtures/track/amethyst/example.txt rename to configlet/fixtures/track/exercises/amethyst/example.txt diff --git a/configlet/track.go b/configlet/track.go index 913e537..b86f10a 100644 --- a/configlet/track.go +++ b/configlet/track.go @@ -93,30 +93,30 @@ func (t Track) Dirs() (map[string]struct{}, error) { } for _, info := range infos { - if info.IsDir() { + if info.IsDir() && info.Name() != "exercises" { dirs[info.Name()] = struct{}{} } } - return dirs, nil -} -// ExerciseDirs lists all directories within the "exercises" directory. -// An implemented problem must be either in the root (legacy) or in the -// exercises dir. -func (t Track) ExerciseDirs() (map[string]struct{}, error) { - dirs := make(map[string]struct{}) + path := filepath.Join(t.path, "exercises") + if _, err := os.Stat(path); err != nil { + if os.IsNotExist(err) { + return dirs, nil + } + return dirs, err + } - infos, err := ioutil.ReadDir(filepath.Join(t.path, "exercises")) + infos, err = ioutil.ReadDir(filepath.Join(t.path, "exercises")) if err != nil { - fmt.Println(err) return dirs, err } for _, info := range infos { - if info.IsDir() { + if info.IsDir() && info.Name() != "exercises" { dirs[info.Name()] = struct{}{} } } + return dirs, nil }