[cipd] Replace "amd64" to "x64" in ".Arch" template for package's path.

By default, when creating local paths for packages for multiple
platforms, jiri uses the cipd platform format, including "linux-amd64".
However, fuchsia developer uses "linux-x64". Since it's not feasible for
Fuchsia to change its platform format into cipd format. This patch
replaces "amd64" with "x64" to allow using ".Arch" template in manifest
without issues. This patch also fixes a typo in cipd.go

Test: Local
Change-Id: Idb6d3d1cddc415dd54e4882faa2a3290d9ef397c
diff --git a/cipd/cipd.go b/cipd/cipd.go
index 6140528..3de93b3 100644
--- a/cipd/cipd.go
+++ b/cipd/cipd.go
@@ -172,6 +172,26 @@
 	return cipdPath, nil
 }
 
+// FuchsiaPlatform returns a Platform struct which can be used in
+// determing the correct path for prebuilt packages. It replace
+// the os and arch names from cipd format to a format used by
+// Fuchsia developers.
+func FuchsiaPlatform(plat Platform) Platform {
+	retPlat := Platform{
+		OS:   plat.OS,
+		Arch: plat.Arch,
+	}
+	// Currently cipd use "amd64" for x86_64 while fuchsia use "x64",
+	// replace "amd64" with "x64".
+	// There might be other differences that need to be addressed in
+	// the future.
+	switch retPlat.Arch {
+	case "amd64":
+		retPlat.Arch = "x64"
+	}
+	return retPlat
+}
+
 func fetchDigest(platform string) (digest, method string, err error) {
 	var digestBuf bytes.Buffer
 	digestBuf.Write([]byte(cipdVersionDigest))
@@ -569,7 +589,7 @@
 		floatingRef := <-c
 		pkgs[floatingRef.pkg] = floatingRef.floating
 		if floatingRef.err != nil {
-			errBuf.WriteString(err.Error())
+			errBuf.WriteString(floatingRef.err.Error())
 			errBuf.WriteByte('\n')
 		}
 	}
diff --git a/cmd/jiri/package.go b/cmd/jiri/package.go
index 5715995..409270c 100644
--- a/cmd/jiri/package.go
+++ b/cmd/jiri/package.go
@@ -96,7 +96,9 @@
 			return fmt.Errorf("parsing package path %q failed", pkgPath)
 		}
 		var subdirBuf bytes.Buffer
-		tmpl.Execute(&subdirBuf, cipd.CipdPlatform)
+		// subdir is using fuchsia platform format instead of
+		// using cipd platform format
+		tmpl.Execute(&subdirBuf, cipd.FuchsiaPlatform(cipd.CipdPlatform))
 		pkgPath = filepath.Join(jirix.Root, subdirBuf.String())
 
 		info = append(info, packageInfoOutput{
diff --git a/project/manifest.go b/project/manifest.go
index 6887e55..a4cb253 100644
--- a/project/manifest.go
+++ b/project/manifest.go
@@ -1000,7 +1000,9 @@
 		return "", fmt.Errorf("parsing package path %q failed", subdir)
 	}
 	var subdirBuf bytes.Buffer
-	tmpl.Execute(&subdirBuf, cipd.CipdPlatform)
+	// subdir is using fuchsia platform format instead of
+	// using cipd platform format
+	tmpl.Execute(&subdirBuf, cipd.FuchsiaPlatform(cipd.CipdPlatform))
 	subdir = subdirBuf.String()
 	buf.WriteString(fmt.Sprintf("@Subdir %s\n", subdir))
 	// Write package version line to cipd declaration