~mvo/snappy/snappy-os-snap-support

« back to all changes in this revision

Viewing changes to partition/bootloader_uboot.go

  • Committer: Snappy Tarmac
  • Author(s): John R. Lenton
  • Date: 2015-04-29 15:52:00 UTC
  • mfrom: (430.1.2 fsync)
  • Revision ID: snappy_tarmac-20150429155200-aa4vrcyxgwgec0ns
do fsync after "atomic" file writes by chipaca approved by mvo

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
                return err
176
176
        }
177
177
 
178
 
        defer file.Close()
 
178
        defer func() {
 
179
                e := file.Close()
 
180
                if err == nil {
 
181
                        err = e
 
182
                }
 
183
        }()
179
184
 
180
185
        writer := bufio.NewWriter(file)
181
186
 
184
189
                        return err
185
190
                }
186
191
        }
187
 
        return writer.Flush()
 
192
 
 
193
        if err := writer.Flush(); err != nil {
 
194
                return err
 
195
        }
 
196
 
 
197
        return file.Sync()
188
198
}
189
199
 
190
200
func (u *uboot) MarkCurrentBootSuccessful() (err error) {
310
320
func atomicFileUpdate(file string, lines []string) (err error) {
311
321
        tmpFile := fmt.Sprintf("%s.NEW", file)
312
322
 
 
323
        // XXX: if go switches to use aio_fsync, we need to open the dir for writing
 
324
        dir, err := os.Open(filepath.Dir(file))
 
325
        if err != nil {
 
326
                return err
 
327
        }
 
328
        defer dir.Close()
 
329
 
313
330
        if err := writeLines(lines, tmpFile); err != nil {
314
331
                return err
315
332
        }
319
336
                return err
320
337
        }
321
338
 
322
 
        return nil
 
339
        return dir.Sync()
323
340
}
324
341
 
325
342
// Rewrite the specified file, applying the specified set of changes.