-
-
Notifications
You must be signed in to change notification settings - Fork 368
Move .solution.json to hidden subdirectory #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8f5493f
cef955f
60b57f1
34c4ec6
c76ab75
964e5c4
bea3009
4ad8121
642f601
858abd2
c363a1f
eaca5f3
5a641a5
9a2c772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,10 @@ import ( | |
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/exercism/cli/visibility" | ||
| ) | ||
|
|
||
| const solutionFilename = ".solution.json" | ||
| const ignoreSubdir = ".exercism" | ||
| const solutionFilename = "solution.json" | ||
|
|
||
| // Solution contains metadata about a user's solution. | ||
| type Solution struct { | ||
|
|
@@ -29,7 +28,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, SolutionMetadataFilepath()) | ||
| b, err := ioutil.ReadFile(path) | ||
| if err != nil { | ||
| return &Solution{}, err | ||
|
|
@@ -66,17 +65,14 @@ func (s *Solution) Write(dir string) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| path := filepath.Join(dir, solutionFilename) | ||
|
|
||
| // Hack because ioutil.WriteFile fails on hidden files | ||
| visibility.ShowFile(path) | ||
|
|
||
| if err := ioutil.WriteFile(path, b, os.FileMode(0600)); err != nil { | ||
| if err = createIgnoreSubdir(dir); err != nil { | ||
| return err | ||
| } | ||
| if err = ioutil.WriteFile(filepath.Join(dir, SolutionMetadataFilepath()), b, os.FileMode(0600)); err != nil { | ||
| return err | ||
| } | ||
| s.Dir = dir | ||
| return visibility.HideFile(path) | ||
| return nil | ||
| } | ||
|
|
||
| // PathToParent is the relative path from the workspace to the parent dir. | ||
|
|
@@ -87,3 +83,37 @@ func (s *Solution) PathToParent() string { | |
| } | ||
| return filepath.Join(dir, s.Track) | ||
| } | ||
|
|
||
| // SolutionMetadataFilepath is the path of the solution metadata file relative to the workspace. | ||
| func SolutionMetadataFilepath() string { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand how this works. Each exercise has its own metadata file, so this is relative to a subdirectory within the workspace.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mistakenly used 'workspace' when I meant 'exercise' there.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that makes sense. Thanks! |
||
| return filepath.Join(ignoreSubdir, solutionFilename) | ||
| } | ||
|
|
||
| func createIgnoreSubdir(path string) error { | ||
| path = filepath.Join(path, ignoreSubdir) | ||
| if _, err := os.Stat(path); os.IsNotExist(err) { | ||
| if err := os.Mkdir(path, os.FileMode(0755)); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func migrateLegacySolutionFile(legacySolutionPath string, solutionPath string) error { | ||
| if _, err := os.Lstat(legacySolutionPath); err != nil { | ||
| return err | ||
| } | ||
| if err := createIgnoreSubdir(filepath.Dir(legacySolutionPath)); err != nil { | ||
| return err | ||
| } | ||
| if _, err := os.Lstat(solutionPath); err != nil { | ||
| if err := os.Rename(legacySolutionPath, solutionPath); err != nil { | ||
| return err | ||
| } | ||
| fmt.Fprintf(os.Stderr, "\nMigrated solution metadata to %s\n", solutionPath) | ||
| } else { | ||
| // TODO: decide how to handle case where both legacy and modern metadata files exist | ||
| fmt.Fprintf(os.Stderr, "\nAttempted to migrate solution metadata to %s but file already exists\n", solutionPath) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the new metadata takes precendence which leads into my next comment about workspace,checkSolutionFile. It currently checks for a legacy metdata first, but I think we should check for the new path first and only check for legacy if it doesn’t exist.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. The most common path should be checked first. |
||
| } | ||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to check that this file doesn’t exist prior to executing submit?
@kytrinyx thoughts, Is it too much?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it would help clarify intent and ensure completeness.