Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/spf13/cobra"
)

const hiddenSolutionDir = ".exercism"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not being used anywhere. Is it needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, not sure how that slipped through.


// downloadCmd represents the download command
var downloadCmd = &cobra.Command{
Use: "download",
Expand Down
2 changes: 1 addition & 1 deletion cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestDownload(t *testing.T) {
},
{
desc: "It creates the .solution.json file.",
path: filepath.Join(cmdTest.TmpDir, "bogus-track", "bogus-exercise", ".solution.json"),
path: filepath.Join(cmdTest.TmpDir, "bogus-track", "bogus-exercise", "./.exercism/.solution.json"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't hard-code slashes here, as on Windows the slashes go the other way.

filepath.Join(cmdTest.TmpDir, "bogus-track", "bogus-exercise", ".exercism", "solution.json")

contents: `{"track":"bogus-track","exercise":"bogus-exercise","id":"bogus-id","url":"","handle":"alice","is_requester":true,"auto_approve":false}`,
},
}
Expand Down
9 changes: 7 additions & 2 deletions workspace/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
"github.com/exercism/cli/visibility"
)

const ignoreSubdir = ".exercism"
const solutionFilename = ".solution.json"

var solutionRelPath = filepath.Join(ignoreSubdir, solutionFilename)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is only used within NewSolution does it need to be a package level variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets used in 3 places (including workspace/workspace.go); it seems worth doing to encapsulate the path in one place. Is inlining const ignoreSubdir preferred?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im speaking about solutionRelPath. I did a quick search and didn’t see other references. If that variable is used three times and we don’t plan on changing it for testing should it be const?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be const: [gometalinter] const initializer filepath.Join(ignoreSubdir, solutionFilename) is not a constant (vet) [Error]

Copy link
Copy Markdown
Contributor

@nywilken nywilken Jul 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn’t clear, if we make solutionFilename a const with the new path we wouldn’t need the other variables as they are just being used to construct the final solution path
const SolutionFilename = filepath.Join(“.exercism”,”solution.json”)

I also think it should be exported to denote that it is actually shared or is expected to be.

Copy link
Copy Markdown
Contributor Author

@jdsutherland jdsutherland Jul 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. It appears that filepath.Join cannot be const: [gometalinter] const initializer filepath.Join(".exercism", "solution.json") is not a constant (vet) [Error]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well then it seems like the best advise I can give is to carry on as you were. Disregarding my coments on this file.

I didnt think about the the separator not being known until run time making it unfit to use as a const, my fault.

Thanks for vetting and for your time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. I appreciate your feedback.


// Solution contains metadata about a user's solution.
type Solution struct {
Track string `json:"track"`
Expand All @@ -29,7 +32,7 @@ type Solution struct {

// NewSolution reads solution metadata from a file in the given directory.
func NewSolution(dir string) (*Solution, error) {
path := filepath.Join(dir, solutionFilename)
path := filepath.Join(dir, solutionRelPath)
b, err := ioutil.ReadFile(path)
if err != nil {
return &Solution{}, err
Expand Down Expand Up @@ -67,11 +70,13 @@ func (s *Solution) Write(dir string) error {
return err
}

path := filepath.Join(dir, solutionFilename)
path := filepath.Join(dir, ignoreSubdir)
_ = os.Mkdir(path, os.FileMode(0755))

// Hack because ioutil.WriteFile fails on hidden files
visibility.ShowFile(path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are calling ShowFile on a directory then down below we are returning the result of visibility.HideFile on the full path to the solution file.

At this point I wonder if it is needed since it is now the directory that is a dot file.


path = filepath.Join(dir, solutionRelPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should now be filepath.Join(path, solutionRealPath)

if err := ioutil.WriteFile(path, b, os.FileMode(0600)); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (ws Workspace) SolutionDir(s string) (string, error) {
if _, err := os.Lstat(path); os.IsNotExist(err) {
return "", err
}
if _, err := os.Lstat(filepath.Join(path, solutionFilename)); err == nil {
if _, err := os.Lstat(filepath.Join(path, solutionRelPath)); err == nil {
return path, nil
}
path = filepath.Dir(path)
Expand Down