File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package workspace
22
33import (
44 "encoding/json"
5+ "errors"
56 "fmt"
67 "io/ioutil"
78 "os"
@@ -71,7 +72,9 @@ func (s *Solution) Write(dir string) error {
7172 }
7273
7374 path := filepath .Join (dir , ignoreSubdir )
74- _ = os .Mkdir (path , os .FileMode (0755 ))
75+ if err := createIgnoreSubdir (path ); err != nil {
76+ return err
77+ }
7578
7679 // Hack because ioutil.WriteFile fails on hidden files
7780 visibility .ShowFile (path )
@@ -92,3 +95,22 @@ func (s *Solution) PathToParent() string {
9295 }
9396 return filepath .Join (dir , s .Track )
9497}
98+
99+ func createIgnoreSubdir (path string ) error {
100+ if _ , err := os .Stat (path ); os .IsNotExist (err ) {
101+ if err := os .Mkdir (path , os .FileMode (0755 )); err != nil {
102+ return fmt .Errorf ("failed to create directory: %s" , path )
103+ }
104+ }
105+ return nil
106+ }
107+
108+ func migrateLegacySolutionFile (path string , legacySolutionPath string , solutionPath string ) error {
109+ if err := createIgnoreSubdir (filepath .Join (path , ignoreSubdir )); err != nil {
110+ return err
111+ }
112+ if err := os .Rename (legacySolutionPath , solutionPath ); err != nil {
113+ return errors .New ("failed migrating legacy solution file" )
114+ }
115+ return nil
116+ }
Original file line number Diff line number Diff line change @@ -186,14 +186,29 @@ func (ws Workspace) SolutionDir(s string) (string, error) {
186186 path := s
187187 for {
188188 if path == ws .Dir {
189- return "" , errors . New ("couldn't find it" )
189+ return "" , fmt . Errorf ("couldn't find %s" , solutionFilename )
190190 }
191191 if _ , err := os .Lstat (path ); os .IsNotExist (err ) {
192192 return "" , err
193193 }
194- if _ , err := os . Lstat ( filepath . Join ( path , solutionRelPath ) ); err == nil {
194+ if err := checkSolutionFile ( path ); err == nil {
195195 return path , nil
196196 }
197197 path = filepath .Dir (path )
198198 }
199199}
200+
201+ func checkSolutionFile (path string ) error {
202+ legacySolutionPath := filepath .Join (path , ".solution.json" )
203+ solutionPath := filepath .Join (path , solutionRelPath )
204+
205+ if _ , legacyErr := os .Lstat (legacySolutionPath ); legacyErr == nil {
206+ return migrateLegacySolutionFile (path , legacySolutionPath , solutionPath )
207+ } else if _ , err := os .Lstat (solutionPath ); err != nil {
208+ return err
209+ } else if legacyErr != nil && err == nil {
210+ return nil
211+ } else {
212+ return legacyErr
213+ }
214+ }
You can’t perform that action at this time.
0 commit comments