You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/01/15 00:35:02 UTC

[GitHub] ccollins476ad closed pull request #57: Some fixes for the `newtmgr file` commands.

ccollins476ad closed pull request #57: Some fixes for the `newtmgr file` commands.
URL: https://github.com/apache/mynewt-newtmgr/pull/57
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nmxact/xact/fs.go b/nmxact/xact/fs.go
index d6faa38..be12879 100644
--- a/nmxact/xact/fs.go
+++ b/nmxact/xact/fs.go
@@ -81,10 +81,12 @@ func (c *FsDownloadCmd) Run(s sesn.Sesn) (Result, error) {
 			c.ProgressCb(c, frsp)
 		}
 
-		off = int(frsp.Off) + len(frsp.Data)
-		if off >= int(frsp.Len) {
+		if len(frsp.Data) == 0 {
+			// Download complete.
 			break
 		}
+
+		off = int(frsp.Off) + len(frsp.Data)
 	}
 
 	return res, nil
@@ -149,13 +151,18 @@ func nextFsUploadReq(s sesn.Sesn, name string, data []byte, off int) (
 
 	room := s.MtuOut() - len(emptyEnc)
 	if room <= 0 {
-		return nil, fmt.Errorf("Cannot create image upload request; " +
-			"MTU too low to fit any image data")
+		return nil, fmt.Errorf("Cannot create file upload request; " +
+			"MTU too low to fit any file data")
+	}
+
+	if off+room > len(data) {
+		// Final chunk.
+		room = len(data) - off
 	}
 
-	// Assume all the unused space can hold image data.  This assumption may
-	// not be valid for some encodings (e.g., CBOR uses variable length fields
-	// to encodes byte string lengths).
+	// Assume all the unused space can hold file data.  This assumption may not
+	// be valid for some encodings (e.g., CBOR uses variable length fields to
+	// encodes byte string lengths).
 	r := buildFsUploadReq(name, len(data), data[off:off+room], off)
 	enc, err := mgmt.EncodeMgmt(s, r.Msg())
 	if err != nil {
@@ -164,7 +171,7 @@ func nextFsUploadReq(s sesn.Sesn, name string, data []byte, off int) (
 
 	oversize := len(enc) - s.MtuOut()
 	if oversize > 0 {
-		// Request too big.  Reduce the amount of image data.
+		// Request too big.  Reduce the amount of file data.
 		r = buildFsUploadReq(name, len(data), data[off:off+room-oversize], off)
 	}
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services