@@ -190,48 +190,17 @@ func GenerateFile(config config.Config, containers context.Context) bool {
190
190
}
191
191
192
192
if config .Dest != "" {
193
- dest , err := os .CreateTemp (filepath .Dir (config .Dest ), "docker-gen" )
194
- defer func () {
195
- dest .Close ()
196
- os .Remove (dest .Name ())
197
- }()
198
- if err != nil {
199
- log .Fatalf ("Unable to create temp file: %s\n " , err )
200
- }
201
-
202
- if n , err := dest .Write (contents ); n != len (contents ) || err != nil {
203
- log .Fatalf ("Failed to write to temp file: wrote %d, exp %d, err=%v" , n , len (contents ), err )
204
- }
205
-
206
- oldContents := []byte {}
207
- if fi , err := os .Stat (config .Dest ); err == nil || os .IsNotExist (err ) {
208
- if err != nil && os .IsNotExist (err ) {
209
- emptyFile , err := os .Create (config .Dest )
210
- if err != nil {
211
- log .Fatalf ("Unable to create empty destination file: %s\n " , err )
212
- } else {
213
- emptyFile .Close ()
214
- fi , _ = os .Stat (config .Dest )
215
- }
216
- }
217
-
218
- if err := dest .Chmod (fi .Mode ()); err != nil {
219
- log .Fatalf ("Unable to chmod temp file: %s\n " , err )
220
- }
221
-
222
- chown (dest , fi )
223
-
224
- oldContents , err = os .ReadFile (config .Dest )
225
- if err != nil {
226
- log .Fatalf ("Unable to compare current file contents: %s: %s\n " , config .Dest , err )
227
- }
193
+ oldContents , err := os .ReadFile (config .Dest )
194
+ if err != nil && ! os .IsNotExist (err ) {
195
+ log .Fatalf ("Unable to compare current file contents: %s: %s\n " , config .Dest , err )
228
196
}
229
197
230
198
if ! bytes .Equal (oldContents , contents ) {
231
- err = os .Rename ( dest . Name (), config .Dest )
199
+ err : = os .WriteFile ( config .Dest , contents , 0644 )
232
200
if err != nil {
233
- log .Fatalf ("Unable to create dest file %s: %s\n " , config .Dest , err )
201
+ log .Fatalf ("Unable to write to dest file %s: %s\n " , config .Dest , err )
234
202
}
203
+
235
204
log .Printf ("Generated '%s' from %d containers" , config .Dest , len (filteredContainers ))
236
205
return true
237
206
}
0 commit comments