File tree Expand file tree Collapse file tree 2 files changed +35
-20
lines changed Expand file tree Collapse file tree 2 files changed +35
-20
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ func NewEditScaffolder(config *config.Config, multigroup bool) scaffold.Scaffold
42
42
43
43
// Scaffold implements Scaffolder
44
44
func (s * editScaffolder ) Scaffold () error {
45
- s .config .MultiGroup = s .multigroup
46
45
filename := "Dockerfile"
47
46
bs , err := ioutil .ReadFile (filename )
48
47
if err != nil {
@@ -56,21 +55,29 @@ func (s *editScaffolder) Scaffold() error {
56
55
str ,
57
56
"COPY api/ api/" ,
58
57
`COPY apis/ apis/` )
59
- if err != nil {
60
- return err
61
- }
62
58
} else {
63
59
str , err = ensureExistAndReplace (
64
60
str ,
65
61
"COPY apis/ apis/" ,
66
62
`COPY api/ api/` )
67
- if err != nil {
68
- return err
69
- }
70
63
}
71
- // false positive
72
- // nolint:gosec
73
- return ioutil .WriteFile (filename , []byte (str ), 0644 )
64
+
65
+ // Ignore the error encountered, if the file is already in desired format.
66
+ if err != nil && s .multigroup != s .config .MultiGroup {
67
+ return err
68
+ }
69
+
70
+ s .config .MultiGroup = s .multigroup
71
+
72
+ // Check if the str is not empty, because when the file is already in desired format it will return empty string
73
+ // because there is nothing to replace.
74
+ if str != "" {
75
+ // false positive
76
+ // nolint:gosec
77
+ return ioutil .WriteFile (filename , []byte (str ), 0644 )
78
+ }
79
+
80
+ return nil
74
81
}
75
82
76
83
func ensureExistAndReplace (input , match , replace string ) (string , error ) {
Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ func NewEditScaffolder(config *config.Config, multigroup bool) scaffold.Scaffold
42
42
43
43
// Scaffold implements Scaffolder
44
44
func (s * editScaffolder ) Scaffold () error {
45
- s .config .MultiGroup = s .multigroup
46
45
filename := "Dockerfile"
47
46
bs , err := ioutil .ReadFile (filename )
48
47
if err != nil {
@@ -56,21 +55,30 @@ func (s *editScaffolder) Scaffold() error {
56
55
str ,
57
56
"COPY api/ api/" ,
58
57
`COPY apis/ apis/` )
59
- if err != nil {
60
- return err
61
- }
58
+
62
59
} else {
63
60
str , err = ensureExistAndReplace (
64
61
str ,
65
62
"COPY apis/ apis/" ,
66
63
`COPY api/ api/` )
67
- if err != nil {
68
- return err
69
- }
70
64
}
71
- // false positive
72
- // nolint:gosec
73
- return ioutil .WriteFile (filename , []byte (str ), 0644 )
65
+
66
+ // Ignore the error encountered, if the file is already in desired format.
67
+ if err != nil && s .multigroup != s .config .MultiGroup {
68
+ return err
69
+ }
70
+
71
+ s .config .MultiGroup = s .multigroup
72
+
73
+ // Check if the str is not empty, because when the file is already in desired format it will return empty string
74
+ // because there is nothing to replace.
75
+ if str != "" {
76
+ // false positive
77
+ // nolint:gosec
78
+ return ioutil .WriteFile (filename , []byte (str ), 0644 )
79
+ }
80
+
81
+ return nil
74
82
}
75
83
76
84
func ensureExistAndReplace (input , match , replace string ) (string , error ) {
You can’t perform that action at this time.
0 commit comments