Browse code

bump mistifyio/go-zfs d5b163290a48f624cbf244ebe4e89ce38653064c

full diff: https://github.com/mistifyio/go-zfs/compare/22c9b32c84eb0d0c6f4043b6e90fc94073de92fa...f784269be439d704d3dfa1906f45dd848fed2beb

relevant changes:

- mistifyio/go-zfs#50 Fix GetProperty always returning 'VALUE'
- fixes mistifyio/go-zfs#49 dataset.GetProperty(key) always returns 'VALUE'
- mistifyio/go-zfs#53 Fix parseLine for fragmentation field
- fixes mistifyio/go-zfs#52 setUint receives empty string for fragmentation in some cases
- mistifyio/go-zfs#54 Add 'referenced' to zfs properties
- mistifyio/go-zfs#72 Switch to google/uuid
- removes the github.com/pborman/uuid dependency

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/04/14 05:42:35
Showing 19 changed files
... ...
@@ -71,8 +71,7 @@ github.com/vbatts/tar-split                         620714a4c508c880ac1bdda9c837
71 71
 github.com/opencontainers/go-digest                 279bed98673dd5bef374d3b6e4b09e2af76183bf # v1.0.0-rc1
72 72
 
73 73
 # get go-zfs packages
74
-github.com/mistifyio/go-zfs                         22c9b32c84eb0d0c6f4043b6e90fc94073de92fa
75
-github.com/pborman/uuid                             a97ce2ca70fa5a848076093f05e639a89ca34d06 # v1.0
74
+github.com/mistifyio/go-zfs                         f784269be439d704d3dfa1906f45dd848fed2beb
76 75
 
77 76
 google.golang.org/grpc                              7a6a684ca69eb4cae85ad0a484f2e531598c047b # v1.12.2
78 77
 
... ...
@@ -29,7 +29,7 @@ The tests have decent examples for most functions.
29 29
 
30 30
 ```go
31 31
 //assuming a zpool named test
32
-//error handling ommitted
32
+//error handling omitted
33 33
 
34 34
 
35 35
 f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"strconv"
12 12
 	"strings"
13 13
 
14
-	"github.com/pborman/uuid"
14
+	"github.com/google/uuid"
15 15
 )
16 16
 
17 17
 type command struct {
... ...
@@ -38,7 +38,7 @@ func (c *command) Run(arg ...string) ([][]string, error) {
38 38
 	}
39 39
 	cmd.Stderr = &stderr
40 40
 
41
-	id := uuid.New()
41
+	id := uuid.New().String()
42 42
 	joinedArgs := strings.Join(cmd.Args, " ")
43 43
 
44 44
 	logger.Log([]string{"ID:" + id, "START", joinedArgs})
... ...
@@ -48,7 +48,7 @@ func (c *command) Run(arg ...string) ([][]string, error) {
48 48
 	if err != nil {
49 49
 		return nil, &Error{
50 50
 			Err:    err,
51
-			Debug:  strings.Join([]string{cmd.Path, joinedArgs}, " "),
51
+			Debug:  strings.Join([]string{cmd.Path, joinedArgs[1:]}, " "),
52 52
 			Stderr: stderr.String(),
53 53
 		}
54 54
 	}
... ...
@@ -118,20 +118,24 @@ func (ds *Dataset) parseLine(line []string) error {
118 118
 	if err = setUint(&ds.Quota, line[8]); err != nil {
119 119
 		return err
120 120
 	}
121
+	if err = setUint(&ds.Referenced, line[9]); err != nil {
122
+		return err
123
+	}
121 124
 
122 125
 	if runtime.GOOS == "solaris" {
123 126
 		return nil
124 127
 	}
125 128
 
126
-	if err = setUint(&ds.Written, line[9]); err != nil {
129
+	if err = setUint(&ds.Written, line[10]); err != nil {
127 130
 		return err
128 131
 	}
129
-	if err = setUint(&ds.Logicalused, line[10]); err != nil {
132
+	if err = setUint(&ds.Logicalused, line[11]); err != nil {
130 133
 		return err
131 134
 	}
132
-	if err = setUint(&ds.Usedbydataset, line[11]); err != nil {
135
+	if err = setUint(&ds.Usedbydataset, line[12]); err != nil {
133 136
 		return err
134 137
 	}
138
+
135 139
 	return nil
136 140
 }
137 141
 
... ...
@@ -337,7 +341,11 @@ func (z *Zpool) parseLine(line []string) error {
337 337
 		err = setUint(&z.Free, val)
338 338
 	case "fragmentation":
339 339
 		// Trim trailing "%" before parsing uint
340
-		err = setUint(&z.Fragmentation, val[:len(val)-1])
340
+		i := strings.Index(val, "%")
341
+		if i < 0 {
342
+			i = len(val)
343
+		}
344
+		err = setUint(&z.Fragmentation, val[:i])
341 345
 	case "readonly":
342 346
 		z.ReadOnly = val == "on"
343 347
 	case "freeing":
... ...
@@ -7,7 +7,7 @@ import (
7 7
 )
8 8
 
9 9
 // List of ZFS properties to retrieve from zfs list command on a non-Solaris platform
10
-var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "written", "logicalused", "usedbydataset"}
10
+var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "referenced", "written", "logicalused", "usedbydataset"}
11 11
 
12 12
 var dsPropListOptions = strings.Join(dsPropList, ",")
13 13
 
... ...
@@ -7,7 +7,7 @@ import (
7 7
 )
8 8
 
9 9
 // List of ZFS properties to retrieve from zfs list command on a Solaris platform
10
-var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota"}
10
+var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "referenced"}
11 11
 
12 12
 var dsPropListOptions = strings.Join(dsPropList, ",")
13 13
 
... ...
@@ -35,6 +35,7 @@ type Dataset struct {
35 35
 	Logicalused   uint64
36 36
 	Usedbydataset uint64
37 37
 	Quota         uint64
38
+	Referenced    uint64
38 39
 }
39 40
 
40 41
 // InodeType is the type of inode as reported by Diff
... ...
@@ -307,7 +308,7 @@ func (d *Dataset) SetProperty(key, val string) error {
307 307
 // A full list of available ZFS properties may be found here:
308 308
 // https://www.freebsd.org/cgi/man.cgi?zfs(8).
309 309
 func (d *Dataset) GetProperty(key string) (string, error) {
310
-	out, err := zfs("get", key, d.Name)
310
+	out, err := zfs("get", "-H", key, d.Name)
311 311
 	if err != nil {
312 312
 		return "", err
313 313
 	}
314 314
deleted file mode 100644
... ...
@@ -1,27 +0,0 @@
1
-Copyright (c) 2009,2014 Google Inc. All rights reserved.
2
-
3
-Redistribution and use in source and binary forms, with or without
4
-modification, are permitted provided that the following conditions are
5
-met:
6
-
7
-   * Redistributions of source code must retain the above copyright
8
-notice, this list of conditions and the following disclaimer.
9
-   * Redistributions in binary form must reproduce the above
10
-copyright notice, this list of conditions and the following disclaimer
11
-in the documentation and/or other materials provided with the
12
-distribution.
13
-   * Neither the name of Google Inc. nor the names of its
14
-contributors may be used to endorse or promote products derived from
15
-this software without specific prior written permission.
16
-
17
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1
deleted file mode 100644
... ...
@@ -1,13 +0,0 @@
1
-This project was automatically exported from code.google.com/p/go-uuid
2
-
3
-# uuid ![build status](https://travis-ci.org/pborman/uuid.svg?branch=master)
4
-The uuid package generates and inspects UUIDs based on [RFC 412](http://tools.ietf.org/html/rfc4122) and DCE 1.1: Authentication and Security Services. 
5
-
6
-###### Install
7
-`go get github.com/pborman/uuid`
8
-
9
-###### Documentation 
10
-[![GoDoc](https://godoc.org/github.com/pborman/uuid?status.svg)](http://godoc.org/github.com/pborman/uuid)
11
-
12
-Full `go doc` style documentation for the package can be viewed online without installing this package by using the GoDoc site here: 
13
-http://godoc.org/github.com/pborman/uuid
14 1
deleted file mode 100755
... ...
@@ -1,84 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"encoding/binary"
9
-	"fmt"
10
-	"os"
11
-)
12
-
13
-// A Domain represents a Version 2 domain
14
-type Domain byte
15
-
16
-// Domain constants for DCE Security (Version 2) UUIDs.
17
-const (
18
-	Person = Domain(0)
19
-	Group  = Domain(1)
20
-	Org    = Domain(2)
21
-)
22
-
23
-// NewDCESecurity returns a DCE Security (Version 2) UUID.
24
-//
25
-// The domain should be one of Person, Group or Org.
26
-// On a POSIX system the id should be the users UID for the Person
27
-// domain and the users GID for the Group.  The meaning of id for
28
-// the domain Org or on non-POSIX systems is site defined.
29
-//
30
-// For a given domain/id pair the same token may be returned for up to
31
-// 7 minutes and 10 seconds.
32
-func NewDCESecurity(domain Domain, id uint32) UUID {
33
-	uuid := NewUUID()
34
-	if uuid != nil {
35
-		uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2
36
-		uuid[9] = byte(domain)
37
-		binary.BigEndian.PutUint32(uuid[0:], id)
38
-	}
39
-	return uuid
40
-}
41
-
42
-// NewDCEPerson returns a DCE Security (Version 2) UUID in the person
43
-// domain with the id returned by os.Getuid.
44
-//
45
-//  NewDCEPerson(Person, uint32(os.Getuid()))
46
-func NewDCEPerson() UUID {
47
-	return NewDCESecurity(Person, uint32(os.Getuid()))
48
-}
49
-
50
-// NewDCEGroup returns a DCE Security (Version 2) UUID in the group
51
-// domain with the id returned by os.Getgid.
52
-//
53
-//  NewDCEGroup(Group, uint32(os.Getgid()))
54
-func NewDCEGroup() UUID {
55
-	return NewDCESecurity(Group, uint32(os.Getgid()))
56
-}
57
-
58
-// Domain returns the domain for a Version 2 UUID or false.
59
-func (uuid UUID) Domain() (Domain, bool) {
60
-	if v, _ := uuid.Version(); v != 2 {
61
-		return 0, false
62
-	}
63
-	return Domain(uuid[9]), true
64
-}
65
-
66
-// Id returns the id for a Version 2 UUID or false.
67
-func (uuid UUID) Id() (uint32, bool) {
68
-	if v, _ := uuid.Version(); v != 2 {
69
-		return 0, false
70
-	}
71
-	return binary.BigEndian.Uint32(uuid[0:4]), true
72
-}
73
-
74
-func (d Domain) String() string {
75
-	switch d {
76
-	case Person:
77
-		return "Person"
78
-	case Group:
79
-		return "Group"
80
-	case Org:
81
-		return "Org"
82
-	}
83
-	return fmt.Sprintf("Domain%d", int(d))
84
-}
85 1
deleted file mode 100755
... ...
@@ -1,8 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-// The uuid package generates and inspects UUIDs.
6
-//
7
-// UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services.
8
-package uuid
9 1
deleted file mode 100644
... ...
@@ -1,53 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"crypto/md5"
9
-	"crypto/sha1"
10
-	"hash"
11
-)
12
-
13
-// Well known Name Space IDs and UUIDs
14
-var (
15
-	NameSpace_DNS  = Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
16
-	NameSpace_URL  = Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
17
-	NameSpace_OID  = Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
18
-	NameSpace_X500 = Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
19
-	NIL            = Parse("00000000-0000-0000-0000-000000000000")
20
-)
21
-
22
-// NewHash returns a new UUID derived from the hash of space concatenated with
23
-// data generated by h.  The hash should be at least 16 byte in length.  The
24
-// first 16 bytes of the hash are used to form the UUID.  The version of the
25
-// UUID will be the lower 4 bits of version.  NewHash is used to implement
26
-// NewMD5 and NewSHA1.
27
-func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
28
-	h.Reset()
29
-	h.Write(space)
30
-	h.Write([]byte(data))
31
-	s := h.Sum(nil)
32
-	uuid := make([]byte, 16)
33
-	copy(uuid, s)
34
-	uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)
35
-	uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant
36
-	return uuid
37
-}
38
-
39
-// NewMD5 returns a new MD5 (Version 3) UUID based on the
40
-// supplied name space and data.
41
-//
42
-//  NewHash(md5.New(), space, data, 3)
43
-func NewMD5(space UUID, data []byte) UUID {
44
-	return NewHash(md5.New(), space, data, 3)
45
-}
46
-
47
-// NewSHA1 returns a new SHA1 (Version 5) UUID based on the
48
-// supplied name space and data.
49
-//
50
-//  NewHash(sha1.New(), space, data, 5)
51
-func NewSHA1(space UUID, data []byte) UUID {
52
-	return NewHash(sha1.New(), space, data, 5)
53
-}
54 1
deleted file mode 100644
... ...
@@ -1,34 +0,0 @@
1
-// Copyright 2014 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import "errors"
8
-
9
-func (u UUID) MarshalJSON() ([]byte, error) {
10
-	if len(u) != 16 {
11
-		return []byte(`""`), nil
12
-	}
13
-	var js [38]byte
14
-	js[0] = '"'
15
-	encodeHex(js[1:], u)
16
-	js[37] = '"'
17
-	return js[:], nil
18
-}
19
-
20
-func (u *UUID) UnmarshalJSON(data []byte) error {
21
-	if string(data) == `""` {
22
-		return nil
23
-	}
24
-	if data[0] != '"' {
25
-		return errors.New("invalid UUID format")
26
-	}
27
-	data = data[1 : len(data)-1]
28
-	uu := Parse(string(data))
29
-	if uu == nil {
30
-		return errors.New("invalid UUID format")
31
-	}
32
-	*u = uu
33
-	return nil
34
-}
35 1
deleted file mode 100755
... ...
@@ -1,117 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"net"
9
-	"sync"
10
-)
11
-
12
-var (
13
-	nodeMu     sync.Mutex
14
-	interfaces []net.Interface // cached list of interfaces
15
-	ifname     string          // name of interface being used
16
-	nodeID     []byte          // hardware for version 1 UUIDs
17
-)
18
-
19
-// NodeInterface returns the name of the interface from which the NodeID was
20
-// derived.  The interface "user" is returned if the NodeID was set by
21
-// SetNodeID.
22
-func NodeInterface() string {
23
-	defer nodeMu.Unlock()
24
-	nodeMu.Lock()
25
-	return ifname
26
-}
27
-
28
-// SetNodeInterface selects the hardware address to be used for Version 1 UUIDs.
29
-// If name is "" then the first usable interface found will be used or a random
30
-// Node ID will be generated.  If a named interface cannot be found then false
31
-// is returned.
32
-//
33
-// SetNodeInterface never fails when name is "".
34
-func SetNodeInterface(name string) bool {
35
-	defer nodeMu.Unlock()
36
-	nodeMu.Lock()
37
-	return setNodeInterface(name)
38
-}
39
-
40
-func setNodeInterface(name string) bool {
41
-	if interfaces == nil {
42
-		var err error
43
-		interfaces, err = net.Interfaces()
44
-		if err != nil && name != "" {
45
-			return false
46
-		}
47
-	}
48
-
49
-	for _, ifs := range interfaces {
50
-		if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
51
-			if setNodeID(ifs.HardwareAddr) {
52
-				ifname = ifs.Name
53
-				return true
54
-			}
55
-		}
56
-	}
57
-
58
-	// We found no interfaces with a valid hardware address.  If name
59
-	// does not specify a specific interface generate a random Node ID
60
-	// (section 4.1.6)
61
-	if name == "" {
62
-		if nodeID == nil {
63
-			nodeID = make([]byte, 6)
64
-		}
65
-		randomBits(nodeID)
66
-		return true
67
-	}
68
-	return false
69
-}
70
-
71
-// NodeID returns a slice of a copy of the current Node ID, setting the Node ID
72
-// if not already set.
73
-func NodeID() []byte {
74
-	defer nodeMu.Unlock()
75
-	nodeMu.Lock()
76
-	if nodeID == nil {
77
-		setNodeInterface("")
78
-	}
79
-	nid := make([]byte, 6)
80
-	copy(nid, nodeID)
81
-	return nid
82
-}
83
-
84
-// SetNodeID sets the Node ID to be used for Version 1 UUIDs.  The first 6 bytes
85
-// of id are used.  If id is less than 6 bytes then false is returned and the
86
-// Node ID is not set.
87
-func SetNodeID(id []byte) bool {
88
-	defer nodeMu.Unlock()
89
-	nodeMu.Lock()
90
-	if setNodeID(id) {
91
-		ifname = "user"
92
-		return true
93
-	}
94
-	return false
95
-}
96
-
97
-func setNodeID(id []byte) bool {
98
-	if len(id) < 6 {
99
-		return false
100
-	}
101
-	if nodeID == nil {
102
-		nodeID = make([]byte, 6)
103
-	}
104
-	copy(nodeID, id)
105
-	return true
106
-}
107
-
108
-// NodeID returns the 6 byte node id encoded in uuid.  It returns nil if uuid is
109
-// not valid.  The NodeID is only well defined for version 1 and 2 UUIDs.
110
-func (uuid UUID) NodeID() []byte {
111
-	if len(uuid) != 16 {
112
-		return nil
113
-	}
114
-	node := make([]byte, 6)
115
-	copy(node, uuid[10:])
116
-	return node
117
-}
118 1
deleted file mode 100644
... ...
@@ -1,58 +0,0 @@
1
-// Copyright 2015 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"errors"
9
-	"fmt"
10
-)
11
-
12
-// Scan implements sql.Scanner so UUIDs can be read from databases transparently
13
-// Currently, database types that map to string and []byte are supported. Please
14
-// consult database-specific driver documentation for matching types.
15
-func (uuid *UUID) Scan(src interface{}) error {
16
-	switch src.(type) {
17
-	case string:
18
-		// if an empty UUID comes from a table, we return a null UUID
19
-		if src.(string) == "" {
20
-			return nil
21
-		}
22
-
23
-		// see uuid.Parse for required string format
24
-		parsed := Parse(src.(string))
25
-
26
-		if parsed == nil {
27
-			return errors.New("Scan: invalid UUID format")
28
-		}
29
-
30
-		*uuid = parsed
31
-	case []byte:
32
-		b := src.([]byte)
33
-
34
-		// if an empty UUID comes from a table, we return a null UUID
35
-		if len(b) == 0 {
36
-			return nil
37
-		}
38
-
39
-		// assumes a simple slice of bytes if 16 bytes
40
-		// otherwise attempts to parse
41
-		if len(b) == 16 {
42
-			*uuid = UUID(b)
43
-		} else {
44
-			u := Parse(string(b))
45
-
46
-			if u == nil {
47
-				return errors.New("Scan: invalid UUID format")
48
-			}
49
-
50
-			*uuid = u
51
-		}
52
-
53
-	default:
54
-		return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
55
-	}
56
-
57
-	return nil
58
-}
59 1
deleted file mode 100755
... ...
@@ -1,132 +0,0 @@
1
-// Copyright 2014 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"encoding/binary"
9
-	"sync"
10
-	"time"
11
-)
12
-
13
-// A Time represents a time as the number of 100's of nanoseconds since 15 Oct
14
-// 1582.
15
-type Time int64
16
-
17
-const (
18
-	lillian    = 2299160          // Julian day of 15 Oct 1582
19
-	unix       = 2440587          // Julian day of 1 Jan 1970
20
-	epoch      = unix - lillian   // Days between epochs
21
-	g1582      = epoch * 86400    // seconds between epochs
22
-	g1582ns100 = g1582 * 10000000 // 100s of a nanoseconds between epochs
23
-)
24
-
25
-var (
26
-	timeMu    sync.Mutex
27
-	lasttime  uint64 // last time we returned
28
-	clock_seq uint16 // clock sequence for this run
29
-
30
-	timeNow = time.Now // for testing
31
-)
32
-
33
-// UnixTime converts t the number of seconds and nanoseconds using the Unix
34
-// epoch of 1 Jan 1970.
35
-func (t Time) UnixTime() (sec, nsec int64) {
36
-	sec = int64(t - g1582ns100)
37
-	nsec = (sec % 10000000) * 100
38
-	sec /= 10000000
39
-	return sec, nsec
40
-}
41
-
42
-// GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and
43
-// clock sequence as well as adjusting the clock sequence as needed.  An error
44
-// is returned if the current time cannot be determined.
45
-func GetTime() (Time, uint16, error) {
46
-	defer timeMu.Unlock()
47
-	timeMu.Lock()
48
-	return getTime()
49
-}
50
-
51
-func getTime() (Time, uint16, error) {
52
-	t := timeNow()
53
-
54
-	// If we don't have a clock sequence already, set one.
55
-	if clock_seq == 0 {
56
-		setClockSequence(-1)
57
-	}
58
-	now := uint64(t.UnixNano()/100) + g1582ns100
59
-
60
-	// If time has gone backwards with this clock sequence then we
61
-	// increment the clock sequence
62
-	if now <= lasttime {
63
-		clock_seq = ((clock_seq + 1) & 0x3fff) | 0x8000
64
-	}
65
-	lasttime = now
66
-	return Time(now), clock_seq, nil
67
-}
68
-
69
-// ClockSequence returns the current clock sequence, generating one if not
70
-// already set.  The clock sequence is only used for Version 1 UUIDs.
71
-//
72
-// The uuid package does not use global static storage for the clock sequence or
73
-// the last time a UUID was generated.  Unless SetClockSequence a new random
74
-// clock sequence is generated the first time a clock sequence is requested by
75
-// ClockSequence, GetTime, or NewUUID.  (section 4.2.1.1) sequence is generated
76
-// for
77
-func ClockSequence() int {
78
-	defer timeMu.Unlock()
79
-	timeMu.Lock()
80
-	return clockSequence()
81
-}
82
-
83
-func clockSequence() int {
84
-	if clock_seq == 0 {
85
-		setClockSequence(-1)
86
-	}
87
-	return int(clock_seq & 0x3fff)
88
-}
89
-
90
-// SetClockSeq sets the clock sequence to the lower 14 bits of seq.  Setting to
91
-// -1 causes a new sequence to be generated.
92
-func SetClockSequence(seq int) {
93
-	defer timeMu.Unlock()
94
-	timeMu.Lock()
95
-	setClockSequence(seq)
96
-}
97
-
98
-func setClockSequence(seq int) {
99
-	if seq == -1 {
100
-		var b [2]byte
101
-		randomBits(b[:]) // clock sequence
102
-		seq = int(b[0])<<8 | int(b[1])
103
-	}
104
-	old_seq := clock_seq
105
-	clock_seq = uint16(seq&0x3fff) | 0x8000 // Set our variant
106
-	if old_seq != clock_seq {
107
-		lasttime = 0
108
-	}
109
-}
110
-
111
-// Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in
112
-// uuid.  It returns false if uuid is not valid.  The time is only well defined
113
-// for version 1 and 2 UUIDs.
114
-func (uuid UUID) Time() (Time, bool) {
115
-	if len(uuid) != 16 {
116
-		return 0, false
117
-	}
118
-	time := int64(binary.BigEndian.Uint32(uuid[0:4]))
119
-	time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
120
-	time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
121
-	return Time(time), true
122
-}
123
-
124
-// ClockSequence returns the clock sequence encoded in uuid.  It returns false
125
-// if uuid is not valid.  The clock sequence is only well defined for version 1
126
-// and 2 UUIDs.
127
-func (uuid UUID) ClockSequence() (int, bool) {
128
-	if len(uuid) != 16 {
129
-		return 0, false
130
-	}
131
-	return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff, true
132
-}
133 1
deleted file mode 100644
... ...
@@ -1,43 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"io"
9
-)
10
-
11
-// randomBits completely fills slice b with random data.
12
-func randomBits(b []byte) {
13
-	if _, err := io.ReadFull(rander, b); err != nil {
14
-		panic(err.Error()) // rand should never fail
15
-	}
16
-}
17
-
18
-// xvalues returns the value of a byte as a hexadecimal digit or 255.
19
-var xvalues = [256]byte{
20
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
21
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
22
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
23
-	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
24
-	255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
25
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
26
-	255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
27
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
28
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
29
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
30
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
31
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
32
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
33
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
34
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
35
-	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
36
-}
37
-
38
-// xtob converts the the first two hex bytes of x into a byte.
39
-func xtob(x string) (byte, bool) {
40
-	b1 := xvalues[x[0]]
41
-	b2 := xvalues[x[1]]
42
-	return (b1 << 4) | b2, b1 != 255 && b2 != 255
43
-}
44 1
deleted file mode 100644
... ...
@@ -1,176 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"bytes"
9
-	"crypto/rand"
10
-	"encoding/hex"
11
-	"fmt"
12
-	"io"
13
-	"strings"
14
-)
15
-
16
-// A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC
17
-// 4122.
18
-type UUID []byte
19
-
20
-// A Version represents a UUIDs version.
21
-type Version byte
22
-
23
-// A Variant represents a UUIDs variant.
24
-type Variant byte
25
-
26
-// Constants returned by Variant.
27
-const (
28
-	Invalid   = Variant(iota) // Invalid UUID
29
-	RFC4122                   // The variant specified in RFC4122
30
-	Reserved                  // Reserved, NCS backward compatibility.
31
-	Microsoft                 // Reserved, Microsoft Corporation backward compatibility.
32
-	Future                    // Reserved for future definition.
33
-)
34
-
35
-var rander = rand.Reader // random function
36
-
37
-// New returns a new random (version 4) UUID as a string.  It is a convenience
38
-// function for NewRandom().String().
39
-func New() string {
40
-	return NewRandom().String()
41
-}
42
-
43
-// Parse decodes s into a UUID or returns nil.  Both the UUID form of
44
-// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and
45
-// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded.
46
-func Parse(s string) UUID {
47
-	if len(s) == 36+9 {
48
-		if strings.ToLower(s[:9]) != "urn:uuid:" {
49
-			return nil
50
-		}
51
-		s = s[9:]
52
-	} else if len(s) != 36 {
53
-		return nil
54
-	}
55
-	if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
56
-		return nil
57
-	}
58
-	var uuid [16]byte
59
-	for i, x := range [16]int{
60
-		0, 2, 4, 6,
61
-		9, 11,
62
-		14, 16,
63
-		19, 21,
64
-		24, 26, 28, 30, 32, 34} {
65
-		if v, ok := xtob(s[x:]); !ok {
66
-			return nil
67
-		} else {
68
-			uuid[i] = v
69
-		}
70
-	}
71
-	return uuid[:]
72
-}
73
-
74
-// Equal returns true if uuid1 and uuid2 are equal.
75
-func Equal(uuid1, uuid2 UUID) bool {
76
-	return bytes.Equal(uuid1, uuid2)
77
-}
78
-
79
-// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
80
-// , or "" if uuid is invalid.
81
-func (uuid UUID) String() string {
82
-	if len(uuid) != 16 {
83
-		return ""
84
-	}
85
-	var buf [36]byte
86
-	encodeHex(buf[:], uuid)
87
-	return string(buf[:])
88
-}
89
-
90
-// URN returns the RFC 2141 URN form of uuid,
91
-// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,  or "" if uuid is invalid.
92
-func (uuid UUID) URN() string {
93
-	if len(uuid) != 16 {
94
-		return ""
95
-	}
96
-	var buf [36 + 9]byte
97
-	copy(buf[:], "urn:uuid:")
98
-	encodeHex(buf[9:], uuid)
99
-	return string(buf[:])
100
-}
101
-
102
-func encodeHex(dst []byte, uuid UUID) {
103
-	hex.Encode(dst[:], uuid[:4])
104
-	dst[8] = '-'
105
-	hex.Encode(dst[9:13], uuid[4:6])
106
-	dst[13] = '-'
107
-	hex.Encode(dst[14:18], uuid[6:8])
108
-	dst[18] = '-'
109
-	hex.Encode(dst[19:23], uuid[8:10])
110
-	dst[23] = '-'
111
-	hex.Encode(dst[24:], uuid[10:])
112
-}
113
-
114
-// Variant returns the variant encoded in uuid.  It returns Invalid if
115
-// uuid is invalid.
116
-func (uuid UUID) Variant() Variant {
117
-	if len(uuid) != 16 {
118
-		return Invalid
119
-	}
120
-	switch {
121
-	case (uuid[8] & 0xc0) == 0x80:
122
-		return RFC4122
123
-	case (uuid[8] & 0xe0) == 0xc0:
124
-		return Microsoft
125
-	case (uuid[8] & 0xe0) == 0xe0:
126
-		return Future
127
-	default:
128
-		return Reserved
129
-	}
130
-}
131
-
132
-// Version returns the version of uuid.  It returns false if uuid is not
133
-// valid.
134
-func (uuid UUID) Version() (Version, bool) {
135
-	if len(uuid) != 16 {
136
-		return 0, false
137
-	}
138
-	return Version(uuid[6] >> 4), true
139
-}
140
-
141
-func (v Version) String() string {
142
-	if v > 15 {
143
-		return fmt.Sprintf("BAD_VERSION_%d", v)
144
-	}
145
-	return fmt.Sprintf("VERSION_%d", v)
146
-}
147
-
148
-func (v Variant) String() string {
149
-	switch v {
150
-	case RFC4122:
151
-		return "RFC4122"
152
-	case Reserved:
153
-		return "Reserved"
154
-	case Microsoft:
155
-		return "Microsoft"
156
-	case Future:
157
-		return "Future"
158
-	case Invalid:
159
-		return "Invalid"
160
-	}
161
-	return fmt.Sprintf("BadVariant%d", int(v))
162
-}
163
-
164
-// SetRand sets the random number generator to r, which implents io.Reader.
165
-// If r.Read returns an error when the package requests random data then
166
-// a panic will be issued.
167
-//
168
-// Calling SetRand with nil sets the random number generator to the default
169
-// generator.
170
-func SetRand(r io.Reader) {
171
-	if r == nil {
172
-		rander = rand.Reader
173
-		return
174
-	}
175
-	rander = r
176
-}
177 1
deleted file mode 100644
... ...
@@ -1,41 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-import (
8
-	"encoding/binary"
9
-)
10
-
11
-// NewUUID returns a Version 1 UUID based on the current NodeID and clock
12
-// sequence, and the current time.  If the NodeID has not been set by SetNodeID
13
-// or SetNodeInterface then it will be set automatically.  If the NodeID cannot
14
-// be set NewUUID returns nil.  If clock sequence has not been set by
15
-// SetClockSequence then it will be set automatically.  If GetTime fails to
16
-// return the current NewUUID returns nil.
17
-func NewUUID() UUID {
18
-	if nodeID == nil {
19
-		SetNodeInterface("")
20
-	}
21
-
22
-	now, seq, err := GetTime()
23
-	if err != nil {
24
-		return nil
25
-	}
26
-
27
-	uuid := make([]byte, 16)
28
-
29
-	time_low := uint32(now & 0xffffffff)
30
-	time_mid := uint16((now >> 32) & 0xffff)
31
-	time_hi := uint16((now >> 48) & 0x0fff)
32
-	time_hi |= 0x1000 // Version 1
33
-
34
-	binary.BigEndian.PutUint32(uuid[0:], time_low)
35
-	binary.BigEndian.PutUint16(uuid[4:], time_mid)
36
-	binary.BigEndian.PutUint16(uuid[6:], time_hi)
37
-	binary.BigEndian.PutUint16(uuid[8:], seq)
38
-	copy(uuid[10:], nodeID)
39
-
40
-	return uuid
41
-}
42 1
deleted file mode 100644
... ...
@@ -1,25 +0,0 @@
1
-// Copyright 2011 Google Inc.  All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package uuid
6
-
7
-// Random returns a Random (Version 4) UUID or panics.
8
-//
9
-// The strength of the UUIDs is based on the strength of the crypto/rand
10
-// package.
11
-//
12
-// A note about uniqueness derived from from the UUID Wikipedia entry:
13
-//
14
-//  Randomly generated UUIDs have 122 random bits.  One's annual risk of being
15
-//  hit by a meteorite is estimated to be one chance in 17 billion, that
16
-//  means the probability is about 0.00000000006 (6 × 10−11),
17
-//  equivalent to the odds of creating a few tens of trillions of UUIDs in a
18
-//  year and having one duplicate.
19
-func NewRandom() UUID {
20
-	uuid := make([]byte, 16)
21
-	randomBits([]byte(uuid))
22
-	uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
23
-	uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10
24
-	return uuid
25
-}