fix: license issue in blob disk feature

This commit is contained in:
andyzhangx
2020-07-06 12:19:51 +00:00
parent dd649bb7ef
commit a552c7640f
8 changed files with 22 additions and 28 deletions

View File

@@ -9,6 +9,10 @@ go_library(
importmap = "k8s.io/kubernetes/vendor/github.com/rubiojr/go-vhd/vhd",
importpath = "github.com/rubiojr/go-vhd/vhd",
visibility = ["//visibility:public"],
deps = [
"//vendor/golang.org/x/text/encoding/unicode:go_default_library",
"//vendor/golang.org/x/text/transform:go_default_library",
],
)
filegroup(

View File

@@ -1,13 +1,10 @@
package vhd
import (
"encoding/binary"
"encoding/hex"
"fmt"
"os"
"strings"
"unicode/utf16"
"unicode/utf8"
)
// https://groups.google.com/forum/#!msg/golang-nuts/d0nF_k4dSx4/rPGgfXv6QCoJ
@@ -55,19 +52,3 @@ func uuidToBytes(uuid string) []byte {
return h
}
/*
utf16BytesToString converts UTF-16 encoded bytes, in big or
little endian byte order, to a UTF-8 encoded string.
http://stackoverflow.com/a/15794113
*/
func utf16BytesToString(b []byte, o binary.ByteOrder) string {
utf := make([]uint16, (len(b)+(2-1))/2)
for i := 0; i+(2-1) < len(b); i += 2 {
utf[i/2] = o.Uint16(b[i:])
}
if len(b)/2 < len(utf) {
utf[len(utf)-1] = utf8.RuneError
}
return string(utf16.Decode(utf))
}

View File

@@ -11,6 +11,9 @@ import (
"os"
"strconv"
"time"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)
const VHD_COOKIE = "636f6e6563746978" // conectix
@@ -324,8 +327,14 @@ func (vhd *VHD) PrintExtraHeader() {
fmtField("Parent timestamp", fmt.Sprintf("%s", t))
fmtField("Reserved", hexs(header.Reserved[:]))
parentName := utf16BytesToString(header.ParentUnicodeName[:],
binary.BigEndian)
parentNameBytes, _, err := transform.Bytes(
unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewDecoder(),
header.ParentUnicodeName[:],
)
if err != nil {
panic(err)
}
parentName := string(parentNameBytes)
fmtField("Parent Name", parentName)
// Parent locator entries ignored since it's a dynamic disk
sum := 0