Skip to content

Commit f33ef0f

Browse files
authored
1 parent d527a4f commit f33ef0f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

internal/generate/generate_modules.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func Generate(projectConfig projectconfig.ZeroProjectConfig) error {
6767
type fileConfig struct {
6868
source string
6969
destination string
70+
modeBits os.FileMode
7071
}
7172

7273
// sortFileType walks the module directory to find and classify all files into bin / text/plain (non-bin) types.
@@ -94,6 +95,11 @@ func sortFileType(moduleDir string, outputDir string, overwrite bool) ([]*fileCo
9495
}
9596
}
9697

98+
fileInfo, err := os.Stat(path)
99+
if err != nil {
100+
panic(err)
101+
}
102+
97103
// detect the file type
98104
detectedMIME, err := mimetype.DetectFile(path)
99105
if err != nil {
@@ -112,13 +118,15 @@ func sortFileType(moduleDir string, outputDir string, overwrite bool) ([]*fileCo
112118
binTypeFiles = append(binTypeFiles, &fileConfig{
113119
source: path,
114120
destination: outputPath,
121+
modeBits: fileInfo.Mode().Perm(),
115122
})
116123
continue
117124
}
118125

119126
txtTypeFiles = append(txtTypeFiles, &fileConfig{
120127
source: path,
121128
destination: outputPath,
129+
modeBits: fileInfo.Mode().Perm(),
122130
})
123131
}
124132
return txtTypeFiles, binTypeFiles
@@ -169,6 +177,12 @@ func executeTemplates(templates []*fileConfig, data interface{}, delimiters []st
169177
if err != nil {
170178
flog.Errorf("Error initializing file '%s'", err)
171179
}
180+
181+
err = f.Chmod(tmpltConfig.modeBits)
182+
if err != nil {
183+
flog.Errorf("Error changing mode bits '%s'", err)
184+
}
185+
172186
// @TODO if strict mode then only copy file
173187
name := path.Base(source)
174188
template, err := template.New(name).Delims(leftDelim, rightDelim).Funcs(util.FuncMap).ParseFiles(source)
@@ -185,7 +199,6 @@ func executeTemplates(templates []*fileConfig, data interface{}, delimiters []st
185199
}
186200

187201
func copyBinFiles(binTypeFiles []*fileConfig) {
188-
189202
for _, binFile := range binTypeFiles {
190203
source := binFile.source
191204
dest := binFile.destination
@@ -204,7 +217,7 @@ func copyBinFiles(binTypeFiles []*fileConfig) {
204217
}
205218
defer from.Close()
206219

207-
to, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, 0666)
220+
to, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, binFile.modeBits)
208221
if err != nil {
209222
log.Fatal(err)
210223
flog.Errorf("Error creating file '%s': %v", dest, err)

0 commit comments

Comments
 (0)