You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/11/19 15:40:27 UTC

[mynewt-newt] branch master updated: imgprod: Close .img before passing it to objcopy

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e263c4  imgprod: Close .img before passing it to objcopy
5e263c4 is described below

commit 5e263c4f760fcc1e028ef2fc37b44af0253a2d79
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Nov 18 12:28:35 2019 -0800

    imgprod: Close .img before passing it to objcopy
    
    This fixes a bug in the Windows port of newt.
    
    Newt produces a .hex file by running `objcopy` on the .img file.  It was
    doing this immediately after creating the .img file, before closing it.
    In Windows, objcopy cannot open a file when it is already open by a
    different process, so the command fails.
    
    The fix is to close the .img file before executing objcopy.
---
 newt/imgprod/imgprod.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/newt/imgprod/imgprod.go b/newt/imgprod/imgprod.go
index 5932048..bcce3a9 100644
--- a/newt/imgprod/imgprod.go
+++ b/newt/imgprod/imgprod.go
@@ -77,9 +77,10 @@ func writeImageFiles(ri image.Image, imgFilename string, hexFilename string,
 		return util.FmtNewtError(
 			"can't open image file \"%s\" %s", imgFilename, err.Error())
 	}
-	defer imgFile.Close()
 
-	if _, err := ri.Write(imgFile); err != nil {
+	_, err = ri.Write(imgFile)
+	imgFile.Close()
+	if err != nil {
 		return err
 	}