replace go-psutil with go-sysinfo
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Dec 29, 2015 at 07:26 UTC
b5ef584f40cab4d579d608f101ad067c66332ed0
144 files changed
+150
-11735
Godeps/Godeps.json
+4
-36
@@ -14,10 +14,6 @@
14
"Comment": "null-5",
15
"Rev": "75cd24fc2f2c2a2088577d12123ddee5f54e0675"
16
},
17
- {
18
- "ImportPath": "github.com/StackExchange/wmi",
19
- "Rev": "8730d7ed549382cb1f889a576a7223c137be7989"
20
- },
17
{
18
"ImportPath": "github.com/alecthomas/kingpin",
19
"Comment": "v2.1.0-2-gaedd543",
@@ -115,11 +111,6 @@
111
"ImportPath": "github.com/fd/go-nat",
112
"Rev": "50e7633d5f27d81490026a13e5b92d2e42d8c6bb"
113
},
118
- {
119
- "ImportPath": "github.com/go-ole/go-ole",
120
- "Comment": "v1.1.1-64-g4246eab",
121
- "Rev": "4246eab2a27c71c143f965432ace52990308d362"
122
- },
114
{
115
"ImportPath": "github.com/gogo/protobuf/io",
116
"Rev": "0ac967c269268f1af7d9bcc7927ccc9a589b2b36"
@@ -144,10 +135,6 @@
135
"ImportPath": "github.com/huin/goupnp",
136
"Rev": "223008361153d7d434c1f0ac990cd3fcae6931f5"
137
},
147
- {
148
- "ImportPath": "github.com/inconshreveable/go-update",
149
- "Rev": "68f5725818189545231c1fd8694793d45f2fc529"
150
- },
138
{
139
"ImportPath": "github.com/jackpal/go-nat-pmp",
140
"Rev": "a45aa3d54aef73b504e15eb71bea0e5565b5e6e1"
@@ -234,14 +221,6 @@
221
"ImportPath": "github.com/jbenet/goprocess",
222
"Rev": "64a8220330a485070813201cc05b0c6777f6a516"
223
},
237
- {
238
- "ImportPath": "github.com/kardianos/osext",
239
- "Rev": "8fef92e41e22a70e700a96b29f066cda30ea24ef"
240
- },
241
- {
242
- "ImportPath": "github.com/kr/binarydist",
243
- "Rev": "9955b0ab8708602d411341e55fffd7e0700f86bd"
244
- },
224
{
225
"ImportPath": "github.com/matttproud/golang_protobuf_extensions/pbutil",
226
"Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a"
@@ -294,21 +273,6 @@
273
"ImportPath": "github.com/satori/go.uuid",
274
"Rev": "7c7f2020c4c9491594b85767967f4619c2fa75f9"
275
},
297
- {
298
- "ImportPath": "github.com/shirou/gopsutil/common",
299
- "Comment": "1.0.0-167-g6a274c3",
300
- "Rev": "6a274c3628382ab316340478300f5282b89f7778"
301
- },
302
- {
303
- "ImportPath": "github.com/shirou/gopsutil/disk",
304
- "Comment": "1.0.0-167-g6a274c3",
305
- "Rev": "6a274c3628382ab316340478300f5282b89f7778"
306
- },
307
- {
308
- "ImportPath": "github.com/shirou/gopsutil/mem",
309
- "Comment": "1.0.0-167-g6a274c3",
310
- "Rev": "6a274c3628382ab316340478300f5282b89f7778"
311
- },
276
{
277
"ImportPath": "github.com/steakknife/hamming",
278
"Comment": "0.0.10",
@@ -346,6 +310,10 @@
310
"ImportPath": "github.com/whyrusleeping/go-multistream",
311
"Rev": "31bb014803a6eba2261bda5593e42c016a5f33bb"
312
},
313
+ {
314
+ "ImportPath": "github.com/whyrusleeping/go-sysinfo",
315
+ "Rev": "769b7c0b50e8030895abc74ba8107ac715e3162a"
316
+ },
317
{
318
"ImportPath": "github.com/whyrusleeping/multiaddr-filter",
319
"Rev": "9e26222151125ecd3fc1fd190179b6bdd55f5608"
Godeps/_workspace/src/github.com/StackExchange/wmi/LICENSE
deleted
-20
@@ -1,20 +0,0 @@
1
-The MIT License (MIT)
2
-
3
-Copyright (c) 2013 Stack Exchange
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy of
6
-this software and associated documentation files (the "Software"), to deal in
7
-the Software without restriction, including without limitation the rights to
8
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
-the Software, and to permit persons to whom the Software is furnished to do so,
10
-subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in all
13
-copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Godeps/_workspace/src/github.com/StackExchange/wmi/README.md
deleted
-4
@@ -1,4 +0,0 @@
1
-wmi
2
-===
3
-
4
-Package wmi provides a WQL interface for WMI on Windows.
Godeps/_workspace/src/github.com/StackExchange/wmi/wmi.go
deleted
-416
@@ -1,416 +0,0 @@
1
-// +build windows
2
-
3
-/*
4
-Package wmi provides a WQL interface for WMI on Windows.
5
-
6
-Example code to print names of running processes:
7
-
8
- type Win32_Process struct {
9
- Name string
10
- }
11
-
12
- func main() {
13
- var dst []Win32_Process
14
- q := wmi.CreateQuery(&dst, "")
15
- err := wmi.Query(q, &dst)
16
- if err != nil {
17
- log.Fatal(err)
18
- }
19
- for i, v := range dst {
20
- println(i, v.Name)
21
- }
22
- }
23
-
24
-*/
25
-package wmi
26
-
27
-import (
28
- "bytes"
29
- "errors"
30
- "fmt"
31
- "log"
32
- "os"
33
- "reflect"
34
- "runtime"
35
- "strconv"
36
- "strings"
37
- "sync"
38
- "time"
39
-
40
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
41
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
42
-)
43
-
44
-var l = log.New(os.Stdout, "", log.LstdFlags)
45
-
46
-var (
47
- ErrInvalidEntityType = errors.New("wmi: invalid entity type")
48
- lock sync.Mutex
49
-)
50
-
51
-// QueryNamespace invokes Query with the given namespace on the local machine.
52
-func QueryNamespace(query string, dst interface{}, namespace string) error {
53
- return Query(query, dst, nil, namespace)
54
-}
55
-
56
-// Query runs the WQL query and appends the values to dst.
57
-//
58
-// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in
59
-// the query must have the same name in dst. Supported types are all signed and
60
-// unsigned integers, time.Time, string, bool, or a pointer to one of those.
61
-// Array types are not supported.
62
-//
63
-// By default, the local machine and default namespace are used. These can be
64
-// changed using connectServerArgs. See
65
-// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
66
-//
67
-// Query is a wrapper around DefaultClient.Query.
68
-func Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
69
- return DefaultClient.Query(query, dst, connectServerArgs...)
70
-}
71
-
72
-// A Client is an WMI query client.
73
-//
74
-// Its zero value (DefaultClient) is a usable client.
75
-type Client struct {
76
- // NonePtrZero specifies if nil values for fields which aren't pointers
77
- // should be returned as the field types zero value.
78
- //
79
- // Setting this to true allows stucts without pointer fields to be used
80
- // without the risk failure should a nil value returned from WMI.
81
- NonePtrZero bool
82
-
83
- // PtrNil specifies if nil values for pointer fields should be returned
84
- // as nil.
85
- //
86
- // Setting this to true will set pointer fields to nil where WMI
87
- // returned nil, otherwise the types zero value will be returned.
88
- PtrNil bool
89
-
90
- // AllowMissingFields specifies that struct fields not present in the
91
- // query result should not result in an error.
92
- //
93
- // Setting this to true allows custom queries to be used with full
94
- // struct definitions instead of having to define multiple structs.
95
- AllowMissingFields bool
96
-}
97
-
98
-// DefaultClient is the default Client and is used by Query, QueryNamespace
99
-var DefaultClient = &Client{}
100
-
101
-// Query runs the WQL query and appends the values to dst.
102
-//
103
-// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in
104
-// the query must have the same name in dst. Supported types are all signed and
105
-// unsigned integers, time.Time, string, bool, or a pointer to one of those.
106
-// Array types are not supported.
107
-//
108
-// By default, the local machine and default namespace are used. These can be
109
-// changed using connectServerArgs. See
110
-// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
111
-func (c *Client) Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
112
- dv := reflect.ValueOf(dst)
113
- if dv.Kind() != reflect.Ptr || dv.IsNil() {
114
- return ErrInvalidEntityType
115
- }
116
- dv = dv.Elem()
117
- mat, elemType := checkMultiArg(dv)
118
- if mat == multiArgTypeInvalid {
119
- return ErrInvalidEntityType
120
- }
121
-
122
- lock.Lock()
123
- defer lock.Unlock()
124
- runtime.LockOSThread()
125
- defer runtime.UnlockOSThread()
126
-
127
- err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
128
- if err != nil {
129
- oleerr := err.(*ole.OleError)
130
- // S_FALSE = 0x00000001 // CoInitializeEx was already called on this thread
131
- if oleerr.Code() != ole.S_OK && oleerr.Code() != 0x00000001 {
132
- return err
133
- }
134
- } else {
135
- // Only invoke CoUninitialize if the thread was not initizlied before.
136
- // This will allow other go packages based on go-ole play along
137
- // with this library.
138
- defer ole.CoUninitialize()
139
- }
140
-
141
- unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
142
- if err != nil {
143
- return err
144
- }
145
- defer unknown.Release()
146
-
147
- wmi, err := unknown.QueryInterface(ole.IID_IDispatch)
148
- if err != nil {
149
- return err
150
- }
151
- defer wmi.Release()
152
-
153
- // service is a SWbemServices
154
- serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer", connectServerArgs...)
155
- if err != nil {
156
- return err
157
- }
158
- service := serviceRaw.ToIDispatch()
159
- defer serviceRaw.Clear()
160
-
161
- // result is a SWBemObjectSet
162
- resultRaw, err := oleutil.CallMethod(service, "ExecQuery", query)
163
- if err != nil {
164
- return err
165
- }
166
- result := resultRaw.ToIDispatch()
167
- defer resultRaw.Clear()
168
-
169
- count, err := oleInt64(result, "Count")
170
- if err != nil {
171
- return err
172
- }
173
-
174
- // Initialize a slice with Count capacity
175
- dv.Set(reflect.MakeSlice(dv.Type(), 0, int(count)))
176
-
177
- var errFieldMismatch error
178
- for i := int64(0); i < count; i++ {
179
- err := func() error {
180
- // item is a SWbemObject, but really a Win32_Process
181
- itemRaw, err := oleutil.CallMethod(result, "ItemIndex", i)
182
- if err != nil {
183
- return err
184
- }
185
- item := itemRaw.ToIDispatch()
186
- defer itemRaw.Clear()
187
-
188
- ev := reflect.New(elemType)
189
- if err = c.loadEntity(ev.Interface(), item); err != nil {
190
- if _, ok := err.(*ErrFieldMismatch); ok {
191
- // We continue loading entities even in the face of field mismatch errors.
192
- // If we encounter any other error, that other error is returned. Otherwise,
193
- // an ErrFieldMismatch is returned.
194
- errFieldMismatch = err
195
- } else {
196
- return err
197
- }
198
- }
199
- if mat != multiArgTypeStructPtr {
200
- ev = ev.Elem()
201
- }
202
- dv.Set(reflect.Append(dv, ev))
203
- return nil
204
- }()
205
- if err != nil {
206
- return err
207
- }
208
- }
209
- return errFieldMismatch
210
-}
211
-
212
-// ErrFieldMismatch is returned when a field is to be loaded into a different
213
-// type than the one it was stored from, or when a field is missing or
214
-// unexported in the destination struct.
215
-// StructType is the type of the struct pointed to by the destination argument.
216
-type ErrFieldMismatch struct {
217
- StructType reflect.Type
218
- FieldName string
219
- Reason string
220
-}
221
-
222
-func (e *ErrFieldMismatch) Error() string {
223
- return fmt.Sprintf("wmi: cannot load field %q into a %q: %s",
224
- e.FieldName, e.StructType, e.Reason)
225
-}
226
-
227
-var timeType = reflect.TypeOf(time.Time{})
228
-
229
-// loadEntity loads a SWbemObject into a struct pointer.
230
-func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismatch error) {
231
- v := reflect.ValueOf(dst).Elem()
232
- for i := 0; i < v.NumField(); i++ {
233
- f := v.Field(i)
234
- of := f
235
- isPtr := f.Kind() == reflect.Ptr
236
- if isPtr {
237
- ptr := reflect.New(f.Type().Elem())
238
- f.Set(ptr)
239
- f = f.Elem()
240
- }
241
- n := v.Type().Field(i).Name
242
- if !f.CanSet() {
243
- return &ErrFieldMismatch{
244
- StructType: of.Type(),
245
- FieldName: n,
246
- Reason: "CanSet() is false",
247
- }
248
- }
249
- prop, err := oleutil.GetProperty(src, n)
250
- if err != nil {
251
- if !c.AllowMissingFields {
252
- errFieldMismatch = &ErrFieldMismatch{
253
- StructType: of.Type(),
254
- FieldName: n,
255
- Reason: "no such struct field",
256
- }
257
- }
258
- continue
259
- }
260
- defer prop.Clear()
261
-
262
- switch val := prop.Value().(type) {
263
- case int8, int16, int32, int64, int:
264
- v := reflect.ValueOf(val).Int()
265
- switch f.Kind() {
266
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
267
- f.SetInt(v)
268
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
269
- f.SetUint(uint64(v))
270
- default:
271
- return &ErrFieldMismatch{
272
- StructType: of.Type(),
273
- FieldName: n,
274
- Reason: "not an integer class",
275
- }
276
- }
277
- case uint8, uint16, uint32, uint64:
278
- v := reflect.ValueOf(val).Uint()
279
- switch f.Kind() {
280
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
281
- f.SetInt(int64(v))
282
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
283
- f.SetUint(v)
284
- default:
285
- return &ErrFieldMismatch{
286
- StructType: of.Type(),
287
- FieldName: n,
288
- Reason: "not an integer class",
289
- }
290
- }
291
- case string:
292
- switch f.Kind() {
293
- case reflect.String:
294
- f.SetString(val)
295
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
296
- iv, err := strconv.ParseInt(val, 10, 64)
297
- if err != nil {
298
- return err
299
- }
300
- f.SetInt(iv)
301
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
302
- uv, err := strconv.ParseUint(val, 10, 64)
303
- if err != nil {
304
- return err
305
- }
306
- f.SetUint(uv)
307
- case reflect.Struct:
308
- switch f.Type() {
309
- case timeType:
310
- if len(val) == 25 {
311
- mins, err := strconv.Atoi(val[22:])
312
- if err != nil {
313
- return err
314
- }
315
- val = val[:22] + fmt.Sprintf("%02d%02d", mins/60, mins%60)
316
- }
317
- t, err := time.Parse("20060102150405.000000-0700", val)
318
- if err != nil {
319
- return err
320
- }
321
- f.Set(reflect.ValueOf(t))
322
- }
323
- }
324
- case bool:
325
- switch f.Kind() {
326
- case reflect.Bool:
327
- f.SetBool(val)
328
- default:
329
- return &ErrFieldMismatch{
330
- StructType: of.Type(),
331
- FieldName: n,
332
- Reason: "not a bool",
333
- }
334
- }
335
- default:
336
- typeof := reflect.TypeOf(val)
337
- if typeof == nil && (isPtr || c.NonePtrZero) {
338
- if (isPtr && c.PtrNil) || (!isPtr && c.NonePtrZero) {
339
- of.Set(reflect.Zero(of.Type()))
340
- }
341
- break
342
- }
343
- return &ErrFieldMismatch{
344
- StructType: of.Type(),
345
- FieldName: n,
346
- Reason: fmt.Sprintf("unsupported type (%T)", val),
347
- }
348
- }
349
- }
350
- return errFieldMismatch
351
-}
352
-
353
-type multiArgType int
354
-
355
-const (
356
- multiArgTypeInvalid multiArgType = iota
357
- multiArgTypeStruct
358
- multiArgTypeStructPtr
359
-)
360
-
361
-// checkMultiArg checks that v has type []S, []*S for some struct type S.
362
-//
363
-// It returns what category the slice's elements are, and the reflect.Type
364
-// that represents S.
365
-func checkMultiArg(v reflect.Value) (m multiArgType, elemType reflect.Type) {
366
- if v.Kind() != reflect.Slice {
367
- return multiArgTypeInvalid, nil
368
- }
369
- elemType = v.Type().Elem()
370
- switch elemType.Kind() {
371
- case reflect.Struct:
372
- return multiArgTypeStruct, elemType
373
- case reflect.Ptr:
374
- elemType = elemType.Elem()
375
- if elemType.Kind() == reflect.Struct {
376
- return multiArgTypeStructPtr, elemType
377
- }
378
- }
379
- return multiArgTypeInvalid, nil
380
-}
381
-
382
-func oleInt64(item *ole.IDispatch, prop string) (int64, error) {
383
- v, err := oleutil.GetProperty(item, prop)
384
- if err != nil {
385
- return 0, err
386
- }
387
- defer v.Clear()
388
-
389
- i := int64(v.Val)
390
- return i, nil
391
-}
392
-
393
-// CreateQuery returns a WQL query string that queries all columns of src. where
394
-// is an optional string that is appended to the query, to be used with WHERE
395
-// clauses. In such a case, the "WHERE" string should appear at the beginning.
396
-func CreateQuery(src interface{}, where string) string {
397
- var b bytes.Buffer
398
- b.WriteString("SELECT ")
399
- s := reflect.Indirect(reflect.ValueOf(src))
400
- t := s.Type()
401
- if s.Kind() == reflect.Slice {
402
- t = t.Elem()
403
- }
404
- if t.Kind() != reflect.Struct {
405
- return ""
406
- }
407
- var fields []string
408
- for i := 0; i < t.NumField(); i++ {
409
- fields = append(fields, t.Field(i).Name)
410
- }
411
- b.WriteString(strings.Join(fields, ", "))
412
- b.WriteString(" FROM ")
413
- b.WriteString(t.Name())
414
- b.WriteString(" " + where)
415
- return b.String()
416
-}
Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_test.go
deleted
-316
@@ -1,316 +0,0 @@
1
-// +build windows
2
-
3
-package wmi
4
-
5
-import (
6
- "encoding/json"
7
- "fmt"
8
- "reflect"
9
- "runtime"
10
- "runtime/debug"
11
- "sync"
12
- "testing"
13
- "time"
14
-)
15
-
16
-func TestQuery(t *testing.T) {
17
- var dst []Win32_Process
18
- q := CreateQuery(&dst, "")
19
- err := Query(q, &dst)
20
- if err != nil {
21
- t.Fatal(err)
22
- }
23
-}
24
-
25
-func TestFieldMismatch(t *testing.T) {
26
- type s struct {
27
- Name string
28
- HandleCount uint32
29
- Blah uint32
30
- }
31
- var dst []s
32
- err := Query("SELECT Name, HandleCount FROM Win32_Process", &dst)
33
- if err == nil || err.Error() != `wmi: cannot load field "Blah" into a "uint32": no such struct field` {
34
- t.Error("Expected err field mismatch")
35
- }
36
-}
37
-
38
-func TestStrings(t *testing.T) {
39
- printed := false
40
- f := func() {
41
- var dst []Win32_Process
42
- zeros := 0
43
- q := CreateQuery(&dst, "")
44
- for i := 0; i < 5; i++ {
45
- err := Query(q, &dst)
46
- if err != nil {
47
- t.Fatal(err, q)
48
- }
49
- for _, d := range dst {
50
- v := reflect.ValueOf(d)
51
- for j := 0; j < v.NumField(); j++ {
52
- f := v.Field(j)
53
- if f.Kind() != reflect.String {
54
- continue
55
- }
56
- s := f.Interface().(string)
57
- if len(s) > 0 && s[0] == '\u0000' {
58
- zeros++
59
- if !printed {
60
- printed = true
61
- j, _ := json.MarshalIndent(&d, "", " ")
62
- t.Log("Example with \\u0000:\n", string(j))
63
- }
64
- }
65
- }
66
- }
67
- fmt.Println("iter", i, "zeros:", zeros)
68
- }
69
- if zeros > 0 {
70
- t.Error("> 0 zeros")
71
- }
72
- }
73
-
74
- fmt.Println("Disabling GC")
75
- debug.SetGCPercent(-1)
76
- f()
77
- fmt.Println("Enabling GC")
78
- debug.SetGCPercent(100)
79
- f()
80
-}
81
-
82
-func TestNamespace(t *testing.T) {
83
- var dst []Win32_Process
84
- q := CreateQuery(&dst, "")
85
- err := QueryNamespace(q, &dst, `root\CIMV2`)
86
- if err != nil {
87
- t.Fatal(err)
88
- }
89
- dst = nil
90
- err = QueryNamespace(q, &dst, `broken\nothing`)
91
- if err == nil {
92
- t.Fatal("expected error")
93
- }
94
-}
95
-
96
-func TestCreateQuery(t *testing.T) {
97
- type TestStruct struct {
98
- Name string
99
- Count int
100
- }
101
- var dst []TestStruct
102
- output := "SELECT Name, Count FROM TestStruct WHERE Count > 2"
103
- tests := []interface{}{
104
- &dst,
105
- dst,
106
- TestStruct{},
107
- &TestStruct{},
108
- }
109
- for i, test := range tests {
110
- if o := CreateQuery(test, "WHERE Count > 2"); o != output {
111
- t.Error("bad output on", i, o)
112
- }
113
- }
114
- if CreateQuery(3, "") != "" {
115
- t.Error("expected empty string")
116
- }
117
-}
118
-
119
-func _TestMany(t *testing.T) {
120
- limit := 5000
121
- fmt.Println("running until:", limit)
122
- fmt.Println("No panics mean it succeeded. Other errors are OK.")
123
- runtime.GOMAXPROCS(2)
124
- wg := sync.WaitGroup{}
125
- wg.Add(2)
126
- go func() {
127
- for i := 0; i < limit; i++ {
128
- if i%25 == 0 {
129
- fmt.Println(i)
130
- }
131
- var dst []Win32_PerfRawData_PerfDisk_LogicalDisk
132
- q := CreateQuery(&dst, "")
133
- err := Query(q, &dst)
134
- if err != nil {
135
- fmt.Println("ERROR disk", err)
136
- }
137
- }
138
- wg.Done()
139
- }()
140
- go func() {
141
- for i := 0; i > -limit; i-- {
142
- if i%25 == 0 {
143
- fmt.Println(i)
144
- }
145
- var dst []Win32_OperatingSystem
146
- q := CreateQuery(&dst, "")
147
- err := Query(q, &dst)
148
- if err != nil {
149
- fmt.Println("ERROR OS", err)
150
- }
151
- }
152
- wg.Done()
153
- }()
154
- wg.Wait()
155
-}
156
-
157
-type Win32_Process struct {
158
- CSCreationClassName string
159
- CSName string
160
- Caption *string
161
- CommandLine *string
162
- CreationClassName string
163
- CreationDate *time.Time
164
- Description *string
165
- ExecutablePath *string
166
- ExecutionState *uint16
167
- Handle string
168
- HandleCount uint32
169
- InstallDate *time.Time
170
- KernelModeTime uint64
171
- MaximumWorkingSetSize *uint32
172
- MinimumWorkingSetSize *uint32
173
- Name string
174
- OSCreationClassName string
175
- OSName string
176
- OtherOperationCount uint64
177
- OtherTransferCount uint64
178
- PageFaults uint32
179
- PageFileUsage uint32
180
- ParentProcessId uint32
181
- PeakPageFileUsage uint32
182
- PeakVirtualSize uint64
183
- PeakWorkingSetSize uint32
184
- Priority uint32
185
- PrivatePageCount uint64
186
- ProcessId uint32
187
- QuotaNonPagedPoolUsage uint32
188
- QuotaPagedPoolUsage uint32
189
- QuotaPeakNonPagedPoolUsage uint32
190
- QuotaPeakPagedPoolUsage uint32
191
- ReadOperationCount uint64
192
- ReadTransferCount uint64
193
- SessionId uint32
194
- Status *string
195
- TerminationDate *time.Time
196
- ThreadCount uint32
197
- UserModeTime uint64
198
- VirtualSize uint64
199
- WindowsVersion string
200
- WorkingSetSize uint64
201
- WriteOperationCount uint64
202
- WriteTransferCount uint64
203
-}
204
-
205
-type Win32_PerfRawData_PerfDisk_LogicalDisk struct {
206
- AvgDiskBytesPerRead uint64
207
- AvgDiskBytesPerRead_Base uint32
208
- AvgDiskBytesPerTransfer uint64
209
- AvgDiskBytesPerTransfer_Base uint32
210
- AvgDiskBytesPerWrite uint64
211
- AvgDiskBytesPerWrite_Base uint32
212
- AvgDiskQueueLength uint64
213
- AvgDiskReadQueueLength uint64
214
- AvgDiskSecPerRead uint32
215
- AvgDiskSecPerRead_Base uint32
216
- AvgDiskSecPerTransfer uint32
217
- AvgDiskSecPerTransfer_Base uint32
218
- AvgDiskSecPerWrite uint32
219
- AvgDiskSecPerWrite_Base uint32
220
- AvgDiskWriteQueueLength uint64
221
- Caption *string
222
- CurrentDiskQueueLength uint32
223
- Description *string
224
- DiskBytesPerSec uint64
225
- DiskReadBytesPerSec uint64
226
- DiskReadsPerSec uint32
227
- DiskTransfersPerSec uint32
228
- DiskWriteBytesPerSec uint64
229
- DiskWritesPerSec uint32
230
- FreeMegabytes uint32
231
- Frequency_Object uint64
232
- Frequency_PerfTime uint64
233
- Frequency_Sys100NS uint64
234
- Name string
235
- PercentDiskReadTime uint64
236
- PercentDiskReadTime_Base uint64
237
- PercentDiskTime uint64
238
- PercentDiskTime_Base uint64
239
- PercentDiskWriteTime uint64
240
- PercentDiskWriteTime_Base uint64
241
- PercentFreeSpace uint32
242
- PercentFreeSpace_Base uint32
243
- PercentIdleTime uint64
244
- PercentIdleTime_Base uint64
245
- SplitIOPerSec uint32
246
- Timestamp_Object uint64
247
- Timestamp_PerfTime uint64
248
- Timestamp_Sys100NS uint64
249
-}
250
-
251
-type Win32_OperatingSystem struct {
252
- BootDevice string
253
- BuildNumber string
254
- BuildType string
255
- Caption *string
256
- CodeSet string
257
- CountryCode string
258
- CreationClassName string
259
- CSCreationClassName string
260
- CSDVersion *string
261
- CSName string
262
- CurrentTimeZone int16
263
- DataExecutionPrevention_Available bool
264
- DataExecutionPrevention_32BitApplications bool
265
- DataExecutionPrevention_Drivers bool
266
- DataExecutionPrevention_SupportPolicy *uint8
267
- Debug bool
268
- Description *string
269
- Distributed bool
270
- EncryptionLevel uint32
271
- ForegroundApplicationBoost *uint8
272
- FreePhysicalMemory uint64
273
- FreeSpaceInPagingFiles uint64
274
- FreeVirtualMemory uint64
275
- InstallDate time.Time
276
- LargeSystemCache *uint32
277
- LastBootUpTime time.Time
278
- LocalDateTime time.Time
279
- Locale string
280
- Manufacturer string
281
- MaxNumberOfProcesses uint32
282
- MaxProcessMemorySize uint64
283
- MUILanguages *[]string
284
- Name string
285
- NumberOfLicensedUsers *uint32
286
- NumberOfProcesses uint32
287
- NumberOfUsers uint32
288
- OperatingSystemSKU uint32
289
- Organization string
290
- OSArchitecture string
291
- OSLanguage uint32
292
- OSProductSuite uint32
293
- OSType uint16
294
- OtherTypeDescription *string
295
- PAEEnabled *bool
296
- PlusProductID *string
297
- PlusVersionNumber *string
298
- PortableOperatingSystem bool
299
- Primary bool
300
- ProductType uint32
301
- RegisteredUser string
302
- SerialNumber string
303
- ServicePackMajorVersion uint16
304
- ServicePackMinorVersion uint16
305
- SizeStoredInPagingFiles uint64
306
- Status string
307
- SuiteMask uint32
308
- SystemDevice string
309
- SystemDirectory string
310
- SystemDrive string
311
- TotalSwapSpaceSize *uint64
312
- TotalVirtualMemorySize uint64
313
- TotalVisibleMemorySize uint64
314
- Version string
315
- WindowsDirectory string
316
-}
Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_unix.go
deleted
-1
@@ -1 +0,0 @@
1
-package wmi
Godeps/_workspace/src/github.com/go-ole/go-ole/.travis.yml
deleted
-9
@@ -1,9 +0,0 @@
1
-language: go
2
-sudo: false
3
-
4
-go:
5
- - 1.1
6
- - 1.2
7
- - 1.3
8
- - 1.4
9
- - tip
Godeps/_workspace/src/github.com/go-ole/go-ole/ChangeLog.md
deleted
-48
@@ -1,48 +0,0 @@
1
-# Version 1.x.x
2
-
3
-* **Add more test cases and reference new test COM server project.** (Placeholder for future additions)
4
-
5
-# Version 1.2.0-alphaX
6
-
7
-**Minimum supported version is now Go 1.4. Go 1.1 support is deprecated, but should still build.**
8
-
9
- * Added CI configuration for Travis-CI and AppVeyor.
10
- * Added test InterfaceID and ClassID for the COM Test Server project.
11
- * Added more inline documentation (#83).
12
- * Added IEnumVARIANT implementation (#88).
13
- * Added support for retrieving `time.Time` from VARIANT (#92).
14
- * Added test case for IUnknown (#64).
15
- * Added test case for IDispatch (#64).
16
- * Added test cases for scalar variants (#64, #76).
17
-
18
-# Version 1.1.1
19
-
20
- * Fixes for Linux build.
21
- * Fixes for Windows build.
22
-
23
-# Version 1.1.0
24
-
25
-The change to provide building on all platforms is a new feature. The increase in minor version reflects that and allows those who wish to stay on 1.0.x to continue to do so. Support for 1.0.x will be limited to bug fixes.
26
-
27
- * Move GUID out of variables.go into its own file to make new documentation available.
28
- * Move OleError out of ole.go into its own file to make new documentation available.
29
- * Add documentation to utility functions.
30
- * Add documentation to variant receiver functions.
31
- * Add documentation to ole structures.
32
- * Make variant available to other systems outside of Windows.
33
- * Make OLE structures available to other systems outside of Windows.
34
-
35
-## New Features
36
-
37
- * Library should now be built on all platforms supported by Go. Library will NOOP on any platform that is not Windows.
38
- * More functions are now documented and available on godoc.org.
39
-
40
-# Version 1.0.1
41
-
42
- 1. Fix package references from repository location change.
43
-
44
-# Version 1.0.0
45
-
46
-This version is stable enough for use. The COM API is still incomplete, but provides enough functionality for accessing COM servers using IDispatch interface.
47
-
48
-There is no changelog for this version. Check commits for history.
Godeps/_workspace/src/github.com/go-ole/go-ole/README.md
deleted
-46
@@ -1,46 +0,0 @@
1
-#Go OLE
2
-
3
-[](https://ci.appveyor.com/project/jacobsantos/go-ole-jgs28)
4
-[](https://travis-ci.org/go-ole/go-ole)
5
-[](https://godoc.org/github.com/go-ole/go-ole)
6
-
7
-Go bindings for Windows COM using shared libraries instead of cgo.
8
-
9
-By Yasuhiro Matsumoto.
10
-
11
-## Install
12
-
13
-To experiment with go-ole, you can just compile and run the example program:
14
-
15
-```
16
-go get github.com/go-ole/go-ole
17
-cd /path/to/go-ole/
18
-go test
19
-
20
-cd /path/to/go-ole/example/excel
21
-go run excel.go
22
-```
23
-
24
-## Continuous Integration
25
-
26
-Continuous integration configuration has been added for both Travis-CI and AppVeyor. You will have to add these to your own account for your fork in order for it to run.
27
-
28
-**Travis-CI**
29
-
30
-Travis-CI was added to check builds on Linux to ensure that `go get` works when cross building. Currently, Travis-CI is not used to test cross-building, but this may be changed in the future. It is also not currently possible to test the library on Linux, since COM API is specific to Windows and it is not currently possible to run a COM server on Linux or even connect to a remote COM server.
31
-
32
-**AppVeyor**
33
-
34
-AppVeyor is used to build on Windows using the (in-development) test COM server. It is currently only used to test the build and ensure that the code works on Windows. It will be used to register a COM server and then run the test cases based on the test COM server.
35
-
36
-The tests currently do run and do pass and this should be maintained with commits.
37
-
38
-##Versioning
39
-
40
-Go OLE uses [semantic versioning](http://semver.org) for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch.
41
-
42
-This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed.
43
-
44
-##LICENSE
45
-
46
-Under the MIT License: http://mattn.mit-license.org/2013
Godeps/_workspace/src/github.com/go-ole/go-ole/appveyor.yml
deleted
-74
@@ -1,74 +0,0 @@
1
-# Notes:
2
-# - Minimal appveyor.yml file is an empty file. All sections are optional.
3
-# - Indent each level of configuration with 2 spaces. Do not use tabs!
4
-# - All section names are case-sensitive.
5
-# - Section names should be unique on each level.
6
-
7
-version: "1.2.0.{build}-alpha-{branch}"
8
-
9
-os: Windows Server 2012 R2
10
-
11
-branches:
12
- only:
13
- - master
14
- - v1.1
15
- - v1.0
16
-
17
-skip_tags: true
18
-
19
-clone_folder: c:\gopath\src\github.com\go-ole\go-ole
20
-
21
-environment:
22
- GOPATH: c:\gopath
23
- matrix:
24
- - GOARCH: amd64
25
- GOVERSION: 1.4
26
- GOROOT: c:\go
27
- DOWNLOADPLATFORM: "x64"
28
- - GOARCH: 386
29
- GOVERSION: 1.4
30
- GOROOT: c:\go
31
- DOWNLOADPLATFORM: "x86"
32
-
33
-matrix:
34
- fast_finish: true
35
- allow_failures:
36
- - GOARCH: 386
37
- GOVERSION: 1.4
38
- GOROOT: c:\go
39
- DOWNLOADPLATFORM: "x86"
40
-
41
-install:
42
- - choco install mingw
43
- - SET PATH=c:\tools\mingw64\bin;%PATH%
44
- # - Download COM Server
45
- - ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.0/test-com-server-${env:DOWNLOADPLATFORM}.zip"
46
- - 7z e test-com-server-%DOWNLOADPLATFORM%.zip -oc:\gopath\src\github.com\go-ole\go-ole > NUL
47
- - c:\gopath\src\github.com\go-ole\go-ole\build\register-assembly.bat
48
- # - set
49
- - go version
50
- - go env
51
- - c:\gopath\src\github.com\go-ole\go-ole\build\compile-go.bat
52
- - go tool dist install -v cmd/8a
53
- - go tool dist install -v cmd/8c
54
- - go tool dist install -v cmd/8g
55
- - go tool dist install -v cmd/8l
56
- - go tool dist install -v cmd/6a
57
- - go tool dist install -v cmd/6c
58
- - go tool dist install -v cmd/6g
59
- - go tool dist install -v cmd/6l
60
- - go get -u golang.org/x/tools/cmd/cover
61
- - go get -u golang.org/x/tools/cmd/godoc
62
- - go get -u golang.org/x/tools/cmd/stringer
63
-
64
-build_script:
65
- - cd c:\gopath\src\github.com\go-ole\go-ole
66
- - go get -v -t ./...
67
- - go build
68
- - go test -v -cover ./...
69
-
70
-# disable automatic tests
71
-test: off
72
-
73
-# disable deployment
74
-deploy: off
Godeps/_workspace/src/github.com/go-ole/go-ole/build/compile-go.bat
deleted
-5
@@ -1,5 +0,0 @@
1
-@echo OFF
2
-
3
-echo "BUILD GOLANG"
4
-cd "%GOROOT%\src"
5
-./make.bat --dist-tool
Godeps/_workspace/src/github.com/go-ole/go-ole/build/register-assembly.bat
deleted
-8
@@ -1,8 +0,0 @@
1
-@ECHO OFF
2
-
3
-IF "x86" == "%DOWNLOADPLATFORM%" (
4
- CALL c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll
5
-)
6
-IF "x64" == "%DOWNLOADPLATFORM%" (
7
- CALL c:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll
8
-)
Godeps/_workspace/src/github.com/go-ole/go-ole/com.go
deleted
-328
@@ -1,328 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "errors"
7
- "syscall"
8
- "time"
9
- "unicode/utf16"
10
- "unsafe"
11
-)
12
-
13
-var (
14
- procCoInitialize, _ = modole32.FindProc("CoInitialize")
15
- procCoInitializeEx, _ = modole32.FindProc("CoInitializeEx")
16
- procCoUninitialize, _ = modole32.FindProc("CoUninitialize")
17
- procCoCreateInstance, _ = modole32.FindProc("CoCreateInstance")
18
- procCoTaskMemFree, _ = modole32.FindProc("CoTaskMemFree")
19
- procCLSIDFromProgID, _ = modole32.FindProc("CLSIDFromProgID")
20
- procCLSIDFromString, _ = modole32.FindProc("CLSIDFromString")
21
- procStringFromCLSID, _ = modole32.FindProc("StringFromCLSID")
22
- procStringFromIID, _ = modole32.FindProc("StringFromIID")
23
- procIIDFromString, _ = modole32.FindProc("IIDFromString")
24
- procGetUserDefaultLCID, _ = modkernel32.FindProc("GetUserDefaultLCID")
25
- procCopyMemory, _ = modkernel32.FindProc("RtlMoveMemory")
26
- procVariantInit, _ = modoleaut32.FindProc("VariantInit")
27
- procVariantClear, _ = modoleaut32.FindProc("VariantClear")
28
- procVariantTimeToSystemTime, _ = modoleaut32.FindProc("VariantTimeToSystemTime")
29
- procSysAllocString, _ = modoleaut32.FindProc("SysAllocString")
30
- procSysAllocStringLen, _ = modoleaut32.FindProc("SysAllocStringLen")
31
- procSysFreeString, _ = modoleaut32.FindProc("SysFreeString")
32
- procSysStringLen, _ = modoleaut32.FindProc("SysStringLen")
33
- procCreateDispTypeInfo, _ = modoleaut32.FindProc("CreateDispTypeInfo")
34
- procCreateStdDispatch, _ = modoleaut32.FindProc("CreateStdDispatch")
35
- procGetActiveObject, _ = modoleaut32.FindProc("GetActiveObject")
36
-
37
- procGetMessageW, _ = moduser32.FindProc("GetMessageW")
38
- procDispatchMessageW, _ = moduser32.FindProc("DispatchMessageW")
39
-)
40
-
41
-// coInitialize initializes COM library on current thread.
42
-//
43
-// MSDN documentation suggests that this function should not be called. Call
44
-// CoInitializeEx() instead. The reason has to do with threading and this
45
-// function is only for single-threaded apartments.
46
-//
47
-// That said, most users of the library have gotten away with just this
48
-// function. If you are experiencing threading issues, then use
49
-// CoInitializeEx().
50
-func coInitialize() (err error) {
51
- // http://msdn.microsoft.com/en-us/library/windows/desktop/ms678543(v=vs.85).aspx
52
- // Suggests that no value should be passed to CoInitialized.
53
- // Could just be Call() since the parameter is optional. <-- Needs testing to be sure.
54
- hr, _, _ := procCoInitialize.Call(uintptr(0))
55
- if hr != 0 {
56
- err = NewError(hr)
57
- }
58
- return
59
-}
60
-
61
-// coInitializeEx initializes COM library with concurrency model.
62
-func coInitializeEx(coinit uint32) (err error) {
63
- // http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx
64
- // Suggests that the first parameter is not only optional but should always be NULL.
65
- hr, _, _ := procCoInitializeEx.Call(uintptr(0), uintptr(coinit))
66
- if hr != 0 {
67
- err = NewError(hr)
68
- }
69
- return
70
-}
71
-
72
-// CoInitialize initializes COM library on current thread.
73
-//
74
-// MSDN documentation suggests that this function should not be called. Call
75
-// CoInitializeEx() instead. The reason has to do with threading and this
76
-// function is only for single-threaded apartments.
77
-//
78
-// That said, most users of the library have gotten away with just this
79
-// function. If you are experiencing threading issues, then use
80
-// CoInitializeEx().
81
-func CoInitialize(p uintptr) (err error) {
82
- // p is ignored and won't be used.
83
- // Avoid any variable not used errors.
84
- p = uintptr(0)
85
- return coInitialize()
86
-}
87
-
88
-// CoInitializeEx initializes COM library with concurrency model.
89
-func CoInitializeEx(p uintptr, coinit uint32) (err error) {
90
- // Avoid any variable not used errors.
91
- p = uintptr(0)
92
- return coInitializeEx(coinit)
93
-}
94
-
95
-// CoUninitialize uninitializes COM Library.
96
-func CoUninitialize() {
97
- procCoUninitialize.Call()
98
-}
99
-
100
-// CoTaskMemFree frees memory pointer.
101
-func CoTaskMemFree(memptr uintptr) {
102
- procCoTaskMemFree.Call(memptr)
103
-}
104
-
105
-// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
106
-//
107
-// The Programmatic Identifier must be registered, because it will be looked up
108
-// in the Windows Registry. The registry entry has the following keys: CLSID,
109
-// Insertable, Protocol and Shell
110
-// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
111
-//
112
-// programID identifies the class id with less precision and is not guaranteed
113
-// to be unique. These are usually found in the registry under
114
-// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
115
-// "Program.Component.Version" with version being optional.
116
-//
117
-// CLSIDFromProgID in Windows API.
118
-func CLSIDFromProgID(progId string) (clsid *GUID, err error) {
119
- var guid GUID
120
- lpszProgID := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
121
- hr, _, _ := procCLSIDFromProgID.Call(lpszProgID, uintptr(unsafe.Pointer(&guid)))
122
- if hr != 0 {
123
- err = NewError(hr)
124
- }
125
- clsid = &guid
126
- return
127
-}
128
-
129
-// CLSIDFromString retrieves Class ID from string representation.
130
-//
131
-// This is technically the string version of the GUID and will convert the
132
-// string to object.
133
-//
134
-// CLSIDFromString in Windows API.
135
-func CLSIDFromString(str string) (clsid *GUID, err error) {
136
- var guid GUID
137
- lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
138
- hr, _, _ := procCLSIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
139
- if hr != 0 {
140
- err = NewError(hr)
141
- }
142
- clsid = &guid
143
- return
144
-}
145
-
146
-// StringFromCLSID returns GUID formated string from GUID object.
147
-func StringFromCLSID(clsid *GUID) (str string, err error) {
148
- var p *uint16
149
- hr, _, _ := procStringFromCLSID.Call(uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(&p)))
150
- if hr != 0 {
151
- err = NewError(hr)
152
- }
153
- str = LpOleStrToString(p)
154
- return
155
-}
156
-
157
-// IIDFromString returns GUID from program ID.
158
-func IIDFromString(progId string) (clsid *GUID, err error) {
159
- var guid GUID
160
- lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
161
- hr, _, _ := procIIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
162
- if hr != 0 {
163
- err = NewError(hr)
164
- }
165
- clsid = &guid
166
- return
167
-}
168
-
169
-// StringFromIID returns GUID formatted string from GUID object.
170
-func StringFromIID(iid *GUID) (str string, err error) {
171
- var p *uint16
172
- hr, _, _ := procStringFromIID.Call(uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(&p)))
173
- if hr != 0 {
174
- err = NewError(hr)
175
- }
176
- str = LpOleStrToString(p)
177
- return
178
-}
179
-
180
-// CreateInstance of single uninitialized object with GUID.
181
-func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
182
- if iid == nil {
183
- iid = IID_IUnknown
184
- }
185
- hr, _, _ := procCoCreateInstance.Call(
186
- uintptr(unsafe.Pointer(clsid)),
187
- 0,
188
- CLSCTX_SERVER,
189
- uintptr(unsafe.Pointer(iid)),
190
- uintptr(unsafe.Pointer(&unk)))
191
- if hr != 0 {
192
- err = NewError(hr)
193
- }
194
- return
195
-}
196
-
197
-// GetActiveObject retrieves pointer to active object.
198
-func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
199
- if iid == nil {
200
- iid = IID_IUnknown
201
- }
202
- hr, _, _ := procGetActiveObject.Call(
203
- uintptr(unsafe.Pointer(clsid)),
204
- uintptr(unsafe.Pointer(iid)),
205
- uintptr(unsafe.Pointer(&unk)))
206
- if hr != 0 {
207
- err = NewError(hr)
208
- }
209
- return
210
-}
211
-
212
-// VariantInit initializes variant.
213
-func VariantInit(v *VARIANT) (err error) {
214
- hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v)))
215
- if hr != 0 {
216
- err = NewError(hr)
217
- }
218
- return
219
-}
220
-
221
-// VariantClear clears value in Variant settings to VT_EMPTY.
222
-func VariantClear(v *VARIANT) (err error) {
223
- hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v)))
224
- if hr != 0 {
225
- err = NewError(hr)
226
- }
227
- return
228
-}
229
-
230
-// SysAllocString allocates memory for string and copies string into memory.
231
-func SysAllocString(v string) (ss *int16) {
232
- pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
233
- ss = (*int16)(unsafe.Pointer(pss))
234
- return
235
-}
236
-
237
-// SysAllocStringLen copies up to length of given string returning pointer.
238
-func SysAllocStringLen(v string) (ss *int16) {
239
- utf16 := utf16.Encode([]rune(v + "\x00"))
240
- ptr := &utf16[0]
241
-
242
- pss, _, _ := procSysAllocStringLen.Call(uintptr(unsafe.Pointer(ptr)), uintptr(len(utf16)-1))
243
- ss = (*int16)(unsafe.Pointer(pss))
244
- return
245
-}
246
-
247
-// SysFreeString frees string system memory. This must be called with SysAllocString.
248
-func SysFreeString(v *int16) (err error) {
249
- hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v)))
250
- if hr != 0 {
251
- err = NewError(hr)
252
- }
253
- return
254
-}
255
-
256
-// SysStringLen is the length of the system allocated string.
257
-func SysStringLen(v *int16) uint32 {
258
- l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v)))
259
- return uint32(l)
260
-}
261
-
262
-// CreateStdDispatch provides default IDispatch implementation for IUnknown.
263
-//
264
-// This handles default IDispatch implementation for objects. It haves a few
265
-// limitations with only supporting one language. It will also only return
266
-// default exception codes.
267
-func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (disp *IDispatch, err error) {
268
- hr, _, _ := procCreateStdDispatch.Call(
269
- uintptr(unsafe.Pointer(unk)),
270
- v,
271
- uintptr(unsafe.Pointer(ptinfo)),
272
- uintptr(unsafe.Pointer(&disp)))
273
- if hr != 0 {
274
- err = NewError(hr)
275
- }
276
- return
277
-}
278
-
279
-// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
280
-//
281
-// This will not handle the full implementation of the interface.
282
-func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
283
- hr, _, _ := procCreateDispTypeInfo.Call(
284
- uintptr(unsafe.Pointer(idata)),
285
- uintptr(GetUserDefaultLCID()),
286
- uintptr(unsafe.Pointer(&pptinfo)))
287
- if hr != 0 {
288
- err = NewError(hr)
289
- }
290
- return
291
-}
292
-
293
-// copyMemory moves location of a block of memory.
294
-func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
295
- procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
296
-}
297
-
298
-// GetUserDefaultLCID retrieves current user default locale.
299
-func GetUserDefaultLCID() (lcid uint32) {
300
- ret, _, _ := procGetUserDefaultLCID.Call()
301
- lcid = uint32(ret)
302
- return
303
-}
304
-
305
-// GetMessage in message queue from runtime.
306
-//
307
-// This function appears to block. PeekMessage does not block.
308
-func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
309
- r0, _, err := procGetMessageW.Call(uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax))
310
- ret = int32(r0)
311
- return
312
-}
313
-
314
-// DispatchMessage to window procedure.
315
-func DispatchMessage(msg *Msg) (ret int32) {
316
- r0, _, _ := procDispatchMessageW.Call(uintptr(unsafe.Pointer(msg)))
317
- ret = int32(r0)
318
- return
319
-}
320
-
321
-func GetVariantDate(value float64) (time.Time, error) {
322
- var st syscall.Systemtime
323
- r, _, _ := procVariantTimeToSystemTime.Call(uintptr(unsafe.Pointer(&value)), uintptr(unsafe.Pointer(&st)))
324
- if r != 0 {
325
- return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), nil), nil
326
- }
327
- return time.Now(), errors.New("Could not convert to time, passing current time.")
328
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/com_func.go
deleted
-174
@@ -1,174 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-import (
6
- "time"
7
- "unsafe"
8
-)
9
-
10
-// coInitialize initializes COM library on current thread.
11
-//
12
-// MSDN documentation suggests that this function should not be called. Call
13
-// CoInitializeEx() instead. The reason has to do with threading and this
14
-// function is only for single-threaded apartments.
15
-//
16
-// That said, most users of the library have gotten away with just this
17
-// function. If you are experiencing threading issues, then use
18
-// CoInitializeEx().
19
-func coInitialize() error {
20
- return NewError(E_NOTIMPL)
21
-}
22
-
23
-// coInitializeEx initializes COM library with concurrency model.
24
-func coInitializeEx(coinit uint32) error {
25
- return NewError(E_NOTIMPL)
26
-}
27
-
28
-// CoInitialize initializes COM library on current thread.
29
-//
30
-// MSDN documentation suggests that this function should not be called. Call
31
-// CoInitializeEx() instead. The reason has to do with threading and this
32
-// function is only for single-threaded apartments.
33
-//
34
-// That said, most users of the library have gotten away with just this
35
-// function. If you are experiencing threading issues, then use
36
-// CoInitializeEx().
37
-func CoInitialize(p uintptr) error {
38
- return NewError(E_NOTIMPL)
39
-}
40
-
41
-// CoInitializeEx initializes COM library with concurrency model.
42
-func CoInitializeEx(p uintptr, coinit uint32) error {
43
- return NewError(E_NOTIMPL)
44
-}
45
-
46
-// CoUninitialize uninitializes COM Library.
47
-func CoUninitialize() {}
48
-
49
-// CoTaskMemFree frees memory pointer.
50
-func CoTaskMemFree(memptr uintptr) {}
51
-
52
-// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
53
-//
54
-// The Programmatic Identifier must be registered, because it will be looked up
55
-// in the Windows Registry. The registry entry has the following keys: CLSID,
56
-// Insertable, Protocol and Shell
57
-// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
58
-//
59
-// programID identifies the class id with less precision and is not guaranteed
60
-// to be unique. These are usually found in the registry under
61
-// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
62
-// "Program.Component.Version" with version being optional.
63
-//
64
-// CLSIDFromProgID in Windows API.
65
-func CLSIDFromProgID(progId string) (*GUID, error) {
66
- return nil, NewError(E_NOTIMPL)
67
-}
68
-
69
-// CLSIDFromString retrieves Class ID from string representation.
70
-//
71
-// This is technically the string version of the GUID and will convert the
72
-// string to object.
73
-//
74
-// CLSIDFromString in Windows API.
75
-func CLSIDFromString(str string) (*GUID, error) {
76
- return nil, NewError(E_NOTIMPL)
77
-}
78
-
79
-// StringFromCLSID returns GUID formated string from GUID object.
80
-func StringFromCLSID(clsid *GUID) (string, error) {
81
- return "", NewError(E_NOTIMPL)
82
-}
83
-
84
-// IIDFromString returns GUID from program ID.
85
-func IIDFromString(progId string) (*GUID, error) {
86
- return nil, NewError(E_NOTIMPL)
87
-}
88
-
89
-// StringFromIID returns GUID formatted string from GUID object.
90
-func StringFromIID(iid *GUID) (string, error) {
91
- return "", NewError(E_NOTIMPL)
92
-}
93
-
94
-// CreateInstance of single uninitialized object with GUID.
95
-func CreateInstance(clsid *GUID, iid *GUID) (*IUnknown, error) {
96
- return nil, NewError(E_NOTIMPL)
97
-}
98
-
99
-// GetActiveObject retrieves pointer to active object.
100
-func GetActiveObject(clsid *GUID, iid *GUID) (*IUnknown, error) {
101
- return nil, NewError(E_NOTIMPL)
102
-}
103
-
104
-// VariantInit initializes variant.
105
-func VariantInit(v *VARIANT) error {
106
- return NewError(E_NOTIMPL)
107
-}
108
-
109
-// VariantClear clears value in Variant settings to VT_EMPTY.
110
-func VariantClear(v *VARIANT) error {
111
- return NewError(E_NOTIMPL)
112
-}
113
-
114
-// SysAllocString allocates memory for string and copies string into memory.
115
-func SysAllocString(v string) *int16 {
116
- u := int16(0)
117
- return &u
118
-}
119
-
120
-// SysAllocStringLen copies up to length of given string returning pointer.
121
-func SysAllocStringLen(v string) *int16 {
122
- u := int16(0)
123
- return &u
124
-}
125
-
126
-// SysFreeString frees string system memory. This must be called with SysAllocString.
127
-func SysFreeString(v *int16) error {
128
- return NewError(E_NOTIMPL)
129
-}
130
-
131
-// SysStringLen is the length of the system allocated string.
132
-func SysStringLen(v *int16) uint32 {
133
- return uint32(0)
134
-}
135
-
136
-// CreateStdDispatch provides default IDispatch implementation for IUnknown.
137
-//
138
-// This handles default IDispatch implementation for objects. It haves a few
139
-// limitations with only supporting one language. It will also only return
140
-// default exception codes.
141
-func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (*IDispatch, error) {
142
- return nil, NewError(E_NOTIMPL)
143
-}
144
-
145
-// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
146
-//
147
-// This will not handle the full implementation of the interface.
148
-func CreateDispTypeInfo(idata *INTERFACEDATA) (*IUnknown, error) {
149
- return nil, NewError(E_NOTIMPL)
150
-}
151
-
152
-// copyMemory moves location of a block of memory.
153
-func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {}
154
-
155
-// GetUserDefaultLCID retrieves current user default locale.
156
-func GetUserDefaultLCID() uint32 {
157
- return uint32(0)
158
-}
159
-
160
-// GetMessage in message queue from runtime.
161
-//
162
-// This function appears to block. PeekMessage does not block.
163
-func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (int32, error) {
164
- return int32(0), NewError(E_NOTIMPL)
165
-}
166
-
167
-// DispatchMessage to window procedure.
168
-func DispatchMessage(msg *Msg) int32 {
169
- return int32(0)
170
-}
171
-
172
-func GetVariantDate(value float64) (time.Time, error) {
173
- return time.Now(), NewError(E_NOTIMPL)
174
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/com_func_test.go
deleted
-193
@@ -1,193 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-import "testing"
6
-
7
-// TestComSetupAndShutDown tests that API fails on Linux.
8
-func TestComSetupAndShutDown(t *testing.T) {
9
- defer func() {
10
- if r := recover(); r != nil {
11
- t.Log(r)
12
- t.Fail()
13
- }
14
- }()
15
-
16
- err := coInitialize()
17
- if err == nil {
18
- t.Error("should be error, because only Windows is supported.")
19
- t.FailNow()
20
- }
21
-
22
- CoUninitialize()
23
-}
24
-
25
-// TestComPublicSetupAndShutDown tests that API fails on Linux.
26
-func TestComPublicSetupAndShutDown(t *testing.T) {
27
- defer func() {
28
- if r := recover(); r != nil {
29
- t.Log(r)
30
- t.Fail()
31
- }
32
- }()
33
-
34
- err := CoInitialize(0)
35
- if err == nil {
36
- t.Error("should be error, because only Windows is supported.")
37
- t.FailNow()
38
- }
39
-
40
- CoUninitialize()
41
-}
42
-
43
-// TestComPublicSetupAndShutDown_WithValue tests that API fails on Linux.
44
-func TestComPublicSetupAndShutDown_WithValue(t *testing.T) {
45
- defer func() {
46
- if r := recover(); r != nil {
47
- t.Log(r)
48
- t.Fail()
49
- }
50
- }()
51
-
52
- err := CoInitialize(5)
53
- if err == nil {
54
- t.Error("should be error, because only Windows is supported.")
55
- t.FailNow()
56
- }
57
-
58
- CoUninitialize()
59
-}
60
-
61
-// TestComExSetupAndShutDown tests that API fails on Linux.
62
-func TestComExSetupAndShutDown(t *testing.T) {
63
- defer func() {
64
- if r := recover(); r != nil {
65
- t.Log(r)
66
- t.Fail()
67
- }
68
- }()
69
-
70
- err := coInitializeEx(COINIT_MULTITHREADED)
71
- if err == nil {
72
- t.Error("should be error, because only Windows is supported.")
73
- t.FailNow()
74
- }
75
-
76
- CoUninitialize()
77
-}
78
-
79
-// TestComPublicExSetupAndShutDown tests that API fails on Linux.
80
-func TestComPublicExSetupAndShutDown(t *testing.T) {
81
- defer func() {
82
- if r := recover(); r != nil {
83
- t.Log(r)
84
- t.Fail()
85
- }
86
- }()
87
-
88
- err := CoInitializeEx(0, COINIT_MULTITHREADED)
89
- if err == nil {
90
- t.Error("should be error, because only Windows is supported.")
91
- t.FailNow()
92
- }
93
-
94
- CoUninitialize()
95
-}
96
-
97
-// TestComPublicExSetupAndShutDown_WithValue tests that API fails on Linux.
98
-func TestComPublicExSetupAndShutDown_WithValue(t *testing.T) {
99
- defer func() {
100
- if r := recover(); r != nil {
101
- t.Log(r)
102
- t.Fail()
103
- }
104
- }()
105
-
106
- err := CoInitializeEx(5, COINIT_MULTITHREADED)
107
- if err == nil {
108
- t.Error("should be error, because only Windows is supported.")
109
- t.FailNow()
110
- }
111
-
112
- CoUninitialize()
113
-}
114
-
115
-// TestClsidFromProgID_WindowsMediaNSSManager tests that API fails on Linux.
116
-func TestClsidFromProgID_WindowsMediaNSSManager(t *testing.T) {
117
- defer func() {
118
- if r := recover(); r != nil {
119
- t.Log(r)
120
- t.Fail()
121
- }
122
- }()
123
-
124
- coInitialize()
125
- defer CoUninitialize()
126
- _, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
127
- if err == nil {
128
- t.Error("should be error, because only Windows is supported.")
129
- t.FailNow()
130
- }
131
-}
132
-
133
-// TestClsidFromString_WindowsMediaNSSManager tests that API fails on Linux.
134
-func TestClsidFromString_WindowsMediaNSSManager(t *testing.T) {
135
- defer func() {
136
- if r := recover(); r != nil {
137
- t.Log(r)
138
- t.Fail()
139
- }
140
- }()
141
-
142
- coInitialize()
143
- defer CoUninitialize()
144
- _, err := CLSIDFromString("{92498132-4D1A-4297-9B78-9E2E4BA99C07}")
145
-
146
- if err == nil {
147
- t.Error("should be error, because only Windows is supported.")
148
- t.FailNow()
149
- }
150
-}
151
-
152
-// TestCreateInstance_WindowsMediaNSSManager tests that API fails on Linux.
153
-func TestCreateInstance_WindowsMediaNSSManager(t *testing.T) {
154
- defer func() {
155
- if r := recover(); r != nil {
156
- t.Log(r)
157
- t.Fail()
158
- }
159
- }()
160
-
161
- coInitialize()
162
- defer CoUninitialize()
163
- _, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
164
-
165
- if err == nil {
166
- t.Error("should be error, because only Windows is supported.")
167
- t.FailNow()
168
- }
169
-}
170
-
171
-// TestError tests that API fails on Linux.
172
-func TestError(t *testing.T) {
173
- defer func() {
174
- if r := recover(); r != nil {
175
- t.Log(r)
176
- t.Fail()
177
- }
178
- }()
179
-
180
- coInitialize()
181
- defer CoUninitialize()
182
- _, err := CLSIDFromProgID("INTERFACE-NOT-FOUND")
183
- if err == nil {
184
- t.Error("should be error, because only Windows is supported.")
185
- t.FailNow()
186
- }
187
-
188
- switch vt := err.(type) {
189
- case *OleError:
190
- default:
191
- t.Fatalf("should be *ole.OleError %t", vt)
192
- }
193
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/com_test.go
deleted
-205
@@ -1,205 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "fmt"
7
- "testing"
8
-)
9
-
10
-func TestComSetupAndShutDown(t *testing.T) {
11
- defer func() {
12
- if r := recover(); r != nil {
13
- t.Log(r)
14
- t.Fail()
15
- }
16
- }()
17
-
18
- err := coInitialize()
19
- if err != nil {
20
- t.Error(err)
21
- t.FailNow()
22
- }
23
-
24
- CoUninitialize()
25
-}
26
-
27
-func TestComPublicSetupAndShutDown(t *testing.T) {
28
- defer func() {
29
- if r := recover(); r != nil {
30
- t.Log(r)
31
- t.Fail()
32
- }
33
- }()
34
-
35
- err := CoInitialize(0)
36
- if err != nil {
37
- t.Error(err)
38
- t.FailNow()
39
- }
40
-
41
- CoUninitialize()
42
-}
43
-
44
-func TestComPublicSetupAndShutDown_WithValue(t *testing.T) {
45
- defer func() {
46
- if r := recover(); r != nil {
47
- t.Log(r)
48
- t.Fail()
49
- }
50
- }()
51
-
52
- err := CoInitialize(5)
53
- if err != nil {
54
- t.Error(err)
55
- t.FailNow()
56
- }
57
-
58
- CoUninitialize()
59
-}
60
-
61
-func TestComExSetupAndShutDown(t *testing.T) {
62
- defer func() {
63
- if r := recover(); r != nil {
64
- t.Log(r)
65
- t.Fail()
66
- }
67
- }()
68
-
69
- err := coInitializeEx(COINIT_MULTITHREADED)
70
- if err != nil {
71
- t.Error(err)
72
- t.FailNow()
73
- }
74
-
75
- CoUninitialize()
76
-}
77
-
78
-func TestComPublicExSetupAndShutDown(t *testing.T) {
79
- defer func() {
80
- if r := recover(); r != nil {
81
- t.Log(r)
82
- t.Fail()
83
- }
84
- }()
85
-
86
- err := CoInitializeEx(0, COINIT_MULTITHREADED)
87
- if err != nil {
88
- t.Error(err)
89
- t.FailNow()
90
- }
91
-
92
- CoUninitialize()
93
-}
94
-
95
-func TestComPublicExSetupAndShutDown_WithValue(t *testing.T) {
96
- defer func() {
97
- if r := recover(); r != nil {
98
- t.Log(r)
99
- t.Fail()
100
- }
101
- }()
102
-
103
- err := CoInitializeEx(5, COINIT_MULTITHREADED)
104
- if err != nil {
105
- t.Error(err)
106
- t.FailNow()
107
- }
108
-
109
- CoUninitialize()
110
-}
111
-
112
-func TestClsidFromProgID_WindowsMediaNSSManager(t *testing.T) {
113
- defer func() {
114
- if r := recover(); r != nil {
115
- t.Log(r)
116
- t.Fail()
117
- }
118
- }()
119
-
120
- expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}}
121
-
122
- coInitialize()
123
- defer CoUninitialize()
124
- actual, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
125
- if err == nil {
126
- if !IsEqualGUID(expected, actual) {
127
- t.Log(err)
128
- t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual))
129
- t.Fail()
130
- }
131
- }
132
-}
133
-
134
-func TestClsidFromString_WindowsMediaNSSManager(t *testing.T) {
135
- defer func() {
136
- if r := recover(); r != nil {
137
- t.Log(r)
138
- t.Fail()
139
- }
140
- }()
141
-
142
- expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}}
143
-
144
- coInitialize()
145
- defer CoUninitialize()
146
- actual, err := CLSIDFromString("{92498132-4D1A-4297-9B78-9E2E4BA99C07}")
147
-
148
- if !IsEqualGUID(expected, actual) {
149
- t.Log(err)
150
- t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual))
151
- t.Fail()
152
- }
153
-}
154
-
155
-func TestCreateInstance_WindowsMediaNSSManager(t *testing.T) {
156
- defer func() {
157
- if r := recover(); r != nil {
158
- t.Log(r)
159
- t.Fail()
160
- }
161
- }()
162
-
163
- expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}}
164
-
165
- coInitialize()
166
- defer CoUninitialize()
167
- actual, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
168
-
169
- if err == nil {
170
- if !IsEqualGUID(expected, actual) {
171
- t.Log(err)
172
- t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual))
173
- t.Fail()
174
- }
175
-
176
- unknown, err := CreateInstance(actual, IID_IUnknown)
177
- if err != nil {
178
- t.Log(err)
179
- t.Fail()
180
- }
181
- unknown.Release()
182
- }
183
-}
184
-
185
-func TestError(t *testing.T) {
186
- defer func() {
187
- if r := recover(); r != nil {
188
- t.Log(r)
189
- t.Fail()
190
- }
191
- }()
192
-
193
- coInitialize()
194
- defer CoUninitialize()
195
- _, err := CLSIDFromProgID("INTERFACE-NOT-FOUND")
196
- if err == nil {
197
- t.Fatalf("should be fail", err)
198
- }
199
-
200
- switch vt := err.(type) {
201
- case *OleError:
202
- default:
203
- t.Fatalf("should be *ole.OleError %t", vt)
204
- }
205
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/connect.go
deleted
-192
@@ -1,192 +0,0 @@
1
-package ole
2
-
3
-// Connection contains IUnknown for fluent interface interaction.
4
-//
5
-// Deprecated. Use oleutil package instead.
6
-type Connection struct {
7
- Object *IUnknown // Access COM
8
-}
9
-
10
-// Initialize COM.
11
-func (*Connection) Initialize() (err error) {
12
- return coInitialize()
13
-}
14
-
15
-// Uninitialize COM.
16
-func (*Connection) Uninitialize() {
17
- CoUninitialize()
18
-}
19
-
20
-// Create IUnknown object based first on ProgId and then from String.
21
-func (c *Connection) Create(progId string) (err error) {
22
- var clsid *GUID
23
- clsid, err = CLSIDFromProgID(progId)
24
- if err != nil {
25
- clsid, err = CLSIDFromString(progId)
26
- if err != nil {
27
- return
28
- }
29
- }
30
-
31
- unknown, err := CreateInstance(clsid, IID_IUnknown)
32
- if err != nil {
33
- return
34
- }
35
- c.Object = unknown
36
-
37
- return
38
-}
39
-
40
-// Release IUnknown object.
41
-func (c *Connection) Release() {
42
- c.Object.Release()
43
-}
44
-
45
-// Load COM object from list of programIDs or strings.
46
-func (c *Connection) Load(names ...string) (errors []error) {
47
- var tempErrors []error = make([]error, len(names))
48
- var numErrors int = 0
49
- for _, name := range names {
50
- err := c.Create(name)
51
- if err != nil {
52
- tempErrors = append(tempErrors, err)
53
- numErrors += 1
54
- continue
55
- }
56
- break
57
- }
58
-
59
- copy(errors, tempErrors[0:numErrors])
60
- return
61
-}
62
-
63
-// Dispatch returns Dispatch object.
64
-func (c *Connection) Dispatch() (object *Dispatch, err error) {
65
- dispatch, err := c.Object.QueryInterface(IID_IDispatch)
66
- if err != nil {
67
- return
68
- }
69
- object = &Dispatch{dispatch}
70
- return
71
-}
72
-
73
-// Dispatch stores IDispatch object.
74
-type Dispatch struct {
75
- Object *IDispatch // Dispatch object.
76
-}
77
-
78
-// Call method on IDispatch with parameters.
79
-func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error) {
80
- id, err := d.GetId(method)
81
- if err != nil {
82
- return
83
- }
84
-
85
- result, err = d.Invoke(id, DISPATCH_METHOD, params)
86
- return
87
-}
88
-
89
-// MustCall method on IDispatch with parameters.
90
-func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT) {
91
- id, err := d.GetId(method)
92
- if err != nil {
93
- panic(err)
94
- }
95
-
96
- result, err = d.Invoke(id, DISPATCH_METHOD, params)
97
- if err != nil {
98
- panic(err)
99
- }
100
-
101
- return
102
-}
103
-
104
-// Get property on IDispatch with parameters.
105
-func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error) {
106
- id, err := d.GetId(name)
107
- if err != nil {
108
- return
109
- }
110
- result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
111
- return
112
-}
113
-
114
-// MustGet property on IDispatch with parameters.
115
-func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT) {
116
- id, err := d.GetId(name)
117
- if err != nil {
118
- panic(err)
119
- }
120
-
121
- result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
122
- if err != nil {
123
- panic(err)
124
- }
125
- return
126
-}
127
-
128
-// Set property on IDispatch with parameters.
129
-func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error) {
130
- id, err := d.GetId(name)
131
- if err != nil {
132
- return
133
- }
134
- result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
135
- return
136
-}
137
-
138
-// MustSet property on IDispatch with parameters.
139
-func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT) {
140
- id, err := d.GetId(name)
141
- if err != nil {
142
- panic(err)
143
- }
144
-
145
- result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
146
- if err != nil {
147
- panic(err)
148
- }
149
- return
150
-}
151
-
152
-// GetId retrieves ID of name on IDispatch.
153
-func (d *Dispatch) GetId(name string) (id int32, err error) {
154
- var dispid []int32
155
- dispid, err = d.Object.GetIDsOfName([]string{name})
156
- if err != nil {
157
- return
158
- }
159
- id = dispid[0]
160
- return
161
-}
162
-
163
-// GetIds retrieves all IDs of names on IDispatch.
164
-func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error) {
165
- dispid, err = d.Object.GetIDsOfName(names)
166
- return
167
-}
168
-
169
-// Invoke IDispatch on DisplayID of dispatch type with parameters.
170
-//
171
-// There have been problems where if send cascading params..., it would error
172
-// out because the parameters would be empty.
173
-func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error) {
174
- if len(params) < 1 {
175
- result, err = d.Object.Invoke(id, dispatch)
176
- } else {
177
- result, err = d.Object.Invoke(id, dispatch, params...)
178
- }
179
- return
180
-}
181
-
182
-// Release IDispatch object.
183
-func (d *Dispatch) Release() {
184
- d.Object.Release()
185
-}
186
-
187
-// Connect initializes COM and attempts to load IUnknown based on given names.
188
-func Connect(names ...string) (connection *Connection) {
189
- connection.Initialize()
190
- connection.Load(names...)
191
- return
192
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/connect_test.go
deleted
-159
@@ -1,159 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-import "strings"
6
-
7
-func Example_quickbooks() {
8
- var err error
9
-
10
- connection := &Connection{nil}
11
-
12
- err = connection.Initialize()
13
- if err != nil {
14
- return
15
- }
16
- defer connection.Uninitialize()
17
-
18
- err = connection.Create("QBXMLRP2.RequestProcessor.1")
19
- if err != nil {
20
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
21
- return
22
- }
23
- }
24
- defer connection.Release()
25
-
26
- dispatch, err := connection.Dispatch()
27
- if err != nil {
28
- return
29
- }
30
- defer dispatch.Release()
31
-}
32
-
33
-func Example_quickbooksConnectHelperCallDispatch() {
34
- var err error
35
-
36
- connection := &Connection{nil}
37
-
38
- err = connection.Initialize()
39
- if err != nil {
40
- return
41
- }
42
- defer connection.Uninitialize()
43
-
44
- err = connection.Create("QBXMLRP2.RequestProcessor.1")
45
- if err != nil {
46
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
47
- return
48
- }
49
- return
50
- }
51
- defer connection.Release()
52
-
53
- dispatch, err := connection.Dispatch()
54
- if err != nil {
55
- return
56
- }
57
- defer dispatch.Release()
58
-
59
- var result *VARIANT
60
-
61
- _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
62
- if err != nil {
63
- return
64
- }
65
-
66
- result, err = dispatch.Call("BeginSession", "", 2)
67
- if err != nil {
68
- return
69
- }
70
-
71
- ticket := result.ToString()
72
-
73
- _, err = dispatch.Call("EndSession", ticket)
74
- if err != nil {
75
- return
76
- }
77
-
78
- _, err = dispatch.Call("CloseConnection")
79
- if err != nil {
80
- return
81
- }
82
-}
83
-
84
-func Example_quickbooksConnectHelperDispatchProperty() {
85
- var err error
86
-
87
- connection := &Connection{nil}
88
-
89
- err = connection.Initialize()
90
- if err != nil {
91
- return
92
- }
93
- defer connection.Uninitialize()
94
-
95
- err = connection.Create("QBXMLRP2.RequestProcessor.1")
96
- if err != nil {
97
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
98
- return
99
- }
100
- return
101
- }
102
- defer connection.Release()
103
-
104
- dispatch, err := connection.Dispatch()
105
- if err != nil {
106
- return
107
- }
108
- defer dispatch.Release()
109
-
110
- var result *VARIANT
111
-
112
- _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
113
- if err != nil {
114
- return
115
- }
116
-
117
- result, err = dispatch.Call("BeginSession", "", 2)
118
- if err != nil {
119
- return
120
- }
121
-
122
- ticket := result.ToString()
123
-
124
- result, err = dispatch.Get("QBXMLVersionsForSession", ticket)
125
- if err != nil {
126
- return
127
- }
128
-
129
- conversion := result.ToArray()
130
-
131
- totalElements, _ := conversion.TotalElements(0)
132
- if totalElements != 13 {
133
- return
134
- }
135
-
136
- versions := conversion.ToStringArray()
137
- expectedVersionString := "1.0, 1.1, 2.0, 2.1, 3.0, 4.0, 4.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0"
138
- versionString := strings.Join(versions, ", ")
139
-
140
- if len(versions) != 13 {
141
- return
142
- }
143
-
144
- if expectedVersionString != versionString {
145
- return
146
- }
147
-
148
- conversion.Release()
149
-
150
- _, err = dispatch.Call("EndSession", ticket)
151
- if err != nil {
152
- return
153
- }
154
-
155
- _, err = dispatch.Call("CloseConnection")
156
- if err != nil {
157
- return
158
- }
159
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/connect_windows_test.go
deleted
-181
@@ -1,181 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "fmt"
7
- "strings"
8
- "testing"
9
-)
10
-
11
-func Example_quickbooks() {
12
- var err error
13
-
14
- connection := &Connection{nil}
15
-
16
- err = connection.Initialize()
17
- if err != nil {
18
- return
19
- }
20
- defer connection.Uninitialize()
21
-
22
- err = connection.Create("QBXMLRP2.RequestProcessor.1")
23
- if err != nil {
24
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
25
- return
26
- }
27
- }
28
- defer connection.Release()
29
-
30
- dispatch, err := connection.Dispatch()
31
- if err != nil {
32
- return
33
- }
34
- defer dispatch.Release()
35
-}
36
-
37
-func TestConnectHelperCallDispatch_QuickBooks(t *testing.T) {
38
- var err error
39
-
40
- connection := &Connection{nil}
41
-
42
- err = connection.Initialize()
43
- if err != nil {
44
- t.Log(err)
45
- t.FailNow()
46
- }
47
- defer connection.Uninitialize()
48
-
49
- err = connection.Create("QBXMLRP2.RequestProcessor.1")
50
- if err != nil {
51
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
52
- return
53
- }
54
- t.Log(err)
55
- t.FailNow()
56
- }
57
- defer connection.Release()
58
-
59
- dispatch, err := connection.Dispatch()
60
- if err != nil {
61
- t.Log(err)
62
- t.FailNow()
63
- }
64
- defer dispatch.Release()
65
-
66
- var result *VARIANT
67
-
68
- _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
69
- if err != nil {
70
- t.Log(err)
71
- t.FailNow()
72
- }
73
-
74
- result, err = dispatch.Call("BeginSession", "", 2)
75
- if err != nil {
76
- t.Log(err)
77
- t.FailNow()
78
- }
79
-
80
- ticket := result.ToString()
81
-
82
- _, err = dispatch.Call("EndSession", ticket)
83
- if err != nil {
84
- t.Log(err)
85
- t.Fail()
86
- }
87
-
88
- _, err = dispatch.Call("CloseConnection")
89
- if err != nil {
90
- t.Log(err)
91
- t.Fail()
92
- }
93
-}
94
-
95
-func TestConnectHelperDispatchProperty_QuickBooks(t *testing.T) {
96
- var err error
97
-
98
- connection := &Connection{nil}
99
-
100
- err = connection.Initialize()
101
- if err != nil {
102
- t.Log(err)
103
- t.FailNow()
104
- }
105
- defer connection.Uninitialize()
106
-
107
- err = connection.Create("QBXMLRP2.RequestProcessor.1")
108
- if err != nil {
109
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
110
- return
111
- }
112
- t.Log(err)
113
- t.FailNow()
114
- }
115
- defer connection.Release()
116
-
117
- dispatch, err := connection.Dispatch()
118
- if err != nil {
119
- t.Log(err)
120
- t.FailNow()
121
- }
122
- defer dispatch.Release()
123
-
124
- var result *VARIANT
125
-
126
- _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
127
- if err != nil {
128
- t.Log(err)
129
- t.FailNow()
130
- }
131
-
132
- result, err = dispatch.Call("BeginSession", "", 2)
133
- if err != nil {
134
- t.Log(err)
135
- t.FailNow()
136
- }
137
-
138
- ticket := result.ToString()
139
-
140
- result, err = dispatch.Get("QBXMLVersionsForSession", ticket)
141
- if err != nil {
142
- t.Log(err)
143
- t.FailNow()
144
- }
145
-
146
- conversion := result.ToArray()
147
-
148
- totalElements, _ := conversion.TotalElements(0)
149
- if totalElements != 13 {
150
- t.Log(fmt.Sprintf("%d total elements does not equal 13\n", totalElements))
151
- t.Fail()
152
- }
153
-
154
- versions := conversion.ToStringArray()
155
- expectedVersionString := "1.0, 1.1, 2.0, 2.1, 3.0, 4.0, 4.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0"
156
- versionString := strings.Join(versions, ", ")
157
-
158
- if len(versions) != 13 {
159
- t.Log(fmt.Sprintf("%s\n", versionString))
160
- t.Fail()
161
- }
162
-
163
- if expectedVersionString != versionString {
164
- t.Log(fmt.Sprintf("Expected: %s\nActual: %s", expectedVersionString, versionString))
165
- t.Fail()
166
- }
167
-
168
- conversion.Release()
169
-
170
- _, err = dispatch.Call("EndSession", ticket)
171
- if err != nil {
172
- t.Log(err)
173
- t.Fail()
174
- }
175
-
176
- _, err = dispatch.Call("CloseConnection")
177
- if err != nil {
178
- t.Log(err)
179
- t.Fail()
180
- }
181
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/constants.go
deleted
-153
@@ -1,153 +0,0 @@
1
-package ole
2
-
3
-const (
4
- CLSCTX_INPROC_SERVER = 1
5
- CLSCTX_INPROC_HANDLER = 2
6
- CLSCTX_LOCAL_SERVER = 4
7
- CLSCTX_INPROC_SERVER16 = 8
8
- CLSCTX_REMOTE_SERVER = 16
9
- CLSCTX_ALL = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER
10
- CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER
11
- CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER
12
-)
13
-
14
-const (
15
- COINIT_APARTMENTTHREADED = 0x2
16
- COINIT_MULTITHREADED = 0x0
17
- COINIT_DISABLE_OLE1DDE = 0x4
18
- COINIT_SPEED_OVER_MEMORY = 0x8
19
-)
20
-
21
-const (
22
- DISPATCH_METHOD = 1
23
- DISPATCH_PROPERTYGET = 2
24
- DISPATCH_PROPERTYPUT = 4
25
- DISPATCH_PROPERTYPUTREF = 8
26
-)
27
-
28
-const (
29
- S_OK = 0x00000000
30
- E_UNEXPECTED = 0x8000FFFF
31
- E_NOTIMPL = 0x80004001
32
- E_OUTOFMEMORY = 0x8007000E
33
- E_INVALIDARG = 0x80070057
34
- E_NOINTERFACE = 0x80004002
35
- E_POINTER = 0x80004003
36
- E_HANDLE = 0x80070006
37
- E_ABORT = 0x80004004
38
- E_FAIL = 0x80004005
39
- E_ACCESSDENIED = 0x80070005
40
- E_PENDING = 0x8000000A
41
-
42
- CO_E_CLASSSTRING = 0x800401F3
43
-)
44
-
45
-const (
46
- CC_FASTCALL = iota
47
- CC_CDECL
48
- CC_MSCPASCAL
49
- CC_PASCAL = CC_MSCPASCAL
50
- CC_MACPASCAL
51
- CC_STDCALL
52
- CC_FPFASTCALL
53
- CC_SYSCALL
54
- CC_MPWCDECL
55
- CC_MPWPASCAL
56
- CC_MAX = CC_MPWPASCAL
57
-)
58
-
59
-type VT uint16
60
-
61
-const (
62
- VT_EMPTY VT = 0x0
63
- VT_NULL VT = 0x1
64
- VT_I2 VT = 0x2
65
- VT_I4 VT = 0x3
66
- VT_R4 VT = 0x4
67
- VT_R8 VT = 0x5
68
- VT_CY VT = 0x6
69
- VT_DATE VT = 0x7
70
- VT_BSTR VT = 0x8
71
- VT_DISPATCH VT = 0x9
72
- VT_ERROR VT = 0xa
73
- VT_BOOL VT = 0xb
74
- VT_VARIANT VT = 0xc
75
- VT_UNKNOWN VT = 0xd
76
- VT_DECIMAL VT = 0xe
77
- VT_I1 VT = 0x10
78
- VT_UI1 VT = 0x11
79
- VT_UI2 VT = 0x12
80
- VT_UI4 VT = 0x13
81
- VT_I8 VT = 0x14
82
- VT_UI8 VT = 0x15
83
- VT_INT VT = 0x16
84
- VT_UINT VT = 0x17
85
- VT_VOID VT = 0x18
86
- VT_HRESULT VT = 0x19
87
- VT_PTR VT = 0x1a
88
- VT_SAFEARRAY VT = 0x1b
89
- VT_CARRAY VT = 0x1c
90
- VT_USERDEFINED VT = 0x1d
91
- VT_LPSTR VT = 0x1e
92
- VT_LPWSTR VT = 0x1f
93
- VT_RECORD VT = 0x24
94
- VT_INT_PTR VT = 0x25
95
- VT_UINT_PTR VT = 0x26
96
- VT_FILETIME VT = 0x40
97
- VT_BLOB VT = 0x41
98
- VT_STREAM VT = 0x42
99
- VT_STORAGE VT = 0x43
100
- VT_STREAMED_OBJECT VT = 0x44
101
- VT_STORED_OBJECT VT = 0x45
102
- VT_BLOB_OBJECT VT = 0x46
103
- VT_CF VT = 0x47
104
- VT_CLSID VT = 0x48
105
- VT_BSTR_BLOB VT = 0xfff
106
- VT_VECTOR VT = 0x1000
107
- VT_ARRAY VT = 0x2000
108
- VT_BYREF VT = 0x4000
109
- VT_RESERVED VT = 0x8000
110
- VT_ILLEGAL VT = 0xffff
111
- VT_ILLEGALMASKED VT = 0xfff
112
- VT_TYPEMASK VT = 0xfff
113
-)
114
-
115
-const (
116
- DISPID_UNKNOWN = -1
117
- DISPID_VALUE = 0
118
- DISPID_PROPERTYPUT = -3
119
- DISPID_NEWENUM = -4
120
- DISPID_EVALUATE = -5
121
- DISPID_CONSTRUCTOR = -6
122
- DISPID_DESTRUCTOR = -7
123
- DISPID_COLLECT = -8
124
-)
125
-
126
-const (
127
- TKIND_ENUM = 1
128
- TKIND_RECORD = 2
129
- TKIND_MODULE = 3
130
- TKIND_INTERFACE = 4
131
- TKIND_DISPATCH = 5
132
- TKIND_COCLASS = 6
133
- TKIND_ALIAS = 7
134
- TKIND_UNION = 8
135
- TKIND_MAX = 9
136
-)
137
-
138
-// Safe Array Feature Flags
139
-
140
-const (
141
- FADF_AUTO = 0x0001
142
- FADF_STATIC = 0x0002
143
- FADF_EMBEDDED = 0x0004
144
- FADF_FIXEDSIZE = 0x0010
145
- FADF_RECORD = 0x0020
146
- FADF_HAVEIID = 0x0040
147
- FADF_HAVEVARTYPE = 0x0080
148
- FADF_BSTR = 0x0100
149
- FADF_UNKNOWN = 0x0200
150
- FADF_DISPATCH = 0x0400
151
- FADF_VARIANT = 0x0800
152
- FADF_RESERVED = 0xF008
153
-)
Godeps/_workspace/src/github.com/go-ole/go-ole/data/screenshot.png
Binary files a/Godeps/_workspace/src/github.com/go-ole/go-ole/data/screenshot.png and /dev/null differ
Godeps/_workspace/src/github.com/go-ole/go-ole/error.go
deleted
-51
@@ -1,51 +0,0 @@
1
-package ole
2
-
3
-// OleError stores COM errors.
4
-type OleError struct {
5
- hr uintptr
6
- description string
7
- subError error
8
-}
9
-
10
-// NewError creates new error with HResult.
11
-func NewError(hr uintptr) *OleError {
12
- return &OleError{hr: hr}
13
-}
14
-
15
-// NewErrorWithDescription creates new COM error with HResult and description.
16
-func NewErrorWithDescription(hr uintptr, description string) *OleError {
17
- return &OleError{hr: hr, description: description}
18
-}
19
-
20
-// NewErrorWithSubError creates new COM error with parent error.
21
-func NewErrorWithSubError(hr uintptr, description string, err error) *OleError {
22
- return &OleError{hr: hr, description: description, subError: err}
23
-}
24
-
25
-// Code is the HResult.
26
-func (v *OleError) Code() uintptr {
27
- return uintptr(v.hr)
28
-}
29
-
30
-// String description, either manually set or format message with error code.
31
-func (v *OleError) String() string {
32
- if v.description != "" {
33
- return errstr(int(v.hr)) + " (" + v.description + ")"
34
- }
35
- return errstr(int(v.hr))
36
-}
37
-
38
-// Error implements error interface.
39
-func (v *OleError) Error() string {
40
- return v.String()
41
-}
42
-
43
-// Description retrieves error summary, if there is one.
44
-func (v *OleError) Description() string {
45
- return v.description
46
-}
47
-
48
-// SubError returns parent error, if there is one.
49
-func (v *OleError) SubError() error {
50
- return v.subError
51
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/error_func.go
deleted
-8
@@ -1,8 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-// errstr converts error code to string.
6
-func errstr(errno int) string {
7
- return ""
8
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/error_windows.go
deleted
-24
@@ -1,24 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "fmt"
7
- "syscall"
8
- "unicode/utf16"
9
-)
10
-
11
-// errstr converts error code to string.
12
-func errstr(errno int) string {
13
- // ask windows for the remaining errors
14
- var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
15
- b := make([]uint16, 300)
16
- n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
17
- if err != nil {
18
- return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
19
- }
20
- // trim terminating \r and \n
21
- for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
22
- }
23
- return string(utf16.Decode(b[:n]))
24
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel/excel.go
deleted
-31
@@ -1,31 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "time"
7
-
8
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10
-)
11
-
12
-func main() {
13
- ole.CoInitialize(0)
14
- unknown, _ := oleutil.CreateObject("Excel.Application")
15
- excel, _ := unknown.QueryInterface(ole.IID_IDispatch)
16
- oleutil.PutProperty(excel, "Visible", true)
17
- workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch()
18
- workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch()
19
- worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch()
20
- cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch()
21
- oleutil.PutProperty(cell, "Value", 12345)
22
-
23
- time.Sleep(2000000000)
24
-
25
- oleutil.PutProperty(workbook, "Saved", true)
26
- oleutil.CallMethod(workbook, "Close", false)
27
- oleutil.CallMethod(excel, "Quit")
28
- excel.Release()
29
-
30
- ole.CoUninitialize()
31
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel2/excel.go
deleted
-96
@@ -1,96 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "fmt"
7
- "log"
8
- "os"
9
-
10
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
11
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
12
-)
13
-
14
-func writeExample(excel, workbooks *ole.IDispatch, filepath string) {
15
- // ref: https://msdn.microsoft.com/zh-tw/library/office/ff198017.aspx
16
- // http://stackoverflow.com/questions/12159513/what-is-the-correct-xlfileformat-enumeration-for-excel-97-2003
17
- const xlExcel8 = 56
18
- workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch()
19
- defer workbook.Release()
20
- worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch()
21
- defer worksheet.Release()
22
- cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch()
23
- oleutil.PutProperty(cell, "Value", 12345)
24
- cell.Release()
25
- activeWorkBook := oleutil.MustGetProperty(excel, "ActiveWorkBook").ToIDispatch()
26
- defer activeWorkBook.Release()
27
-
28
- os.Remove(filepath)
29
- // ref: https://msdn.microsoft.com/zh-tw/library/microsoft.office.tools.excel.workbook.saveas.aspx
30
- oleutil.MustCallMethod(activeWorkBook, "SaveAs", filepath, xlExcel8, nil, nil).ToIDispatch()
31
-
32
- //time.Sleep(2 * time.Second)
33
-
34
- // let excel could close without asking
35
- // oleutil.PutProperty(workbook, "Saved", true)
36
- // oleutil.CallMethod(workbook, "Close", false)
37
-}
38
-
39
-func readExample(fileName string, excel, workbooks *ole.IDispatch) {
40
- workbook, err := oleutil.CallMethod(workbooks, "Open", fileName)
41
-
42
- if err != nil {
43
- log.Fatalln(err)
44
- }
45
- defer workbook.ToIDispatch().Release()
46
-
47
- sheets := oleutil.MustGetProperty(excel, "Sheets").ToIDispatch()
48
- sheetCount := (int)(oleutil.MustGetProperty(sheets, "Count").Val)
49
- fmt.Println("sheet count=", sheetCount)
50
- sheets.Release()
51
-
52
- worksheet := oleutil.MustGetProperty(workbook.ToIDispatch(), "Worksheets", 1).ToIDispatch()
53
- defer worksheet.Release()
54
- for row := 1; row <= 2; row++ {
55
- for col := 1; col <= 5; col++ {
56
- cell := oleutil.MustGetProperty(worksheet, "Cells", row, col).ToIDispatch()
57
- val, err := oleutil.GetProperty(cell, "Value")
58
- if err != nil {
59
- break
60
- }
61
- fmt.Printf("(%d,%d)=%+v toString=%s\n", col, row, val.Value(), val.ToString())
62
- cell.Release()
63
- }
64
- }
65
-}
66
-
67
-func showMethodsAndProperties(i *ole.IDispatch) {
68
- n, err := i.GetTypeInfoCount()
69
- if err != nil {
70
- log.Fatalln(err)
71
- }
72
- tinfo, err := i.GetTypeInfo()
73
- if err != nil {
74
- log.Fatalln(err)
75
- }
76
-
77
- fmt.Println("n=", n, "tinfo=", tinfo)
78
-}
79
-
80
-func main() {
81
- log.SetFlags(log.Flags() | log.Lshortfile)
82
- ole.CoInitialize(0)
83
- unknown, _ := oleutil.CreateObject("Excel.Application")
84
- excel, _ := unknown.QueryInterface(ole.IID_IDispatch)
85
- oleutil.PutProperty(excel, "Visible", true)
86
-
87
- workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch()
88
- cwd, _ := os.Getwd()
89
- writeExample(excel, workbooks, cwd+"\\write.xls")
90
- readExample(cwd+"\\excel97-2003.xls", excel, workbooks)
91
- showMethodsAndProperties(workbooks)
92
- workbooks.Release()
93
- // oleutil.CallMethod(excel, "Quit")
94
- excel.Release()
95
- ole.CoUninitialize()
96
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/ie/ie.go
deleted
-33
@@ -1,33 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "time"
7
-
8
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10
-)
11
-
12
-func main() {
13
- ole.CoInitialize(0)
14
- unknown, _ := oleutil.CreateObject("InternetExplorer.Application")
15
- ie, _ := unknown.QueryInterface(ole.IID_IDispatch)
16
- oleutil.CallMethod(ie, "Navigate", "http://www.google.com")
17
- oleutil.PutProperty(ie, "Visible", true)
18
- for {
19
- if oleutil.MustGetProperty(ie, "Busy").Val == 0 {
20
- break
21
- }
22
- }
23
-
24
- time.Sleep(1e9)
25
-
26
- document := oleutil.MustGetProperty(ie, "document").ToIDispatch()
27
- window := oleutil.MustGetProperty(document, "parentWindow").ToIDispatch()
28
- // set 'golang' to text box.
29
- oleutil.MustCallMethod(window, "eval", "document.getElementsByName('q')[0].value = 'golang'")
30
- // click btnG.
31
- btnG := oleutil.MustCallMethod(window, "eval", "document.getElementsByName('btnG')[0]").ToIDispatch()
32
- oleutil.MustCallMethod(btnG, "click")
33
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/itunes/itunes.go
deleted
-47
@@ -1,47 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "log"
7
- "os"
8
- "strings"
9
-
10
- "github.com/gonuts/commander"
11
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
12
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
13
-)
14
-
15
-func iTunes() *ole.IDispatch {
16
- ole.CoInitialize(0)
17
- unknown, err := oleutil.CreateObject("iTunes.Application")
18
- if err != nil {
19
- log.Fatal(err)
20
- }
21
- itunes, err := unknown.QueryInterface(ole.IID_IDispatch)
22
- if err != nil {
23
- log.Fatal(err)
24
- }
25
- return itunes
26
-}
27
-
28
-func main() {
29
- command := &commander.Command{
30
- UsageLine: os.Args[0],
31
- Short: "itunes cmd",
32
- }
33
- command.Subcommands = []*commander.Command{}
34
- for _, name := range []string{"Play", "Stop", "Pause", "Quit"} {
35
- command.Subcommands = append(command.Subcommands, &commander.Command{
36
- Run: func(cmd *commander.Command, args []string) error {
37
- _, err := oleutil.CallMethod(iTunes(), name)
38
- return err
39
- },
40
- UsageLine: strings.ToLower(name),
41
- })
42
- }
43
- err := command.Dispatch(os.Args[1:])
44
- if err != nil {
45
- log.Fatal(err)
46
- }
47
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/mediaplayer/mediaplayer.go
deleted
-29
@@ -1,29 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "fmt"
7
- "log"
8
-
9
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
11
-)
12
-
13
-func main() {
14
- ole.CoInitialize(0)
15
- unknown, err := oleutil.CreateObject("WMPlayer.OCX")
16
- if err != nil {
17
- log.Fatal(err)
18
- }
19
- wmp := unknown.MustQueryInterface(ole.IID_IDispatch)
20
- collection := oleutil.MustGetProperty(wmp, "MediaCollection").ToIDispatch()
21
- list := oleutil.MustCallMethod(collection, "getAll").ToIDispatch()
22
- count := int(oleutil.MustGetProperty(list, "count").Val)
23
- for i := 0; i < count; i++ {
24
- item := oleutil.MustGetProperty(list, "item", i).ToIDispatch()
25
- name := oleutil.MustGetProperty(item, "name").ToString()
26
- sourceURL := oleutil.MustGetProperty(item, "sourceURL").ToString()
27
- fmt.Println(name, sourceURL)
28
- }
29
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/msagent/msagent.go
deleted
-24
@@ -1,24 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "time"
7
-
8
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10
-)
11
-
12
-func main() {
13
- ole.CoInitialize(0)
14
- unknown, _ := oleutil.CreateObject("Agent.Control.1")
15
- agent, _ := unknown.QueryInterface(ole.IID_IDispatch)
16
- oleutil.PutProperty(agent, "Connected", true)
17
- characters := oleutil.MustGetProperty(agent, "Characters").ToIDispatch()
18
- oleutil.CallMethod(characters, "Load", "Merlin", "c:\\windows\\msagent\\chars\\Merlin.acs")
19
- character := oleutil.MustCallMethod(characters, "Character", "Merlin").ToIDispatch()
20
- oleutil.CallMethod(character, "Show")
21
- oleutil.CallMethod(character, "Speak", "こんにちわ世界")
22
-
23
- time.Sleep(4000000000)
24
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/msxml/rssreader.go
deleted
-49
@@ -1,49 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "fmt"
7
- "time"
8
-
9
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
11
-)
12
-
13
-func main() {
14
- ole.CoInitialize(0)
15
- unknown, _ := oleutil.CreateObject("Microsoft.XMLHTTP")
16
- xmlhttp, _ := unknown.QueryInterface(ole.IID_IDispatch)
17
- _, err := oleutil.CallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false)
18
- if err != nil {
19
- panic(err.Error())
20
- }
21
- _, err = oleutil.CallMethod(xmlhttp, "send", nil)
22
- if err != nil {
23
- panic(err.Error())
24
- }
25
- state := -1
26
- for state != 4 {
27
- state = int(oleutil.MustGetProperty(xmlhttp, "readyState").Val)
28
- time.Sleep(10000000)
29
- }
30
- responseXml := oleutil.MustGetProperty(xmlhttp, "responseXml").ToIDispatch()
31
- items := oleutil.MustCallMethod(responseXml, "selectNodes", "/rss/channel/item").ToIDispatch()
32
- length := int(oleutil.MustGetProperty(items, "length").Val)
33
-
34
- for n := 0; n < length; n++ {
35
- item := oleutil.MustGetProperty(items, "item", n).ToIDispatch()
36
-
37
- title := oleutil.MustCallMethod(item, "selectSingleNode", "title").ToIDispatch()
38
- fmt.Println(oleutil.MustGetProperty(title, "text").ToString())
39
-
40
- link := oleutil.MustCallMethod(item, "selectSingleNode", "link").ToIDispatch()
41
- fmt.Println(" " + oleutil.MustGetProperty(link, "text").ToString())
42
-
43
- title.Release()
44
- link.Release()
45
- item.Release()
46
- }
47
- items.Release()
48
- xmlhttp.Release()
49
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/outlook/outlook.go
deleted
-29
@@ -1,29 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "fmt"
7
-
8
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10
-)
11
-
12
-func main() {
13
- ole.CoInitialize(0)
14
- unknown, _ := oleutil.CreateObject("Outlook.Application")
15
- outlook, _ := unknown.QueryInterface(ole.IID_IDispatch)
16
- ns := oleutil.MustCallMethod(outlook, "GetNamespace", "MAPI").ToIDispatch()
17
- folder := oleutil.MustCallMethod(ns, "GetDefaultFolder", 10).ToIDispatch()
18
- contacts := oleutil.MustCallMethod(folder, "Items").ToIDispatch()
19
- count := oleutil.MustGetProperty(contacts, "Count").Value().(int32)
20
- for i := 1; i <= int(count); i++ {
21
- item, err := oleutil.GetProperty(contacts, "Item", i)
22
- if err == nil && item.VT == ole.VT_DISPATCH {
23
- if value, err := oleutil.GetProperty(item.ToIDispatch(), "FullName"); err == nil {
24
- fmt.Println(value.Value())
25
- }
26
- }
27
- }
28
- oleutil.MustCallMethod(outlook, "Quit")
29
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/winsock/winsock.go
deleted
-140
@@ -1,140 +0,0 @@
1
-// +build windows
2
-
3
-package main
4
-
5
-import (
6
- "log"
7
- "syscall"
8
- "unsafe"
9
-
10
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
11
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
12
-)
13
-
14
-type EventReceiver struct {
15
- lpVtbl *EventReceiverVtbl
16
- ref int32
17
- host *ole.IDispatch
18
-}
19
-
20
-type EventReceiverVtbl struct {
21
- pQueryInterface uintptr
22
- pAddRef uintptr
23
- pRelease uintptr
24
- pGetTypeInfoCount uintptr
25
- pGetTypeInfo uintptr
26
- pGetIDsOfNames uintptr
27
- pInvoke uintptr
28
-}
29
-
30
-func QueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 {
31
- s, _ := ole.StringFromCLSID(iid)
32
- *punk = nil
33
- if ole.IsEqualGUID(iid, ole.IID_IUnknown) ||
34
- ole.IsEqualGUID(iid, ole.IID_IDispatch) {
35
- AddRef(this)
36
- *punk = this
37
- return ole.S_OK
38
- }
39
- if s == "{248DD893-BB45-11CF-9ABC-0080C7E7B78D}" {
40
- AddRef(this)
41
- *punk = this
42
- return ole.S_OK
43
- }
44
- return ole.E_NOINTERFACE
45
-}
46
-
47
-func AddRef(this *ole.IUnknown) int32 {
48
- pthis := (*EventReceiver)(unsafe.Pointer(this))
49
- pthis.ref++
50
- return pthis.ref
51
-}
52
-
53
-func Release(this *ole.IUnknown) int32 {
54
- pthis := (*EventReceiver)(unsafe.Pointer(this))
55
- pthis.ref--
56
- return pthis.ref
57
-}
58
-
59
-func GetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
60
- for n := 0; n < namelen; n++ {
61
- pdisp[n] = int32(n)
62
- }
63
- return uintptr(ole.S_OK)
64
-}
65
-
66
-func GetTypeInfoCount(pcount *int) uintptr {
67
- if pcount != nil {
68
- *pcount = 0
69
- }
70
- return uintptr(ole.S_OK)
71
-}
72
-
73
-func GetTypeInfo(ptypeif *uintptr) uintptr {
74
- return uintptr(ole.E_NOTIMPL)
75
-}
76
-
77
-func Invoke(this *ole.IDispatch, dispid int, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr {
78
- switch dispid {
79
- case 0:
80
- log.Println("DataArrival")
81
- winsock := (*EventReceiver)(unsafe.Pointer(this)).host
82
- var data ole.VARIANT
83
- ole.VariantInit(&data)
84
- oleutil.CallMethod(winsock, "GetData", &data)
85
- s := string(data.ToArray().ToByteArray())
86
- println()
87
- println(s)
88
- println()
89
- case 1:
90
- log.Println("Connected")
91
- winsock := (*EventReceiver)(unsafe.Pointer(this)).host
92
- oleutil.CallMethod(winsock, "SendData", "GET / HTTP/1.0\r\n\r\n")
93
- case 3:
94
- log.Println("SendProgress")
95
- case 4:
96
- log.Println("SendComplete")
97
- case 5:
98
- log.Println("Close")
99
- this.Release()
100
- case 6:
101
- log.Fatal("Error")
102
- default:
103
- log.Println(dispid)
104
- }
105
- return ole.E_NOTIMPL
106
-}
107
-
108
-func main() {
109
- ole.CoInitialize(0)
110
-
111
- unknown, err := oleutil.CreateObject("{248DD896-BB45-11CF-9ABC-0080C7E7B78D}")
112
- if err != nil {
113
- panic(err.Error())
114
- }
115
- winsock, _ := unknown.QueryInterface(ole.IID_IDispatch)
116
- iid, _ := ole.CLSIDFromString("{248DD893-BB45-11CF-9ABC-0080C7E7B78D}")
117
-
118
- dest := &EventReceiver{}
119
- dest.lpVtbl = &EventReceiverVtbl{}
120
- dest.lpVtbl.pQueryInterface = syscall.NewCallback(QueryInterface)
121
- dest.lpVtbl.pAddRef = syscall.NewCallback(AddRef)
122
- dest.lpVtbl.pRelease = syscall.NewCallback(Release)
123
- dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(GetTypeInfoCount)
124
- dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(GetTypeInfo)
125
- dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(GetIDsOfNames)
126
- dest.lpVtbl.pInvoke = syscall.NewCallback(Invoke)
127
- dest.host = winsock
128
-
129
- oleutil.ConnectObject(winsock, iid, (*ole.IUnknown)(unsafe.Pointer(dest)))
130
- _, err = oleutil.CallMethod(winsock, "Connect", "127.0.0.1", 80)
131
- if err != nil {
132
- log.Fatal(err)
133
- }
134
-
135
- var m ole.Msg
136
- for dest.ref != 0 {
137
- ole.GetMessage(&m, 0, 0, 0)
138
- ole.DispatchMessage(&m)
139
- }
140
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/guid.go
deleted
-115
@@ -1,115 +0,0 @@
1
-package ole
2
-
3
-var (
4
- // IID_NULL is null Interface ID, used when no other Interface ID is known.
5
- IID_NULL = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
6
-
7
- // IID_IUnknown is for IUnknown interfaces.
8
- IID_IUnknown = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
9
-
10
- // IID_IDispatch is for IDispatch interfaces.
11
- IID_IDispatch = &GUID{0x00020400, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
12
-
13
- // IID_IConnectionPointContainer is for IConnectionPointContainer interfaces.
14
- IID_IConnectionPointContainer = &GUID{0xB196B284, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
15
-
16
- // IID_IConnectionPoint is for IConnectionPoint interfaces.
17
- IID_IConnectionPoint = &GUID{0xB196B286, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
18
-
19
- // IID_IInspectable is for IInspectable interfaces.
20
- IID_IInspectable = &GUID{0xaf86e2e0, 0xb12d, 0x4c6a, [8]byte{0x9c, 0x5a, 0xd7, 0xaa, 0x65, 0x10, 0x1e, 0x90}}
21
-
22
- // IID_IProvideClassInfo is for IProvideClassInfo interfaces.
23
- IID_IProvideClassInfo = &GUID{0xb196b283, 0xbab4, 0x101a, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
24
-)
25
-
26
-// These are for testing and not part of any library.
27
-var (
28
- // IID_ICOMTestString is for ICOMTestString interfaces.
29
- //
30
- // {E0133EB4-C36F-469A-9D3D-C66B84BE19ED}
31
- IID_ICOMTestString = &GUID{0xe0133eb4, 0xc36f, 0x469a, [8]byte{0x9d, 0x3d, 0xc6, 0x6b, 0x84, 0xbe, 0x19, 0xed}}
32
-
33
- // IID_ICOMTestInt8 is for ICOMTestInt8 interfaces.
34
- //
35
- // {BEB06610-EB84-4155-AF58-E2BFF53608B4}
36
- IID_ICOMTestInt8 = &GUID{0xbeb06610, 0xeb84, 0x4155, [8]byte{0xaf, 0x58, 0xe2, 0xbf, 0xf5, 0x36, 0x80, 0xb4}}
37
-
38
- // IID_ICOMTestInt16 is for ICOMTestInt16 interfaces.
39
- //
40
- // {DAA3F9FA-761E-4976-A860-8364CE55F6FC}
41
- IID_ICOMTestInt16 = &GUID{0xdaa3f9fa, 0x761e, 0x4976, [8]byte{0xa8, 0x60, 0x83, 0x64, 0xce, 0x55, 0xf6, 0xfc}}
42
-
43
- // IID_ICOMTestInt32 is for ICOMTestInt32 interfaces.
44
- //
45
- // {E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}
46
- IID_ICOMTestInt32 = &GUID{0xe3dedee7, 0x38a2, 0x4540, [8]byte{0x91, 0xd1, 0x2e, 0xef, 0x1d, 0x88, 0x91, 0xb0}}
47
-
48
- // IID_ICOMTestInt64 is for ICOMTestInt64 interfaces.
49
- //
50
- // {8D437CBC-B3ED-485C-BC32-C336432A1623}
51
- IID_ICOMTestInt64 = &GUID{0x8d437cbc, 0xb3ed, 0x485c, [8]byte{0xbc, 0x32, 0xc3, 0x36, 0x43, 0x2a, 0x16, 0x23}}
52
-
53
- // IID_ICOMTestFloat is for ICOMTestFloat interfaces.
54
- //
55
- // {BF1ED004-EA02-456A-AA55-2AC8AC6B054C}
56
- IID_ICOMTestFloat = &GUID{0xbf1ed004, 0xea02, 0x456a, [8]byte{0xaa, 0x55, 0x2a, 0xc8, 0xac, 0x6b, 0x5, 0x4c}}
57
-
58
- // IID_ICOMTestDouble is for ICOMTestDouble interfaces.
59
- //
60
- // {BF908A81-8687-4E93-999F-D86FAB284BA0}
61
- IID_ICOMTestDouble = &GUID{0xbf908a81, 0x8687, 0x4e93, [8]byte{0x99, 0x9f, 0xd8, 0x6f, 0xab, 0x28, 0x4b, 0xa0}}
62
-
63
- // IID_ICOMTestBoolean is for ICOMTestBoolean interfaces.
64
- //
65
- // {D530E7A6-4EE8-40D1-8931-3D63B8605001}
66
- IID_ICOMTestBoolean = &GUID{0xd530e7a6, 0x4ee8, 0x40d1, [8]byte{0x89, 0x31, 0x3d, 0x63, 0xb8, 0x60, 0x50, 0x10}}
67
-
68
- // IID_ICOMEchoTestObject is for ICOMEchoTestObject interfaces.
69
- //
70
- // {6485B1EF-D780-4834-A4FE-1EBB51746CA3}
71
- IID_ICOMEchoTestObject = &GUID{0x6485b1ef, 0xd780, 0x4834, [8]byte{0xa4, 0xfe, 0x1e, 0xbb, 0x51, 0x74, 0x6c, 0xa3}}
72
-
73
- // IID_ICOMTestTypes is for ICOMTestTypes interfaces.
74
- //
75
- // {CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}
76
- IID_ICOMTestTypes = &GUID{0xcca8d7ae, 0x91c0, 0x4277, [8]byte{0xa8, 0xb3, 0xff, 0x4e, 0xdf, 0x28, 0xd3, 0xc0}}
77
-
78
- // CLSID_COMEchoTestObject is for COMEchoTestObject class.
79
- //
80
- // {3C24506A-AE9E-4D50-9157-EF317281F1B0}
81
- CLSID_COMEchoTestObject = &GUID{0x3c24506a, 0xae9e, 0x4d50, [8]byte{0x91, 0x57, 0xef, 0x31, 0x72, 0x81, 0xf1, 0xb0}}
82
-
83
- // CLSID_COMTestScalarClass is for COMTestScalarClass class.
84
- //
85
- // {865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}
86
- CLSID_COMTestScalarClass = &GUID{0x865b85c5, 0x3340, 0x4ac6, [8]byte{0x9e, 0xf6, 0xaa, 0xce, 0xc8, 0xfc, 0x5e, 0x86}}
87
-)
88
-
89
-// GUID is Windows API specific GUID type.
90
-//
91
-// This exists to match Windows GUID type for direct passing for COM.
92
-// Format is in xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx.
93
-type GUID struct {
94
- Data1 uint32
95
- Data2 uint16
96
- Data3 uint16
97
- Data4 [8]byte
98
-}
99
-
100
-// IsEqualGUID compares two GUID.
101
-//
102
-// Not constant time comparison.
103
-func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
104
- return guid1.Data1 == guid2.Data1 &&
105
- guid1.Data2 == guid2.Data2 &&
106
- guid1.Data3 == guid2.Data3 &&
107
- guid1.Data4[0] == guid2.Data4[0] &&
108
- guid1.Data4[1] == guid2.Data4[1] &&
109
- guid1.Data4[2] == guid2.Data4[2] &&
110
- guid1.Data4[3] == guid2.Data4[3] &&
111
- guid1.Data4[4] == guid2.Data4[4] &&
112
- guid1.Data4[5] == guid2.Data4[5] &&
113
- guid1.Data4[6] == guid2.Data4[6] &&
114
- guid1.Data4[7] == guid2.Data4[7]
115
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint.go
deleted
-20
@@ -1,20 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type IConnectionPoint struct {
6
- IUnknown
7
-}
8
-
9
-type IConnectionPointVtbl struct {
10
- IUnknownVtbl
11
- GetConnectionInterface uintptr
12
- GetConnectionPointContainer uintptr
13
- Advise uintptr
14
- Unadvise uintptr
15
- EnumConnections uintptr
16
-}
17
-
18
-func (v *IConnectionPoint) VTable() *IConnectionPointVtbl {
19
- return (*IConnectionPointVtbl)(unsafe.Pointer(v.RawVTable))
20
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_func.go
deleted
-21
@@ -1,21 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-import "unsafe"
6
-
7
-func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
8
- return int32(0)
9
-}
10
-
11
-func (v *IConnectionPoint) Advise(unknown *IUnknown) (uint32, error) {
12
- return uint32(0), NewError(E_NOTIMPL)
13
-}
14
-
15
-func (v *IConnectionPoint) Unadvise(cookie uint32) error {
16
- return NewError(E_NOTIMPL)
17
-}
18
-
19
-func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) (err error) {
20
- return NewError(E_NOTIMPL)
21
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_windows.go
deleted
-43
@@ -1,43 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-)
9
-
10
-func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
11
- // XXX: This doesn't look like it does what it's supposed to
12
- return release((*IUnknown)(unsafe.Pointer(v)))
13
-}
14
-
15
-func (v *IConnectionPoint) Advise(unknown *IUnknown) (cookie uint32, err error) {
16
- hr, _, _ := syscall.Syscall(
17
- v.VTable().Advise,
18
- 3,
19
- uintptr(unsafe.Pointer(v)),
20
- uintptr(unsafe.Pointer(unknown)),
21
- uintptr(unsafe.Pointer(&cookie)))
22
- if hr != 0 {
23
- err = NewError(hr)
24
- }
25
- return
26
-}
27
-
28
-func (v *IConnectionPoint) Unadvise(cookie uint32) (err error) {
29
- hr, _, _ := syscall.Syscall(
30
- v.VTable().Unadvise,
31
- 2,
32
- uintptr(unsafe.Pointer(v)),
33
- uintptr(cookie),
34
- 0)
35
- if hr != 0 {
36
- err = NewError(hr)
37
- }
38
- return
39
-}
40
-
41
-func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) error {
42
- return NewError(E_NOTIMPL)
43
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer.go
deleted
-17
@@ -1,17 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type IConnectionPointContainer struct {
6
- IUnknown
7
-}
8
-
9
-type IConnectionPointContainerVtbl struct {
10
- IUnknownVtbl
11
- EnumConnectionPoints uintptr
12
- FindConnectionPoint uintptr
13
-}
14
-
15
-func (v *IConnectionPointContainer) VTable() *IConnectionPointContainerVtbl {
16
- return (*IConnectionPointContainerVtbl)(unsafe.Pointer(v.RawVTable))
17
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go
deleted
-11
@@ -1,11 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
6
- return NewError(E_NOTIMPL)
7
-}
8
-
9
-func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) error {
10
- return NewError(E_NOTIMPL)
11
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go
deleted
-25
@@ -1,25 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-)
9
-
10
-func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
11
- return NewError(E_NOTIMPL)
12
-}
13
-
14
-func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) (err error) {
15
- hr, _, _ := syscall.Syscall(
16
- v.VTable().FindConnectionPoint,
17
- 3,
18
- uintptr(unsafe.Pointer(v)),
19
- uintptr(unsafe.Pointer(iid)),
20
- uintptr(unsafe.Pointer(point)))
21
- if hr != 0 {
22
- err = NewError(hr)
23
- }
24
- return
25
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch.go
deleted
-39
@@ -1,39 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type IDispatch struct {
6
- IUnknown
7
-}
8
-
9
-type IDispatchVtbl struct {
10
- IUnknownVtbl
11
- GetTypeInfoCount uintptr
12
- GetTypeInfo uintptr
13
- GetIDsOfNames uintptr
14
- Invoke uintptr
15
-}
16
-
17
-func (v *IDispatch) VTable() *IDispatchVtbl {
18
- return (*IDispatchVtbl)(unsafe.Pointer(v.RawVTable))
19
-}
20
-
21
-func (v *IDispatch) GetIDsOfName(names []string) (dispid []int32, err error) {
22
- dispid, err = getIDsOfName(v, names)
23
- return
24
-}
25
-
26
-func (v *IDispatch) Invoke(dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
27
- result, err = invoke(v, dispid, dispatch, params...)
28
- return
29
-}
30
-
31
-func (v *IDispatch) GetTypeInfoCount() (c uint32, err error) {
32
- c, err = getTypeInfoCount(v)
33
- return
34
-}
35
-
36
-func (v *IDispatch) GetTypeInfo() (tinfo *ITypeInfo, err error) {
37
- tinfo, err = getTypeInfo(v)
38
- return
39
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_func.go
deleted
-19
@@ -1,19 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-func getIDsOfName(disp *IDispatch, names []string) ([]int32, error) {
6
- return []int32{}, NewError(E_NOTIMPL)
7
-}
8
-
9
-func getTypeInfoCount(disp *IDispatch) (uint32, error) {
10
- return uint32(0), NewError(E_NOTIMPL)
11
-}
12
-
13
-func getTypeInfo(disp *IDispatch) (*ITypeInfo, error) {
14
- return nil, NewError(E_NOTIMPL)
15
-}
16
-
17
-func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (*VARIANT, error) {
18
- return nil, NewError(E_NOTIMPL)
19
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows.go
deleted
-184
@@ -1,184 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "syscall"
7
- "time"
8
- "unsafe"
9
-)
10
-
11
-func getIDsOfName(disp *IDispatch, names []string) (dispid []int32, err error) {
12
- wnames := make([]*uint16, len(names))
13
- for i := 0; i < len(names); i++ {
14
- wnames[i] = syscall.StringToUTF16Ptr(names[i])
15
- }
16
- dispid = make([]int32, len(names))
17
- namelen := uint32(len(names))
18
- hr, _, _ := syscall.Syscall6(
19
- disp.VTable().GetIDsOfNames,
20
- 6,
21
- uintptr(unsafe.Pointer(disp)),
22
- uintptr(unsafe.Pointer(IID_NULL)),
23
- uintptr(unsafe.Pointer(&wnames[0])),
24
- uintptr(namelen),
25
- uintptr(GetUserDefaultLCID()),
26
- uintptr(unsafe.Pointer(&dispid[0])))
27
- if hr != 0 {
28
- err = NewError(hr)
29
- }
30
- return
31
-}
32
-
33
-func getTypeInfoCount(disp *IDispatch) (c uint32, err error) {
34
- hr, _, _ := syscall.Syscall(
35
- disp.VTable().GetTypeInfoCount,
36
- 2,
37
- uintptr(unsafe.Pointer(disp)),
38
- uintptr(unsafe.Pointer(&c)),
39
- 0)
40
- if hr != 0 {
41
- err = NewError(hr)
42
- }
43
- return
44
-}
45
-
46
-func getTypeInfo(disp *IDispatch) (tinfo *ITypeInfo, err error) {
47
- hr, _, _ := syscall.Syscall(
48
- disp.VTable().GetTypeInfo,
49
- 3,
50
- uintptr(unsafe.Pointer(disp)),
51
- uintptr(GetUserDefaultLCID()),
52
- uintptr(unsafe.Pointer(&tinfo)))
53
- if hr != 0 {
54
- err = NewError(hr)
55
- }
56
- return
57
-}
58
-
59
-func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
60
- var dispparams DISPPARAMS
61
-
62
- if dispatch&DISPATCH_PROPERTYPUT != 0 {
63
- dispnames := [1]int32{DISPID_PROPERTYPUT}
64
- dispparams.rgdispidNamedArgs = uintptr(unsafe.Pointer(&dispnames[0]))
65
- dispparams.cNamedArgs = 1
66
- }
67
- var vargs []VARIANT
68
- if len(params) > 0 {
69
- vargs = make([]VARIANT, len(params))
70
- for i, v := range params {
71
- //n := len(params)-i-1
72
- n := len(params) - i - 1
73
- VariantInit(&vargs[n])
74
- switch vv := v.(type) {
75
- case bool:
76
- if vv {
77
- vargs[n] = NewVariant(VT_BOOL, 0xffff)
78
- } else {
79
- vargs[n] = NewVariant(VT_BOOL, 0)
80
- }
81
- case *bool:
82
- vargs[n] = NewVariant(VT_BOOL|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*bool)))))
83
- case byte:
84
- vargs[n] = NewVariant(VT_I1, int64(v.(byte)))
85
- case *byte:
86
- vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*byte)))))
87
- case int16:
88
- vargs[n] = NewVariant(VT_I2, int64(v.(int16)))
89
- case *int16:
90
- vargs[n] = NewVariant(VT_I2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int16)))))
91
- case uint16:
92
- vargs[n] = NewVariant(VT_UI2, int64(v.(uint16)))
93
- case *uint16:
94
- vargs[n] = NewVariant(VT_UI2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint16)))))
95
- case int, int32:
96
- vargs[n] = NewVariant(VT_I4, int64(v.(int)))
97
- case *int, *int32:
98
- vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int)))))
99
- case uint, uint32:
100
- vargs[n] = NewVariant(VT_UI4, int64(v.(uint)))
101
- case *uint, *uint32:
102
- vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint)))))
103
- case int64:
104
- vargs[n] = NewVariant(VT_I8, int64(v.(int64)))
105
- case *int64:
106
- vargs[n] = NewVariant(VT_I8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int64)))))
107
- case uint64:
108
- vargs[n] = NewVariant(VT_UI8, v.(int64))
109
- case *uint64:
110
- vargs[n] = NewVariant(VT_UI8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint64)))))
111
- case float32:
112
- vargs[n] = NewVariant(VT_R4, *(*int64)(unsafe.Pointer(&vv)))
113
- case *float32:
114
- vargs[n] = NewVariant(VT_R4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float32)))))
115
- case float64:
116
- vargs[n] = NewVariant(VT_R8, *(*int64)(unsafe.Pointer(&vv)))
117
- case *float64:
118
- vargs[n] = NewVariant(VT_R8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float64)))))
119
- case string:
120
- vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(v.(string))))))
121
- case *string:
122
- vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*string)))))
123
- case time.Time:
124
- s := vv.Format("2006-01-02 15:04:05")
125
- vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(s)))))
126
- case *time.Time:
127
- s := vv.Format("2006-01-02 15:04:05")
128
- vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(&s))))
129
- case *IDispatch:
130
- vargs[n] = NewVariant(VT_DISPATCH, int64(uintptr(unsafe.Pointer(v.(*IDispatch)))))
131
- case **IDispatch:
132
- vargs[n] = NewVariant(VT_DISPATCH|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(**IDispatch)))))
133
- case nil:
134
- vargs[n] = NewVariant(VT_NULL, 0)
135
- case *VARIANT:
136
- vargs[n] = NewVariant(VT_VARIANT|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*VARIANT)))))
137
- case []byte:
138
- safeByteArray := safeArrayFromByteSlice(v.([]byte))
139
- vargs[n] = NewVariant(VT_ARRAY|VT_UI1, int64(uintptr(unsafe.Pointer(safeByteArray))))
140
- defer VariantClear(&vargs[n])
141
- case []string:
142
- safeByteArray := safeArrayFromStringSlice(v.([]string))
143
- vargs[n] = NewVariant(VT_ARRAY|VT_BSTR, int64(uintptr(unsafe.Pointer(safeByteArray))))
144
- defer VariantClear(&vargs[n])
145
- default:
146
- panic("unknown type")
147
- }
148
- }
149
- dispparams.rgvarg = uintptr(unsafe.Pointer(&vargs[0]))
150
- dispparams.cArgs = uint32(len(params))
151
- }
152
-
153
- result = new(VARIANT)
154
- var excepInfo EXCEPINFO
155
- VariantInit(result)
156
- hr, _, _ := syscall.Syscall9(
157
- disp.VTable().Invoke,
158
- 9,
159
- uintptr(unsafe.Pointer(disp)),
160
- uintptr(dispid),
161
- uintptr(unsafe.Pointer(IID_NULL)),
162
- uintptr(GetUserDefaultLCID()),
163
- uintptr(dispatch),
164
- uintptr(unsafe.Pointer(&dispparams)),
165
- uintptr(unsafe.Pointer(result)),
166
- uintptr(unsafe.Pointer(&excepInfo)),
167
- 0)
168
- if hr != 0 {
169
- err = NewErrorWithSubError(hr, BstrToString(excepInfo.bstrDescription), excepInfo)
170
- }
171
- for _, varg := range vargs {
172
- if varg.VT == VT_BSTR && varg.Val != 0 {
173
- SysFreeString(((*int16)(unsafe.Pointer(uintptr(varg.Val)))))
174
- }
175
- /*
176
- if varg.VT == (VT_BSTR|VT_BYREF) && varg.Val != 0 {
177
- *(params[n].(*string)) = LpOleStrToString((*uint16)(unsafe.Pointer(uintptr(varg.Val))))
178
- println(*(params[n].(*string)))
179
- fmt.Fprintln(os.Stderr, *(params[n].(*string)))
180
- }
181
- */
182
- }
183
- return
184
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows_test.go
deleted
-83
@@ -1,83 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "reflect"
7
- "testing"
8
-)
9
-
10
-func TestIDispatch(t *testing.T) {
11
- defer func() {
12
- if r := recover(); r != nil {
13
- t.Error(r)
14
- }
15
- }()
16
-
17
- var err error
18
-
19
- err = CoInitialize(0)
20
- if err != nil {
21
- t.Fatal(err)
22
- }
23
-
24
- defer CoUninitialize()
25
-
26
- var unknown *IUnknown
27
- var dispatch *IDispatch
28
-
29
- // oleutil.CreateObject()
30
- unknown, err = CreateInstance(CLSID_COMEchoTestObject, IID_IUnknown)
31
- if err != nil {
32
- t.Fatal(err)
33
- return
34
- }
35
- defer unknown.Release()
36
-
37
- dispatch, err = unknown.QueryInterface(IID_ICOMEchoTestObject)
38
- if err != nil {
39
- t.Fatal(err)
40
- return
41
- }
42
- defer dispatch.Release()
43
-
44
- echoValue := func(method string, value interface{}) (interface{}, bool) {
45
- var dispid []int32
46
- var err error
47
-
48
- dispid, err = dispatch.GetIDsOfName([]string{method})
49
- if err != nil {
50
- t.Fatal(err)
51
- return nil, false
52
- }
53
-
54
- result, err := dispatch.Invoke(dispid[0], DISPATCH_METHOD, value)
55
- if err != nil {
56
- t.Fatal(err)
57
- return nil, false
58
- }
59
-
60
- return result.Value(), true
61
- }
62
-
63
- methods := map[string]interface{}{
64
- "EchoInt8": int8(1),
65
- "EchoInt16": int16(1),
66
- "EchoInt32": int32(1),
67
- "EchoInt64": int64(1),
68
- "EchoUInt8": uint8(1),
69
- "EchoUInt16": uint16(1),
70
- "EchoUInt32": uint(1),
71
- "EchoUInt64": uint64(1),
72
- "EchoFloat32": float32(1.2),
73
- "EchoFloat64": float64(1.2),
74
- "EchoString": "Test String"}
75
-
76
- for method, expected := range methods {
77
- if actual, passed := echoValue(method, expected); passed {
78
- if !reflect.DeepEqual(expected, actual) {
79
- t.Errorf("%s() expected %v did not match %v", method, expected, actual)
80
- }
81
- }
82
- }
83
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant.go
deleted
-19
@@ -1,19 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type IEnumVARIANT struct {
6
- IUnknown
7
-}
8
-
9
-type IEnumVARIANTVtbl struct {
10
- IUnknownVtbl
11
- Next uintptr
12
- Skip uintptr
13
- Reset uintptr
14
- Clone uintptr
15
-}
16
-
17
-func (v *IEnumVARIANT) VTable() *IEnumVARIANTVtbl {
18
- return (*IEnumVARIANTVtbl)(unsafe.Pointer(v.RawVTable))
19
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_func.go
deleted
-19
@@ -1,19 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-func (enum *IEnumVARIANT) Clone() (*IEnumVARIANT, error) {
6
- return nil, NewError(E_NOTIMPL)
7
-}
8
-
9
-func (enum *IEnumVARIANT) Reset() error {
10
- return NewError(E_NOTIMPL)
11
-}
12
-
13
-func (enum *IEnumVARIANT) Skip(celt uint) error {
14
- return NewError(E_NOTIMPL)
15
-}
16
-
17
-func (enum *IEnumVARIANT) Next(celt uint) (*VARIANT, uint, error) {
18
- return nil, 0, NewError(E_NOTIMPL)
19
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_windows.go
deleted
-63
@@ -1,63 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-)
9
-
10
-func (enum *IEnumVARIANT) Clone() (cloned *IEnumVARIANT, err error) {
11
- hr, _, _ := syscall.Syscall(
12
- enum.VTable().Clone,
13
- 2,
14
- uintptr(unsafe.Pointer(enum)),
15
- uintptr(unsafe.Pointer(&cloned)),
16
- 0)
17
- if hr != 0 {
18
- err = NewError(hr)
19
- }
20
- return
21
-}
22
-
23
-func (enum *IEnumVARIANT) Reset() (err error) {
24
- hr, _, _ := syscall.Syscall(
25
- enum.VTable().Reset,
26
- 1,
27
- uintptr(unsafe.Pointer(enum)),
28
- 0,
29
- 0)
30
- if hr != 0 {
31
- err = NewError(hr)
32
- }
33
- return
34
-}
35
-
36
-func (enum *IEnumVARIANT) Skip(celt uint) (err error) {
37
- hr, _, _ := syscall.Syscall(
38
- enum.VTable().Skip,
39
- 2,
40
- uintptr(unsafe.Pointer(enum)),
41
- uintptr(celt),
42
- 0)
43
- if hr != 0 {
44
- err = NewError(hr)
45
- }
46
- return
47
-}
48
-
49
-func (enum *IEnumVARIANT) Next(celt uint) (array *VARIANT, length uint, err error) {
50
- hr, _, _ := syscall.Syscall6(
51
- enum.VTable().Next,
52
- 4,
53
- uintptr(unsafe.Pointer(enum)),
54
- uintptr(celt),
55
- uintptr(unsafe.Pointer(&array)),
56
- uintptr(unsafe.Pointer(&length)),
57
- 0,
58
- 0)
59
- if hr != 0 {
60
- err = NewError(hr)
61
- }
62
- return
63
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable.go
deleted
-18
@@ -1,18 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type IInspectable struct {
6
- IUnknown
7
-}
8
-
9
-type IInspectableVtbl struct {
10
- IUnknownVtbl
11
- GetIIds uintptr
12
- GetRuntimeClassName uintptr
13
- GetTrustLevel uintptr
14
-}
15
-
16
-func (v *IInspectable) VTable() *IInspectableVtbl {
17
- return (*IInspectableVtbl)(unsafe.Pointer(v.RawVTable))
18
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_func.go
deleted
-15
@@ -1,15 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-func (v *IInspectable) GetIids() ([]*GUID, error) {
6
- return []*GUID{}, NewError(E_NOTIMPL)
7
-}
8
-
9
-func (v *IInspectable) GetRuntimeClassName() (string, error) {
10
- return "", NewError(E_NOTIMPL)
11
-}
12
-
13
-func (v *IInspectable) GetTrustLevel() (uint32, error) {
14
- return uint32(0), NewError(E_NOTIMPL)
15
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_windows.go
deleted
-72
@@ -1,72 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "bytes"
7
- "encoding/binary"
8
- "reflect"
9
- "syscall"
10
- "unsafe"
11
-)
12
-
13
-func (v *IInspectable) GetIids() (iids []*GUID, err error) {
14
- var count uint32
15
- var array uintptr
16
- hr, _, _ := syscall.Syscall(
17
- v.VTable().GetIIds,
18
- 3,
19
- uintptr(unsafe.Pointer(v)),
20
- uintptr(unsafe.Pointer(&count)),
21
- uintptr(unsafe.Pointer(&array)))
22
- if hr != 0 {
23
- err = NewError(hr)
24
- return
25
- }
26
- defer CoTaskMemFree(array)
27
-
28
- iids = make([]*GUID, count)
29
- byteCount := count * uint32(unsafe.Sizeof(GUID{}))
30
- slicehdr := reflect.SliceHeader{Data: array, Len: int(byteCount), Cap: int(byteCount)}
31
- byteSlice := *(*[]byte)(unsafe.Pointer(&slicehdr))
32
- reader := bytes.NewReader(byteSlice)
33
- for i, _ := range iids {
34
- guid := GUID{}
35
- err = binary.Read(reader, binary.LittleEndian, &guid)
36
- if err != nil {
37
- return
38
- }
39
- iids[i] = &guid
40
- }
41
- return
42
-}
43
-
44
-func (v *IInspectable) GetRuntimeClassName() (s string, err error) {
45
- var hstring HString
46
- hr, _, _ := syscall.Syscall(
47
- v.VTable().GetRuntimeClassName,
48
- 2,
49
- uintptr(unsafe.Pointer(v)),
50
- uintptr(unsafe.Pointer(&hstring)),
51
- 0)
52
- if hr != 0 {
53
- err = NewError(hr)
54
- return
55
- }
56
- s = hstring.String()
57
- DeleteHString(hstring)
58
- return
59
-}
60
-
61
-func (v *IInspectable) GetTrustLevel() (level uint32, err error) {
62
- hr, _, _ := syscall.Syscall(
63
- v.VTable().GetTrustLevel,
64
- 2,
65
- uintptr(unsafe.Pointer(v)),
66
- uintptr(unsafe.Pointer(&level)),
67
- 0)
68
- if hr != 0 {
69
- err = NewError(hr)
70
- }
71
- return
72
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo.go
deleted
-21
@@ -1,21 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type IProvideClassInfo struct {
6
- IUnknown
7
-}
8
-
9
-type IProvideClassInfoVtbl struct {
10
- IUnknownVtbl
11
- GetClassInfo uintptr
12
-}
13
-
14
-func (v *IProvideClassInfo) VTable() *IProvideClassInfoVtbl {
15
- return (*IProvideClassInfoVtbl)(unsafe.Pointer(v.RawVTable))
16
-}
17
-
18
-func (v *IProvideClassInfo) GetClassInfo() (cinfo *ITypeInfo, err error) {
19
- cinfo, err = getClassInfo(v)
20
- return
21
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_func.go
deleted
-7
@@ -1,7 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
6
- return nil, NewError(E_NOTIMPL)
7
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_windows.go
deleted
-21
@@ -1,21 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-)
9
-
10
-func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
11
- hr, _, _ := syscall.Syscall(
12
- disp.VTable().GetClassInfo,
13
- 2,
14
- uintptr(unsafe.Pointer(disp)),
15
- uintptr(unsafe.Pointer(&tinfo)),
16
- 0)
17
- if hr != 0 {
18
- err = NewError(hr)
19
- }
20
- return
21
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo.go
deleted
-34
@@ -1,34 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type ITypeInfo struct {
6
- IUnknown
7
-}
8
-
9
-type ITypeInfoVtbl struct {
10
- IUnknownVtbl
11
- GetTypeAttr uintptr
12
- GetTypeComp uintptr
13
- GetFuncDesc uintptr
14
- GetVarDesc uintptr
15
- GetNames uintptr
16
- GetRefTypeOfImplType uintptr
17
- GetImplTypeFlags uintptr
18
- GetIDsOfNames uintptr
19
- Invoke uintptr
20
- GetDocumentation uintptr
21
- GetDllEntry uintptr
22
- GetRefTypeInfo uintptr
23
- AddressOfMember uintptr
24
- CreateInstance uintptr
25
- GetMops uintptr
26
- GetContainingTypeLib uintptr
27
- ReleaseTypeAttr uintptr
28
- ReleaseFuncDesc uintptr
29
- ReleaseVarDesc uintptr
30
-}
31
-
32
-func (v *ITypeInfo) VTable() *ITypeInfoVtbl {
33
- return (*ITypeInfoVtbl)(unsafe.Pointer(v.RawVTable))
34
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_func.go
deleted
-7
@@ -1,7 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-func (v *ITypeInfo) GetTypeAttr() (*TYPEATTR, error) {
6
- return nil, NewError(E_NOTIMPL)
7
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_windows.go
deleted
-21
@@ -1,21 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-)
9
-
10
-func (v *ITypeInfo) GetTypeAttr() (tattr *TYPEATTR, err error) {
11
- hr, _, _ := syscall.Syscall(
12
- uintptr(v.VTable().GetTypeAttr),
13
- 2,
14
- uintptr(unsafe.Pointer(v)),
15
- uintptr(unsafe.Pointer(&tattr)),
16
- 0)
17
- if hr != 0 {
18
- err = NewError(hr)
19
- }
20
- return
21
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown.go
deleted
-57
@@ -1,57 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-type IUnknown struct {
6
- RawVTable *interface{}
7
-}
8
-
9
-type IUnknownVtbl struct {
10
- QueryInterface uintptr
11
- AddRef uintptr
12
- Release uintptr
13
-}
14
-
15
-type UnknownLike interface {
16
- QueryInterface(iid *GUID) (disp *IDispatch, err error)
17
- AddRef() int32
18
- Release() int32
19
-}
20
-
21
-func (v *IUnknown) VTable() *IUnknownVtbl {
22
- return (*IUnknownVtbl)(unsafe.Pointer(v.RawVTable))
23
-}
24
-
25
-func (v *IUnknown) PutQueryInterface(interfaceID *GUID, obj interface{}) error {
26
- return reflectQueryInterface(v, v.VTable().QueryInterface, interfaceID, &obj)
27
-}
28
-
29
-func (v *IUnknown) IDispatch(interfaceID *GUID) (dispatch *IDispatch, err error) {
30
- err = v.PutQueryInterface(interfaceID, &dispatch)
31
- return
32
-}
33
-
34
-func (v *IUnknown) IEnumVARIANT(interfaceID *GUID) (enum *IEnumVARIANT, err error) {
35
- err = v.PutQueryInterface(interfaceID, &enum)
36
- return
37
-}
38
-
39
-func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error) {
40
- return queryInterface(v, iid)
41
-}
42
-
43
-func (v *IUnknown) MustQueryInterface(iid *GUID) (disp *IDispatch) {
44
- unk, err := queryInterface(v, iid)
45
- if err != nil {
46
- panic(err)
47
- }
48
- return unk
49
-}
50
-
51
-func (v *IUnknown) AddRef() int32 {
52
- return addRef(v)
53
-}
54
-
55
-func (v *IUnknown) Release() int32 {
56
- return release(v)
57
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_func.go
deleted
-19
@@ -1,19 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
6
- return NewError(E_NOTIMPL)
7
-}
8
-
9
-func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
10
- return nil, NewError(E_NOTIMPL)
11
-}
12
-
13
-func addRef(unk *IUnknown) int32 {
14
- return 0
15
-}
16
-
17
-func release(unk *IUnknown) int32 {
18
- return 0
19
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows.go
deleted
-55
@@ -1,55 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "reflect"
7
- "syscall"
8
- "unsafe"
9
-)
10
-
11
-func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
12
- hr, _, _ := syscall.Syscall(
13
- method,
14
- 3,
15
- reflect.ValueOf(self).UnsafeAddr(),
16
- uintptr(unsafe.Pointer(interfaceID)),
17
- reflect.ValueOf(obj).UnsafeAddr())
18
- if hr != 0 {
19
- err = NewError(hr)
20
- }
21
- return
22
-}
23
-
24
-func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
25
- hr, _, _ := syscall.Syscall(
26
- unk.VTable().QueryInterface,
27
- 3,
28
- uintptr(unsafe.Pointer(unk)),
29
- uintptr(unsafe.Pointer(iid)),
30
- uintptr(unsafe.Pointer(&disp)))
31
- if hr != 0 {
32
- err = NewError(hr)
33
- }
34
- return
35
-}
36
-
37
-func addRef(unk *IUnknown) int32 {
38
- ret, _, _ := syscall.Syscall(
39
- unk.VTable().AddRef,
40
- 1,
41
- uintptr(unsafe.Pointer(unk)),
42
- 0,
43
- 0)
44
- return int32(ret)
45
-}
46
-
47
-func release(unk *IUnknown) int32 {
48
- ret, _, _ := syscall.Syscall(
49
- unk.VTable().Release,
50
- 1,
51
- uintptr(unsafe.Pointer(unk)),
52
- 0,
53
- 0)
54
- return int32(ret)
55
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows_test.go
deleted
-32
@@ -1,32 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import "testing"
6
-
7
-func TestIUnknown(t *testing.T) {
8
- defer func() {
9
- if r := recover(); r != nil {
10
- t.Error(r)
11
- }
12
- }()
13
-
14
- var err error
15
-
16
- err = CoInitialize(0)
17
- if err != nil {
18
- t.Fatal(err)
19
- }
20
-
21
- defer CoUninitialize()
22
-
23
- var unknown *IUnknown
24
-
25
- // oleutil.CreateObject()
26
- unknown, err = CreateInstance(CLSID_COMEchoTestObject, IID_IUnknown)
27
- if err != nil {
28
- t.Fatal(err)
29
- return
30
- }
31
- unknown.Release()
32
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/ole.go
deleted
-147
@@ -1,147 +0,0 @@
1
-package ole
2
-
3
-import (
4
- "fmt"
5
- "strings"
6
-)
7
-
8
-// DISPPARAMS are the arguments that passed to methods or property.
9
-type DISPPARAMS struct {
10
- rgvarg uintptr
11
- rgdispidNamedArgs uintptr
12
- cArgs uint32
13
- cNamedArgs uint32
14
-}
15
-
16
-// EXCEPINFO defines exception info.
17
-type EXCEPINFO struct {
18
- wCode uint16
19
- wReserved uint16
20
- bstrSource *uint16
21
- bstrDescription *uint16
22
- bstrHelpFile *uint16
23
- dwHelpContext uint32
24
- pvReserved uintptr
25
- pfnDeferredFillIn uintptr
26
- scode uint32
27
-}
28
-
29
-// String convert EXCEPINFO to string.
30
-func (e EXCEPINFO) String() string {
31
- var src, desc, hlp string
32
- if e.bstrSource == nil {
33
- src = "<nil>"
34
- } else {
35
- src = BstrToString(e.bstrSource)
36
- }
37
-
38
- if e.bstrDescription == nil {
39
- desc = "<nil>"
40
- } else {
41
- desc = BstrToString(e.bstrDescription)
42
- }
43
-
44
- if e.bstrHelpFile == nil {
45
- hlp = "<nil>"
46
- } else {
47
- hlp = BstrToString(e.bstrHelpFile)
48
- }
49
-
50
- return fmt.Sprintf(
51
- "wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
52
- e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
53
- )
54
-}
55
-
56
-// Error implements error interface and returns error string.
57
-func (e EXCEPINFO) Error() string {
58
- if e.bstrDescription != nil {
59
- return strings.TrimSpace(BstrToString(e.bstrDescription))
60
- }
61
-
62
- src := "Unknown"
63
- if e.bstrSource != nil {
64
- src = BstrToString(e.bstrSource)
65
- }
66
-
67
- code := e.scode
68
- if e.wCode != 0 {
69
- code = uint32(e.wCode)
70
- }
71
-
72
- return fmt.Sprintf("%v: %#x", src, code)
73
-}
74
-
75
-// PARAMDATA defines parameter data type.
76
-type PARAMDATA struct {
77
- Name *int16
78
- Vt uint16
79
-}
80
-
81
-// METHODDATA defines method info.
82
-type METHODDATA struct {
83
- Name *uint16
84
- Data *PARAMDATA
85
- Dispid int32
86
- Meth uint32
87
- CC int32
88
- CArgs uint32
89
- Flags uint16
90
- VtReturn uint32
91
-}
92
-
93
-// INTERFACEDATA defines interface info.
94
-type INTERFACEDATA struct {
95
- MethodData *METHODDATA
96
- CMembers uint32
97
-}
98
-
99
-// Point is 2D vector type.
100
-type Point struct {
101
- X int32
102
- Y int32
103
-}
104
-
105
-// Msg is message between processes.
106
-type Msg struct {
107
- Hwnd uint32
108
- Message uint32
109
- Wparam int32
110
- Lparam int32
111
- Time uint32
112
- Pt Point
113
-}
114
-
115
-// TYPEDESC defines data type.
116
-type TYPEDESC struct {
117
- Hreftype uint32
118
- VT uint16
119
-}
120
-
121
-// IDLDESC defines IDL info.
122
-type IDLDESC struct {
123
- DwReserved uint32
124
- WIDLFlags uint16
125
-}
126
-
127
-// TYPEATTR defines type info.
128
-type TYPEATTR struct {
129
- Guid GUID
130
- Lcid uint32
131
- dwReserved uint32
132
- MemidConstructor int32
133
- MemidDestructor int32
134
- LpstrSchema *uint16
135
- CbSizeInstance uint32
136
- Typekind int32
137
- CFuncs uint16
138
- CVars uint16
139
- CImplTypes uint16
140
- CbSizeVft uint16
141
- CbAlignment uint16
142
- WTypeFlags uint16
143
- WMajorVerNum uint16
144
- WMinorVerNum uint16
145
- TdescAlias TYPEDESC
146
- IdldescType IDLDESC
147
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection.go
deleted
-100
@@ -1,100 +0,0 @@
1
-// +build windows
2
-
3
-package oleutil
4
-
5
-import (
6
- "reflect"
7
- "unsafe"
8
-
9
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
10
-)
11
-
12
-type stdDispatch struct {
13
- lpVtbl *stdDispatchVtbl
14
- ref int32
15
- iid *ole.GUID
16
- iface interface{}
17
- funcMap map[string]int32
18
-}
19
-
20
-type stdDispatchVtbl struct {
21
- pQueryInterface uintptr
22
- pAddRef uintptr
23
- pRelease uintptr
24
- pGetTypeInfoCount uintptr
25
- pGetTypeInfo uintptr
26
- pGetIDsOfNames uintptr
27
- pInvoke uintptr
28
-}
29
-
30
-func dispQueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 {
31
- pthis := (*stdDispatch)(unsafe.Pointer(this))
32
- *punk = nil
33
- if ole.IsEqualGUID(iid, ole.IID_IUnknown) ||
34
- ole.IsEqualGUID(iid, ole.IID_IDispatch) {
35
- dispAddRef(this)
36
- *punk = this
37
- return ole.S_OK
38
- }
39
- if ole.IsEqualGUID(iid, pthis.iid) {
40
- dispAddRef(this)
41
- *punk = this
42
- return ole.S_OK
43
- }
44
- return ole.E_NOINTERFACE
45
-}
46
-
47
-func dispAddRef(this *ole.IUnknown) int32 {
48
- pthis := (*stdDispatch)(unsafe.Pointer(this))
49
- pthis.ref++
50
- return pthis.ref
51
-}
52
-
53
-func dispRelease(this *ole.IUnknown) int32 {
54
- pthis := (*stdDispatch)(unsafe.Pointer(this))
55
- pthis.ref--
56
- return pthis.ref
57
-}
58
-
59
-func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
60
- pthis := (*stdDispatch)(unsafe.Pointer(this))
61
- names := make([]string, len(wnames))
62
- for i := 0; i < len(names); i++ {
63
- names[i] = ole.LpOleStrToString(wnames[i])
64
- }
65
- for n := 0; n < namelen; n++ {
66
- if id, ok := pthis.funcMap[names[n]]; ok {
67
- pdisp[n] = id
68
- }
69
- }
70
- return ole.S_OK
71
-}
72
-
73
-func dispGetTypeInfoCount(pcount *int) uintptr {
74
- if pcount != nil {
75
- *pcount = 0
76
- }
77
- return ole.S_OK
78
-}
79
-
80
-func dispGetTypeInfo(ptypeif *uintptr) uintptr {
81
- return ole.E_NOTIMPL
82
-}
83
-
84
-func dispInvoke(this *ole.IDispatch, dispid int32, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr {
85
- pthis := (*stdDispatch)(unsafe.Pointer(this))
86
- found := ""
87
- for name, id := range pthis.funcMap {
88
- if id == dispid {
89
- found = name
90
- }
91
- }
92
- if found != "" {
93
- rv := reflect.ValueOf(pthis.iface).Elem()
94
- rm := rv.MethodByName(found)
95
- rr := rm.Call([]reflect.Value{})
96
- println(len(rr))
97
- return ole.S_OK
98
- }
99
- return ole.E_NOTIMPL
100
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_func.go
deleted
-10
@@ -1,10 +0,0 @@
1
-// +build !windows
2
-
3
-package oleutil
4
-
5
-import ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
6
-
7
-// ConnectObject creates a connection point between two services for communication.
8
-func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (uint32, error) {
9
- return 0, ole.NewError(ole.E_NOTIMPL)
10
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_windows.go
deleted
-57
@@ -1,57 +0,0 @@
1
-// +build windows
2
-
3
-package oleutil
4
-
5
-import (
6
- "reflect"
7
- "syscall"
8
- "unsafe"
9
-
10
- ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
11
-)
12
-
13
-// ConnectObject creates a connection point between two services for communication.
14
-func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (cookie uint32, err error) {
15
- unknown, err := disp.QueryInterface(ole.IID_IConnectionPointContainer)
16
- if err != nil {
17
- return
18
- }
19
-
20
- container := (*ole.IConnectionPointContainer)(unsafe.Pointer(unknown))
21
- var point *ole.IConnectionPoint
22
- err = container.FindConnectionPoint(iid, &point)
23
- if err != nil {
24
- return
25
- }
26
- if edisp, ok := idisp.(*ole.IUnknown); ok {
27
- cookie, err = point.Advise(edisp)
28
- container.Release()
29
- if err != nil {
30
- return
31
- }
32
- }
33
- rv := reflect.ValueOf(disp).Elem()
34
- if rv.Type().Kind() == reflect.Struct {
35
- dest := &stdDispatch{}
36
- dest.lpVtbl = &stdDispatchVtbl{}
37
- dest.lpVtbl.pQueryInterface = syscall.NewCallback(dispQueryInterface)
38
- dest.lpVtbl.pAddRef = syscall.NewCallback(dispAddRef)
39
- dest.lpVtbl.pRelease = syscall.NewCallback(dispRelease)
40
- dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(dispGetTypeInfoCount)
41
- dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(dispGetTypeInfo)
42
- dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(dispGetIDsOfNames)
43
- dest.lpVtbl.pInvoke = syscall.NewCallback(dispInvoke)
44
- dest.iface = disp
45
- dest.iid = iid
46
- cookie, err = point.Advise((*ole.IUnknown)(unsafe.Pointer(dest)))
47
- container.Release()
48
- if err != nil {
49
- point.Release()
50
- return
51
- }
52
- }
53
-
54
- container.Release()
55
-
56
- return 0, ole.NewError(ole.E_INVALIDARG)
57
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/go-get.go
deleted
-6
@@ -1,6 +0,0 @@
1
-// This file is here so go get succeeds as without it errors with:
2
-// no buildable Go source files in ...
3
-//
4
-// +build !windows
5
-
6
-package oleutil
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/oleutil.go
deleted
-132
@@ -1,132 +0,0 @@
1
-package oleutil
2
-
3
-import ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
4
-
5
-// ClassIDFrom retrieves class ID whether given is program ID or application string.
6
-func ClassIDFrom(programID string) (classID *ole.GUID, err error) {
7
- classID, err = ole.CLSIDFromProgID(programID)
8
- if err != nil {
9
- classID, err = ole.CLSIDFromString(programID)
10
- if err != nil {
11
- return
12
- }
13
- }
14
- return
15
-}
16
-
17
-// CreateObject creates object from programID based on interface type.
18
-//
19
-// Only supports IUnknown.
20
-//
21
-// Program ID can be either program ID or application string.
22
-func CreateObject(programID string) (unknown *ole.IUnknown, err error) {
23
- classID, err := ClassIDFrom(programID)
24
- if err != nil {
25
- return
26
- }
27
-
28
- unknown, err = ole.CreateInstance(classID, ole.IID_IUnknown)
29
- if err != nil {
30
- return
31
- }
32
-
33
- return
34
-}
35
-
36
-// GetActiveObject retrieves active object for program ID and interface ID based
37
-// on interface type.
38
-//
39
-// Only supports IUnknown.
40
-//
41
-// Program ID can be either program ID or application string.
42
-func GetActiveObject(programID string) (unknown *ole.IUnknown, err error) {
43
- classID, err := ClassIDFrom(programID)
44
- if err != nil {
45
- return
46
- }
47
-
48
- unknown, err = ole.GetActiveObject(classID, ole.IID_IUnknown)
49
- if err != nil {
50
- return
51
- }
52
-
53
- return
54
-}
55
-
56
-// CallMethod calls method on IDispatch with parameters.
57
-func CallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
58
- var dispid []int32
59
- dispid, err = disp.GetIDsOfName([]string{name})
60
- if err != nil {
61
- return
62
- }
63
-
64
- if len(params) < 1 {
65
- result, err = disp.Invoke(dispid[0], ole.DISPATCH_METHOD)
66
- } else {
67
- result, err = disp.Invoke(dispid[0], ole.DISPATCH_METHOD, params...)
68
- }
69
-
70
- return
71
-}
72
-
73
-// MustCallMethod calls method on IDispatch with parameters or panics.
74
-func MustCallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
75
- r, err := CallMethod(disp, name, params...)
76
- if err != nil {
77
- panic(err.Error())
78
- }
79
- return r
80
-}
81
-
82
-// GetProperty retrieves property from IDispatch.
83
-func GetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
84
- var dispid []int32
85
- dispid, err = disp.GetIDsOfName([]string{name})
86
- if err != nil {
87
- return
88
- }
89
-
90
- if len(params) < 1 {
91
- result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYGET)
92
- } else {
93
- result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYGET, params...)
94
- }
95
-
96
- return
97
-}
98
-
99
-// MustGetProperty retrieves property from IDispatch or panics.
100
-func MustGetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
101
- r, err := GetProperty(disp, name, params...)
102
- if err != nil {
103
- panic(err.Error())
104
- }
105
- return r
106
-}
107
-
108
-// PutProperty mutates property.
109
-func PutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
110
- var dispid []int32
111
- dispid, err = disp.GetIDsOfName([]string{name})
112
- if err != nil {
113
- return
114
- }
115
-
116
- if len(params) < 1 {
117
- result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYPUT)
118
- } else {
119
- result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYPUT, params...)
120
- }
121
-
122
- return
123
-}
124
-
125
-// MustPutProperty mutates property or panics.
126
-func MustPutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
127
- r, err := PutProperty(disp, name, params...)
128
- if err != nil {
129
- panic(err.Error())
130
- }
131
- return r
132
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray.go
deleted
-27
@@ -1,27 +0,0 @@
1
-// Package is meant to retrieve and process safe array data returned from COM.
2
-
3
-package ole
4
-
5
-// SafeArrayBound defines the SafeArray boundaries.
6
-type SafeArrayBound struct {
7
- Elements uint32
8
- LowerBound int32
9
-}
10
-
11
-// SafeArray is how COM handles arrays.
12
-type SafeArray struct {
13
- Dimensions uint16
14
- FeaturesFlag uint16
15
- ElementsSize uint32
16
- LocksAmount uint32
17
- Data uint32
18
- Bounds [16]byte
19
-}
20
-
21
-// SAFEARRAY is obsolete, exists for backwards compatibility.
22
-// Use SafeArray
23
-type SAFEARRAY SafeArray
24
-
25
-// SAFEARRAYBOUND is obsolete, exists for backwards compatibility.
26
-// Use SafeArrayBound
27
-type SAFEARRAYBOUND SafeArrayBound
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_func.go
deleted
-207
@@ -1,207 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-// safeArrayAccessData returns raw array pointer.
6
-//
7
-// AKA: SafeArrayAccessData in Windows API.
8
-func safeArrayAccessData(safearray *SafeArray) (uintptr, error) {
9
- return uintptr(0), NewError(E_NOTIMPL)
10
-}
11
-
12
-// safeArrayUnaccessData releases raw array.
13
-//
14
-// AKA: SafeArrayUnaccessData in Windows API.
15
-func safeArrayUnaccessData(safearray *SafeArray) error {
16
- return NewError(E_NOTIMPL)
17
-}
18
-
19
-// safeArrayAllocData allocates SafeArray.
20
-//
21
-// AKA: SafeArrayAllocData in Windows API.
22
-func safeArrayAllocData(safearray *SafeArray) error {
23
- return NewError(E_NOTIMPL)
24
-}
25
-
26
-// safeArrayAllocDescriptor allocates SafeArray.
27
-//
28
-// AKA: SafeArrayAllocDescriptor in Windows API.
29
-func safeArrayAllocDescriptor(dimensions uint32) (*SafeArray, error) {
30
- return nil, NewError(E_NOTIMPL)
31
-}
32
-
33
-// safeArrayAllocDescriptorEx allocates SafeArray.
34
-//
35
-// AKA: SafeArrayAllocDescriptorEx in Windows API.
36
-func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (*SafeArray, error) {
37
- return nil, NewError(E_NOTIMPL)
38
-}
39
-
40
-// safeArrayCopy returns copy of SafeArray.
41
-//
42
-// AKA: SafeArrayCopy in Windows API.
43
-func safeArrayCopy(original *SafeArray) (*SafeArray, error) {
44
- return nil, NewError(E_NOTIMPL)
45
-}
46
-
47
-// safeArrayCopyData duplicates SafeArray into another SafeArray object.
48
-//
49
-// AKA: SafeArrayCopyData in Windows API.
50
-func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) error {
51
- return NewError(E_NOTIMPL)
52
-}
53
-
54
-// safeArrayCreate creates SafeArray.
55
-//
56
-// AKA: SafeArrayCreate in Windows API.
57
-func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (*SafeArray, error) {
58
- return nil, NewError(E_NOTIMPL)
59
-}
60
-
61
-// safeArrayCreateEx creates SafeArray.
62
-//
63
-// AKA: SafeArrayCreateEx in Windows API.
64
-func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (*SafeArray, error) {
65
- return nil, NewError(E_NOTIMPL)
66
-}
67
-
68
-// safeArrayCreateVector creates SafeArray.
69
-//
70
-// AKA: SafeArrayCreateVector in Windows API.
71
-func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (*SafeArray, error) {
72
- return nil, NewError(E_NOTIMPL)
73
-}
74
-
75
-// safeArrayCreateVectorEx creates SafeArray.
76
-//
77
-// AKA: SafeArrayCreateVectorEx in Windows API.
78
-func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (*SafeArray, error) {
79
- return nil, NewError(E_NOTIMPL)
80
-}
81
-
82
-// safeArrayDestroy destroys SafeArray object.
83
-//
84
-// AKA: SafeArrayDestroy in Windows API.
85
-func safeArrayDestroy(safearray *SafeArray) error {
86
- return NewError(E_NOTIMPL)
87
-}
88
-
89
-// safeArrayDestroyData destroys SafeArray object.
90
-//
91
-// AKA: SafeArrayDestroyData in Windows API.
92
-func safeArrayDestroyData(safearray *SafeArray) error {
93
- return NewError(E_NOTIMPL)
94
-}
95
-
96
-// safeArrayDestroyDescriptor destroys SafeArray object.
97
-//
98
-// AKA: SafeArrayDestroyDescriptor in Windows API.
99
-func safeArrayDestroyDescriptor(safearray *SafeArray) error {
100
- return NewError(E_NOTIMPL)
101
-}
102
-
103
-// safeArrayGetDim is the amount of dimensions in the SafeArray.
104
-//
105
-// SafeArrays may have multiple dimensions. Meaning, it could be
106
-// multidimensional array.
107
-//
108
-// AKA: SafeArrayGetDim in Windows API.
109
-func safeArrayGetDim(safearray *SafeArray) (*uint32, error) {
110
- u := uint32(0)
111
- return &u, NewError(E_NOTIMPL)
112
-}
113
-
114
-// safeArrayGetElementSize is the element size in bytes.
115
-//
116
-// AKA: SafeArrayGetElemsize in Windows API.
117
-func safeArrayGetElementSize(safearray *SafeArray) (*uint32, error) {
118
- u := uint32(0)
119
- return &u, NewError(E_NOTIMPL)
120
-}
121
-
122
-// safeArrayGetElement retrieves element at given index.
123
-func safeArrayGetElement(safearray *SafeArray, index int64) (uintptr, error) {
124
- return uintptr(0), NewError(E_NOTIMPL)
125
-}
126
-
127
-// safeArrayGetElement retrieves element at given index and converts to string.
128
-func safeArrayGetElementString(safearray *SafeArray, index int64) (string, error) {
129
- return "", NewError(E_NOTIMPL)
130
-}
131
-
132
-// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
133
-//
134
-// AKA: SafeArrayGetIID in Windows API.
135
-func safeArrayGetIID(safearray *SafeArray) (*GUID, error) {
136
- return nil, NewError(E_NOTIMPL)
137
-}
138
-
139
-// safeArrayGetLBound returns lower bounds of SafeArray.
140
-//
141
-// SafeArrays may have multiple dimensions. Meaning, it could be
142
-// multidimensional array.
143
-//
144
-// AKA: SafeArrayGetLBound in Windows API.
145
-func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (int64, error) {
146
- return int64(0), NewError(E_NOTIMPL)
147
-}
148
-
149
-// safeArrayGetUBound returns upper bounds of SafeArray.
150
-//
151
-// SafeArrays may have multiple dimensions. Meaning, it could be
152
-// multidimensional array.
153
-//
154
-// AKA: SafeArrayGetUBound in Windows API.
155
-func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (int64, error) {
156
- return int64(0), NewError(E_NOTIMPL)
157
-}
158
-
159
-// safeArrayGetVartype returns data type of SafeArray.
160
-//
161
-// AKA: SafeArrayGetVartype in Windows API.
162
-func safeArrayGetVartype(safearray *SafeArray) (uint16, error) {
163
- return uint16(0), NewError(E_NOTIMPL)
164
-}
165
-
166
-// safeArrayLock locks SafeArray for reading to modify SafeArray.
167
-//
168
-// This must be called during some calls to ensure that another process does not
169
-// read or write to the SafeArray during editing.
170
-//
171
-// AKA: SafeArrayLock in Windows API.
172
-func safeArrayLock(safearray *SafeArray) error {
173
- return NewError(E_NOTIMPL)
174
-}
175
-
176
-// safeArrayUnlock unlocks SafeArray for reading.
177
-//
178
-// AKA: SafeArrayUnlock in Windows API.
179
-func safeArrayUnlock(safearray *SafeArray) error {
180
- return NewError(E_NOTIMPL)
181
-}
182
-
183
-// safeArrayPutElement stores the data element at the specified location in the
184
-// array.
185
-//
186
-// AKA: SafeArrayPutElement in Windows API.
187
-func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) error {
188
- return NewError(E_NOTIMPL)
189
-}
190
-
191
-// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
192
-//
193
-// AKA: SafeArrayGetRecordInfo in Windows API.
194
-//
195
-// XXX: Must implement IRecordInfo interface for this to return.
196
-func safeArrayGetRecordInfo(safearray *SafeArray) (interface{}, error) {
197
- return nil, NewError(E_NOTIMPL)
198
-}
199
-
200
-// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
201
-//
202
-// AKA: SafeArraySetRecordInfo in Windows API.
203
-//
204
-// XXX: Must implement IRecordInfo interface for this to return.
205
-func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) error {
206
- return NewError(E_NOTIMPL)
207
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_test.go
deleted
-108
@@ -1,108 +0,0 @@
1
-package ole
2
-
3
-// This tests more than one function. It tests all of the functions needed in
4
-// order to retrieve an SafeArray populated with Strings.
5
-func Example_safeArrayGetElementString() {
6
- CoInitialize(0)
7
- defer CoUninitialize()
8
-
9
- clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1")
10
- if err != nil {
11
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
12
- return
13
- }
14
- }
15
-
16
- unknown, err := CreateInstance(clsid, IID_IUnknown)
17
- if err != nil {
18
- return
19
- }
20
- defer unknown.Release()
21
-
22
- dispatch, err := unknown.QueryInterface(IID_IDispatch)
23
- if err != nil {
24
- return
25
- }
26
-
27
- var dispid []int32
28
- dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"})
29
- if err != nil {
30
- return
31
- }
32
-
33
- var result *VARIANT
34
- _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1)
35
- if err != nil {
36
- return
37
- }
38
-
39
- dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"})
40
- if err != nil {
41
- return
42
- }
43
-
44
- result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2)
45
- if err != nil {
46
- return
47
- }
48
-
49
- ticket := result.ToString()
50
-
51
- dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"})
52
- if err != nil {
53
- return
54
- }
55
-
56
- result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket)
57
- if err != nil {
58
- return
59
- }
60
-
61
- // Where the real tests begin.
62
- var qbXMLVersions *SafeArray
63
- var qbXmlVersionStrings []string
64
- qbXMLVersions = result.ToArray().Array
65
-
66
- // Get array bounds
67
- var LowerBounds int64
68
- var UpperBounds int64
69
- LowerBounds, err = safeArrayGetLBound(qbXMLVersions, 1)
70
- if err != nil {
71
- return
72
- }
73
-
74
- UpperBounds, err = safeArrayGetUBound(qbXMLVersions, 1)
75
- if err != nil {
76
- return
77
- }
78
-
79
- totalElements := UpperBounds - LowerBounds + 1
80
- qbXmlVersionStrings = make([]string, totalElements)
81
-
82
- for i := int64(0); i < totalElements; i++ {
83
- qbXmlVersionStrings[int32(i)], _ = safeArrayGetElementString(qbXMLVersions, i)
84
- }
85
-
86
- // Release Safe Array memory
87
- safeArrayDestroy(qbXMLVersions)
88
-
89
- dispid, err = dispatch.GetIDsOfName([]string{"EndSession"})
90
- if err != nil {
91
- return
92
- }
93
-
94
- _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket)
95
- if err != nil {
96
- return
97
- }
98
-
99
- dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"})
100
- if err != nil {
101
- return
102
- }
103
-
104
- _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD)
105
- if err != nil {
106
- return
107
- }
108
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_windows.go
deleted
-338
@@ -1,338 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "unsafe"
7
-)
8
-
9
-var (
10
- procSafeArrayAccessData, _ = modoleaut32.FindProc("SafeArrayAccessData")
11
- procSafeArrayAllocData, _ = modoleaut32.FindProc("SafeArrayAllocData")
12
- procSafeArrayAllocDescriptor, _ = modoleaut32.FindProc("SafeArrayAllocDescriptor")
13
- procSafeArrayAllocDescriptorEx, _ = modoleaut32.FindProc("SafeArrayAllocDescriptorEx")
14
- procSafeArrayCopy, _ = modoleaut32.FindProc("SafeArrayCopy")
15
- procSafeArrayCopyData, _ = modoleaut32.FindProc("SafeArrayCopyData")
16
- procSafeArrayCreate, _ = modoleaut32.FindProc("SafeArrayCreate")
17
- procSafeArrayCreateEx, _ = modoleaut32.FindProc("SafeArrayCreateEx")
18
- procSafeArrayCreateVector, _ = modoleaut32.FindProc("SafeArrayCreateVector")
19
- procSafeArrayCreateVectorEx, _ = modoleaut32.FindProc("SafeArrayCreateVectorEx")
20
- procSafeArrayDestroy, _ = modoleaut32.FindProc("SafeArrayDestroy")
21
- procSafeArrayDestroyData, _ = modoleaut32.FindProc("SafeArrayDestroyData")
22
- procSafeArrayDestroyDescriptor, _ = modoleaut32.FindProc("SafeArrayDestroyDescriptor")
23
- procSafeArrayGetDim, _ = modoleaut32.FindProc("SafeArrayGetDim")
24
- procSafeArrayGetElement, _ = modoleaut32.FindProc("SafeArrayGetElement")
25
- procSafeArrayGetElemsize, _ = modoleaut32.FindProc("SafeArrayGetElemsize")
26
- procSafeArrayGetIID, _ = modoleaut32.FindProc("SafeArrayGetIID")
27
- procSafeArrayGetLBound, _ = modoleaut32.FindProc("SafeArrayGetLBound")
28
- procSafeArrayGetUBound, _ = modoleaut32.FindProc("SafeArrayGetUBound")
29
- procSafeArrayGetVartype, _ = modoleaut32.FindProc("SafeArrayGetVartype")
30
- procSafeArrayLock, _ = modoleaut32.FindProc("SafeArrayLock")
31
- procSafeArrayPtrOfIndex, _ = modoleaut32.FindProc("SafeArrayPtrOfIndex")
32
- procSafeArrayUnaccessData, _ = modoleaut32.FindProc("SafeArrayUnaccessData")
33
- procSafeArrayUnlock, _ = modoleaut32.FindProc("SafeArrayUnlock")
34
- procSafeArrayPutElement, _ = modoleaut32.FindProc("SafeArrayPutElement")
35
- //procSafeArrayRedim, _ = modoleaut32.FindProc("SafeArrayRedim") // TODO
36
- //procSafeArraySetIID, _ = modoleaut32.FindProc("SafeArraySetIID") // TODO
37
- procSafeArrayGetRecordInfo, _ = modoleaut32.FindProc("SafeArrayGetRecordInfo")
38
- procSafeArraySetRecordInfo, _ = modoleaut32.FindProc("SafeArraySetRecordInfo")
39
-)
40
-
41
-// safeArrayAccessData returns raw array pointer.
42
-//
43
-// AKA: SafeArrayAccessData in Windows API.
44
-// Todo: Test
45
-func safeArrayAccessData(safearray *SafeArray) (element uintptr, err error) {
46
- err = convertHresultToError(
47
- procSafeArrayAccessData.Call(
48
- uintptr(unsafe.Pointer(safearray)),
49
- uintptr(unsafe.Pointer(&element))))
50
- return
51
-}
52
-
53
-// safeArrayUnaccessData releases raw array.
54
-//
55
-// AKA: SafeArrayUnaccessData in Windows API.
56
-func safeArrayUnaccessData(safearray *SafeArray) (err error) {
57
- err = convertHresultToError(procSafeArrayUnaccessData.Call(uintptr(unsafe.Pointer(safearray))))
58
- return
59
-}
60
-
61
-// safeArrayAllocData allocates SafeArray.
62
-//
63
-// AKA: SafeArrayAllocData in Windows API.
64
-func safeArrayAllocData(safearray *SafeArray) (err error) {
65
- err = convertHresultToError(procSafeArrayAllocData.Call(uintptr(unsafe.Pointer(safearray))))
66
- return
67
-}
68
-
69
-// safeArrayAllocDescriptor allocates SafeArray.
70
-//
71
-// AKA: SafeArrayAllocDescriptor in Windows API.
72
-func safeArrayAllocDescriptor(dimensions uint32) (safearray *SafeArray, err error) {
73
- err = convertHresultToError(
74
- procSafeArrayAllocDescriptor.Call(uintptr(dimensions), uintptr(unsafe.Pointer(&safearray))))
75
- return
76
-}
77
-
78
-// safeArrayAllocDescriptorEx allocates SafeArray.
79
-//
80
-// AKA: SafeArrayAllocDescriptorEx in Windows API.
81
-func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (safearray *SafeArray, err error) {
82
- err = convertHresultToError(
83
- procSafeArrayAllocDescriptorEx.Call(
84
- uintptr(variantType),
85
- uintptr(dimensions),
86
- uintptr(unsafe.Pointer(&safearray))))
87
- return
88
-}
89
-
90
-// safeArrayCopy returns copy of SafeArray.
91
-//
92
-// AKA: SafeArrayCopy in Windows API.
93
-func safeArrayCopy(original *SafeArray) (safearray *SafeArray, err error) {
94
- err = convertHresultToError(
95
- procSafeArrayCopy.Call(
96
- uintptr(unsafe.Pointer(original)),
97
- uintptr(unsafe.Pointer(&safearray))))
98
- return
99
-}
100
-
101
-// safeArrayCopyData duplicates SafeArray into another SafeArray object.
102
-//
103
-// AKA: SafeArrayCopyData in Windows API.
104
-func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) (err error) {
105
- err = convertHresultToError(
106
- procSafeArrayCopyData.Call(
107
- uintptr(unsafe.Pointer(original)),
108
- uintptr(unsafe.Pointer(duplicate))))
109
- return
110
-}
111
-
112
-// safeArrayCreate creates SafeArray.
113
-//
114
-// AKA: SafeArrayCreate in Windows API.
115
-func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (safearray *SafeArray, err error) {
116
- sa, _, err := procSafeArrayCreate.Call(
117
- uintptr(variantType),
118
- uintptr(dimensions),
119
- uintptr(unsafe.Pointer(bounds)))
120
- safearray = (*SafeArray)(unsafe.Pointer(&sa))
121
- return
122
-}
123
-
124
-// safeArrayCreateEx creates SafeArray.
125
-//
126
-// AKA: SafeArrayCreateEx in Windows API.
127
-func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (safearray *SafeArray, err error) {
128
- sa, _, err := procSafeArrayCreateEx.Call(
129
- uintptr(variantType),
130
- uintptr(dimensions),
131
- uintptr(unsafe.Pointer(bounds)),
132
- extra)
133
- safearray = (*SafeArray)(unsafe.Pointer(sa))
134
- return
135
-}
136
-
137
-// safeArrayCreateVector creates SafeArray.
138
-//
139
-// AKA: SafeArrayCreateVector in Windows API.
140
-func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (safearray *SafeArray, err error) {
141
- sa, _, err := procSafeArrayCreateVector.Call(
142
- uintptr(variantType),
143
- uintptr(lowerBound),
144
- uintptr(length))
145
- safearray = (*SafeArray)(unsafe.Pointer(sa))
146
- return
147
-}
148
-
149
-// safeArrayCreateVectorEx creates SafeArray.
150
-//
151
-// AKA: SafeArrayCreateVectorEx in Windows API.
152
-func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (safearray *SafeArray, err error) {
153
- sa, _, err := procSafeArrayCreateVectorEx.Call(
154
- uintptr(variantType),
155
- uintptr(lowerBound),
156
- uintptr(length),
157
- extra)
158
- safearray = (*SafeArray)(unsafe.Pointer(sa))
159
- return
160
-}
161
-
162
-// safeArrayDestroy destroys SafeArray object.
163
-//
164
-// AKA: SafeArrayDestroy in Windows API.
165
-func safeArrayDestroy(safearray *SafeArray) (err error) {
166
- err = convertHresultToError(procSafeArrayDestroy.Call(uintptr(unsafe.Pointer(safearray))))
167
- return
168
-}
169
-
170
-// safeArrayDestroyData destroys SafeArray object.
171
-//
172
-// AKA: SafeArrayDestroyData in Windows API.
173
-func safeArrayDestroyData(safearray *SafeArray) (err error) {
174
- err = convertHresultToError(procSafeArrayDestroyData.Call(uintptr(unsafe.Pointer(safearray))))
175
- return
176
-}
177
-
178
-// safeArrayDestroyDescriptor destroys SafeArray object.
179
-//
180
-// AKA: SafeArrayDestroyDescriptor in Windows API.
181
-func safeArrayDestroyDescriptor(safearray *SafeArray) (err error) {
182
- err = convertHresultToError(procSafeArrayDestroyDescriptor.Call(uintptr(unsafe.Pointer(safearray))))
183
- return
184
-}
185
-
186
-// safeArrayGetDim is the amount of dimensions in the SafeArray.
187
-//
188
-// SafeArrays may have multiple dimensions. Meaning, it could be
189
-// multidimensional array.
190
-//
191
-// AKA: SafeArrayGetDim in Windows API.
192
-func safeArrayGetDim(safearray *SafeArray) (dimensions *uint32, err error) {
193
- l, _, err := procSafeArrayGetDim.Call(uintptr(unsafe.Pointer(safearray)))
194
- dimensions = (*uint32)(unsafe.Pointer(l))
195
- return
196
-}
197
-
198
-// safeArrayGetElementSize is the element size in bytes.
199
-//
200
-// AKA: SafeArrayGetElemsize in Windows API.
201
-func safeArrayGetElementSize(safearray *SafeArray) (length *uint32, err error) {
202
- l, _, err := procSafeArrayGetElemsize.Call(uintptr(unsafe.Pointer(safearray)))
203
- length = (*uint32)(unsafe.Pointer(l))
204
- return
205
-}
206
-
207
-// safeArrayGetElement retrieves element at given index.
208
-func safeArrayGetElement(safearray *SafeArray, index int64) (element uintptr, err error) {
209
- err = convertHresultToError(
210
- procSafeArrayGetElement.Call(
211
- uintptr(unsafe.Pointer(safearray)),
212
- uintptr(unsafe.Pointer(&index)),
213
- uintptr(unsafe.Pointer(&element))))
214
- return
215
-}
216
-
217
-// safeArrayGetElement retrieves element at given index and converts to string.
218
-func safeArrayGetElementString(safearray *SafeArray, index int64) (str string, err error) {
219
- var element *int16
220
- err = convertHresultToError(
221
- procSafeArrayGetElement.Call(
222
- uintptr(unsafe.Pointer(safearray)),
223
- uintptr(unsafe.Pointer(&index)),
224
- uintptr(unsafe.Pointer(&element))))
225
- str = BstrToString(*(**uint16)(unsafe.Pointer(&element)))
226
- SysFreeString(element)
227
- return
228
-}
229
-
230
-// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
231
-//
232
-// AKA: SafeArrayGetIID in Windows API.
233
-func safeArrayGetIID(safearray *SafeArray) (guid *GUID, err error) {
234
- err = convertHresultToError(
235
- procSafeArrayGetIID.Call(
236
- uintptr(unsafe.Pointer(safearray)),
237
- uintptr(unsafe.Pointer(&guid))))
238
- return
239
-}
240
-
241
-// safeArrayGetLBound returns lower bounds of SafeArray.
242
-//
243
-// SafeArrays may have multiple dimensions. Meaning, it could be
244
-// multidimensional array.
245
-//
246
-// AKA: SafeArrayGetLBound in Windows API.
247
-func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (lowerBound int64, err error) {
248
- err = convertHresultToError(
249
- procSafeArrayGetLBound.Call(
250
- uintptr(unsafe.Pointer(safearray)),
251
- uintptr(dimension),
252
- uintptr(unsafe.Pointer(&lowerBound))))
253
- return
254
-}
255
-
256
-// safeArrayGetUBound returns upper bounds of SafeArray.
257
-//
258
-// SafeArrays may have multiple dimensions. Meaning, it could be
259
-// multidimensional array.
260
-//
261
-// AKA: SafeArrayGetUBound in Windows API.
262
-func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (upperBound int64, err error) {
263
- err = convertHresultToError(
264
- procSafeArrayGetUBound.Call(
265
- uintptr(unsafe.Pointer(safearray)),
266
- uintptr(dimension),
267
- uintptr(unsafe.Pointer(&upperBound))))
268
- return
269
-}
270
-
271
-// safeArrayGetVartype returns data type of SafeArray.
272
-//
273
-// AKA: SafeArrayGetVartype in Windows API.
274
-func safeArrayGetVartype(safearray *SafeArray) (varType uint16, err error) {
275
- err = convertHresultToError(
276
- procSafeArrayGetVartype.Call(
277
- uintptr(unsafe.Pointer(safearray)),
278
- uintptr(unsafe.Pointer(&varType))))
279
- return
280
-}
281
-
282
-// safeArrayLock locks SafeArray for reading to modify SafeArray.
283
-//
284
-// This must be called during some calls to ensure that another process does not
285
-// read or write to the SafeArray during editing.
286
-//
287
-// AKA: SafeArrayLock in Windows API.
288
-func safeArrayLock(safearray *SafeArray) (err error) {
289
- err = convertHresultToError(procSafeArrayLock.Call(uintptr(unsafe.Pointer(safearray))))
290
- return
291
-}
292
-
293
-// safeArrayUnlock unlocks SafeArray for reading.
294
-//
295
-// AKA: SafeArrayUnlock in Windows API.
296
-func safeArrayUnlock(safearray *SafeArray) (err error) {
297
- err = convertHresultToError(procSafeArrayUnlock.Call(uintptr(unsafe.Pointer(safearray))))
298
- return
299
-}
300
-
301
-// safeArrayPutElement stores the data element at the specified location in the
302
-// array.
303
-//
304
-// AKA: SafeArrayPutElement in Windows API.
305
-func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) (err error) {
306
- err = convertHresultToError(
307
- procSafeArrayPutElement.Call(
308
- uintptr(unsafe.Pointer(safearray)),
309
- uintptr(unsafe.Pointer(&index)),
310
- uintptr(unsafe.Pointer(element))))
311
- return
312
-}
313
-
314
-// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
315
-//
316
-// AKA: SafeArrayGetRecordInfo in Windows API.
317
-//
318
-// XXX: Must implement IRecordInfo interface for this to return.
319
-func safeArrayGetRecordInfo(safearray *SafeArray) (recordInfo interface{}, err error) {
320
- err = convertHresultToError(
321
- procSafeArrayGetRecordInfo.Call(
322
- uintptr(unsafe.Pointer(safearray)),
323
- uintptr(unsafe.Pointer(&recordInfo))))
324
- return
325
-}
326
-
327
-// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
328
-//
329
-// AKA: SafeArraySetRecordInfo in Windows API.
330
-//
331
-// XXX: Must implement IRecordInfo interface for this to return.
332
-func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) (err error) {
333
- err = convertHresultToError(
334
- procSafeArraySetRecordInfo.Call(
335
- uintptr(unsafe.Pointer(safearray)),
336
- uintptr(unsafe.Pointer(&recordInfo))))
337
- return
338
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion.go
deleted
-72
@@ -1,72 +0,0 @@
1
-// Helper for converting SafeArray to array of objects.
2
-
3
-package ole
4
-
5
-import "unsafe"
6
-
7
-type SafeArrayConversion struct {
8
- Array *SafeArray
9
-}
10
-
11
-func (sac *SafeArrayConversion) ToStringArray() (strings []string) {
12
- totalElements, _ := sac.TotalElements(0)
13
- strings = make([]string, totalElements)
14
-
15
- for i := int64(0); i < totalElements; i++ {
16
- strings[int32(i)], _ = safeArrayGetElementString(sac.Array, i)
17
- }
18
-
19
- return
20
-}
21
-
22
-func (sac *SafeArrayConversion) ToByteArray() (bytes []byte) {
23
- totalElements, _ := sac.TotalElements(0)
24
- bytes = make([]byte, totalElements)
25
-
26
- for i := int64(0); i < totalElements; i++ {
27
- ptr, _ := safeArrayGetElement(sac.Array, i)
28
- bytes[int32(i)] = *(*byte)(unsafe.Pointer(&ptr))
29
- }
30
-
31
- return
32
-}
33
-
34
-func (sac *SafeArrayConversion) GetType() (varType uint16, err error) {
35
- return safeArrayGetVartype(sac.Array)
36
-}
37
-
38
-func (sac *SafeArrayConversion) GetDimensions() (dimensions *uint32, err error) {
39
- return safeArrayGetDim(sac.Array)
40
-}
41
-
42
-func (sac *SafeArrayConversion) GetSize() (length *uint32, err error) {
43
- return safeArrayGetElementSize(sac.Array)
44
-}
45
-
46
-func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int64, err error) {
47
- if index < 1 {
48
- index = 1
49
- }
50
-
51
- // Get array bounds
52
- var LowerBounds int64
53
- var UpperBounds int64
54
-
55
- LowerBounds, err = safeArrayGetLBound(sac.Array, index)
56
- if err != nil {
57
- return
58
- }
59
-
60
- UpperBounds, err = safeArrayGetUBound(sac.Array, index)
61
- if err != nil {
62
- return
63
- }
64
-
65
- totalElements = UpperBounds - LowerBounds + 1
66
- return
67
-}
68
-
69
-// Release Safe Array memory
70
-func (sac *SafeArrayConversion) Release() {
71
- safeArrayDestroy(sac.Array)
72
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion_test.go
deleted
-119
@@ -1,119 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "fmt"
7
- "strings"
8
- "testing"
9
-)
10
-
11
-// This tests more than one function. It tests all of the functions needed in order to retrieve an
12
-// SafeArray populated with Strings.
13
-func TestSafeArrayConversionString(t *testing.T) {
14
- CoInitialize(0)
15
- defer CoUninitialize()
16
-
17
- clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1")
18
- if err != nil {
19
- if err.(*OleError).Code() == CO_E_CLASSSTRING {
20
- return
21
- }
22
- t.Log(err)
23
- t.FailNow()
24
- }
25
-
26
- unknown, err := CreateInstance(clsid, IID_IUnknown)
27
- if err != nil {
28
- t.Log(err)
29
- t.FailNow()
30
- }
31
- defer unknown.Release()
32
-
33
- dispatch, err := unknown.QueryInterface(IID_IDispatch)
34
- if err != nil {
35
- t.Log(err)
36
- t.FailNow()
37
- }
38
-
39
- var dispid []int32
40
- dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"})
41
- if err != nil {
42
- t.Log(err)
43
- t.FailNow()
44
- }
45
-
46
- var result *VARIANT
47
- _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1)
48
- if err != nil {
49
- t.Log(err)
50
- t.FailNow()
51
- }
52
-
53
- dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"})
54
- if err != nil {
55
- t.Log(err)
56
- t.FailNow()
57
- }
58
-
59
- result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2)
60
- if err != nil {
61
- t.Log(err)
62
- t.FailNow()
63
- }
64
-
65
- ticket := result.ToString()
66
-
67
- dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"})
68
- if err != nil {
69
- t.Log(err)
70
- t.FailNow()
71
- }
72
-
73
- result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket)
74
- if err != nil {
75
- t.Log(err)
76
- t.FailNow()
77
- }
78
-
79
- // Where the real tests begin.
80
- conversion := result.ToArray()
81
-
82
- totalElements, _ := conversion.TotalElements(0)
83
- if totalElements != 13 {
84
- t.Log(fmt.Sprintf("%d total elements does not equal 13\n", totalElements))
85
- t.Fail()
86
- }
87
-
88
- versions := conversion.ToStringArray()
89
- if len(versions) != 13 {
90
- t.Log(fmt.Sprintf("%s\n", strings.Join(versions, ", ")))
91
- t.Fail()
92
- }
93
-
94
- conversion.Release()
95
-
96
- dispid, err = dispatch.GetIDsOfName([]string{"EndSession"})
97
- if err != nil {
98
- t.Log(err)
99
- t.FailNow()
100
- }
101
-
102
- _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket)
103
- if err != nil {
104
- t.Log(err)
105
- t.FailNow()
106
- }
107
-
108
- dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"})
109
- if err != nil {
110
- t.Log(err)
111
- t.FailNow()
112
- }
113
-
114
- _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD)
115
- if err != nil {
116
- t.Log(err)
117
- t.FailNow()
118
- }
119
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayslices.go
deleted
-33
@@ -1,33 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "unsafe"
7
-)
8
-
9
-func safeArrayFromByteSlice(slice []byte) *SafeArray {
10
- array, _ := safeArrayCreateVector(VT_UI1, 0, uint32(len(slice)))
11
-
12
- if array == nil {
13
- panic("Could not convert []byte to SAFEARRAY")
14
- }
15
-
16
- for i, v := range slice {
17
- safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(&v)))
18
- }
19
- return array
20
-}
21
-
22
-func safeArrayFromStringSlice(slice []string) *SafeArray {
23
- array, _ := safeArrayCreateVector(VT_BSTR, 0, uint32(len(slice)))
24
-
25
- if array == nil {
26
- panic("Could not convert []string to SAFEARRAY")
27
- }
28
- // SysAllocStringLen(s)
29
- for i, v := range slice {
30
- safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(SysAllocStringLen(v))))
31
- }
32
- return array
33
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/utility.go
deleted
-85
@@ -1,85 +0,0 @@
1
-package ole
2
-
3
-import (
4
- "unicode/utf16"
5
- "unsafe"
6
-)
7
-
8
-// BytePtrToString converts byte pointer to a Go string.
9
-func BytePtrToString(p *byte) string {
10
- a := (*[10000]uint8)(unsafe.Pointer(p))
11
- i := 0
12
- for a[i] != 0 {
13
- i++
14
- }
15
- return string(a[:i])
16
-}
17
-
18
-// UTF16PtrToString is alias for LpOleStrToString.
19
-//
20
-// Kept for compatibility reasons.
21
-func UTF16PtrToString(p *uint16) string {
22
- return LpOleStrToString(p)
23
-}
24
-
25
-// LpOleStrToString converts COM Unicode to Go string.
26
-func LpOleStrToString(p *uint16) string {
27
- if p == nil {
28
- return ""
29
- }
30
-
31
- length := lpOleStrLen(p)
32
- a := make([]uint16, length)
33
-
34
- ptr := unsafe.Pointer(p)
35
-
36
- for i := 0; i < int(length); i++ {
37
- a[i] = *(*uint16)(ptr)
38
- ptr = unsafe.Pointer(uintptr(ptr) + 2)
39
- }
40
-
41
- return string(utf16.Decode(a))
42
-}
43
-
44
-// BstrToString converts COM binary string to Go string.
45
-func BstrToString(p *uint16) string {
46
- if p == nil {
47
- return ""
48
- }
49
- length := SysStringLen((*int16)(unsafe.Pointer(p)))
50
- a := make([]uint16, length)
51
-
52
- ptr := unsafe.Pointer(p)
53
-
54
- for i := 0; i < int(length); i++ {
55
- a[i] = *(*uint16)(ptr)
56
- ptr = unsafe.Pointer(uintptr(ptr) + 2)
57
- }
58
- return string(utf16.Decode(a))
59
-}
60
-
61
-// lpOleStrLen returns the length of Unicode string.
62
-func lpOleStrLen(p *uint16) (length int64) {
63
- if p == nil {
64
- return 0
65
- }
66
-
67
- ptr := unsafe.Pointer(p)
68
-
69
- for i := 0; ; i++ {
70
- if 0 == *(*uint16)(ptr) {
71
- length = int64(i)
72
- break
73
- }
74
- ptr = unsafe.Pointer(uintptr(ptr) + 2)
75
- }
76
- return
77
-}
78
-
79
-// convertHresultToError converts syscall to error, if call is unsuccessful.
80
-func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
81
- if hr != 0 {
82
- err = NewError(hr)
83
- }
84
- return
85
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/variables.go
deleted
-16
@@ -1,16 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "syscall"
7
-)
8
-
9
-var (
10
- modcombase = syscall.NewLazyDLL("combase.dll")
11
- modkernel32, _ = syscall.LoadDLL("kernel32.dll")
12
- modole32, _ = syscall.LoadDLL("ole32.dll")
13
- modoleaut32, _ = syscall.LoadDLL("oleaut32.dll")
14
- modmsvcrt, _ = syscall.LoadDLL("msvcrt.dll")
15
- moduser32, _ = syscall.LoadDLL("user32.dll")
16
-)
Godeps/_workspace/src/github.com/go-ole/go-ole/variant.go
deleted
-101
@@ -1,101 +0,0 @@
1
-package ole
2
-
3
-import "unsafe"
4
-
5
-// NewVariant returns new variant based on type and value.
6
-func NewVariant(vt VT, val int64) VARIANT {
7
- return VARIANT{VT: vt, Val: val}
8
-}
9
-
10
-// ToIUnknown converts Variant to Unknown object.
11
-func (v *VARIANT) ToIUnknown() *IUnknown {
12
- if v.VT != VT_UNKNOWN {
13
- return nil
14
- }
15
- return (*IUnknown)(unsafe.Pointer(uintptr(v.Val)))
16
-}
17
-
18
-// ToIDispatch converts variant to dispatch object.
19
-func (v *VARIANT) ToIDispatch() *IDispatch {
20
- if v.VT != VT_DISPATCH {
21
- return nil
22
- }
23
- return (*IDispatch)(unsafe.Pointer(uintptr(v.Val)))
24
-}
25
-
26
-// ToArray converts variant to SafeArray helper.
27
-func (v *VARIANT) ToArray() *SafeArrayConversion {
28
- if v.VT != VT_SAFEARRAY {
29
- return nil
30
- }
31
- var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val)))
32
- return &SafeArrayConversion{safeArray}
33
-}
34
-
35
-// ToString converts variant to Go string.
36
-func (v *VARIANT) ToString() string {
37
- if v.VT != VT_BSTR {
38
- return ""
39
- }
40
- return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val)))
41
-}
42
-
43
-// Clear the memory of variant object.
44
-func (v *VARIANT) Clear() error {
45
- return VariantClear(v)
46
-}
47
-
48
-// Value returns variant value based on its type.
49
-//
50
-// Currently supported types: 2- and 4-byte integers, strings, bools.
51
-// Note that 64-bit integers, datetimes, and other types are stored as strings
52
-// and will be returned as strings.
53
-//
54
-// Needs to be further converted, because this returns an interface{}.
55
-func (v *VARIANT) Value() interface{} {
56
- switch v.VT {
57
- case VT_I1:
58
- return int8(v.Val)
59
- case VT_UI1:
60
- return uint8(v.Val)
61
- case VT_I2:
62
- return int16(v.Val)
63
- case VT_UI2:
64
- return uint16(v.Val)
65
- case VT_I4:
66
- return int32(v.Val)
67
- case VT_UINT:
68
- return uint32(v.Val)
69
- case VT_INT_PTR:
70
- return uintptr(v.Val) // TODO
71
- case VT_UINT_PTR:
72
- return uintptr(v.Val)
73
- case VT_UI4:
74
- return uint32(v.Val)
75
- case VT_I8:
76
- return int64(v.Val)
77
- case VT_UI8:
78
- return uint64(v.Val)
79
- case VT_R4:
80
- return float32(v.Val)
81
- case VT_R8:
82
- return float64(v.Val)
83
- case VT_BSTR:
84
- return v.ToString()
85
- case VT_DATE:
86
- // VT_DATE type will either return float64 or time.Time.
87
- d := float64(v.Val)
88
- date, err := GetVariantDate(d)
89
- if err != nil {
90
- return d
91
- }
92
- return date
93
- case VT_UNKNOWN:
94
- return v.ToIUnknown()
95
- case VT_DISPATCH:
96
- return v.ToIDispatch()
97
- case VT_BOOL:
98
- return v.Val != 0
99
- }
100
- return nil
101
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/variant_386.go
deleted
-11
@@ -1,11 +0,0 @@
1
-// +build 386
2
-
3
-package ole
4
-
5
-type VARIANT struct {
6
- VT VT // 2
7
- wReserved1 uint16 // 4
8
- wReserved2 uint16 // 6
9
- wReserved3 uint16 // 8
10
- Val int64 // 16
11
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/variant_amd64.go
deleted
-12
@@ -1,12 +0,0 @@
1
-// +build amd64
2
-
3
-package ole
4
-
5
-type VARIANT struct {
6
- VT VT // 2
7
- wReserved1 uint16 // 4
8
- wReserved2 uint16 // 6
9
- wReserved3 uint16 // 8
10
- Val int64 // 16
11
- _ [8]byte // 24
12
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/vt_string.go
deleted
-58
@@ -1,58 +0,0 @@
1
-// generated by stringer -output vt_string.go -type VT; DO NOT EDIT
2
-
3
-package ole
4
-
5
-import "fmt"
6
-
7
-const (
8
- _VT_name_0 = "VT_EMPTYVT_NULLVT_I2VT_I4VT_R4VT_R8VT_CYVT_DATEVT_BSTRVT_DISPATCHVT_ERRORVT_BOOLVT_VARIANTVT_UNKNOWNVT_DECIMAL"
9
- _VT_name_1 = "VT_I1VT_UI1VT_UI2VT_UI4VT_I8VT_UI8VT_INTVT_UINTVT_VOIDVT_HRESULTVT_PTRVT_SAFEARRAYVT_CARRAYVT_USERDEFINEDVT_LPSTRVT_LPWSTR"
10
- _VT_name_2 = "VT_RECORDVT_INT_PTRVT_UINT_PTR"
11
- _VT_name_3 = "VT_FILETIMEVT_BLOBVT_STREAMVT_STORAGEVT_STREAMED_OBJECTVT_STORED_OBJECTVT_BLOB_OBJECTVT_CFVT_CLSID"
12
- _VT_name_4 = "VT_BSTR_BLOBVT_VECTOR"
13
- _VT_name_5 = "VT_ARRAY"
14
- _VT_name_6 = "VT_BYREF"
15
- _VT_name_7 = "VT_RESERVED"
16
- _VT_name_8 = "VT_ILLEGAL"
17
-)
18
-
19
-var (
20
- _VT_index_0 = [...]uint8{0, 8, 15, 20, 25, 30, 35, 40, 47, 54, 65, 73, 80, 90, 100, 110}
21
- _VT_index_1 = [...]uint8{0, 5, 11, 17, 23, 28, 34, 40, 47, 54, 64, 70, 82, 91, 105, 113, 122}
22
- _VT_index_2 = [...]uint8{0, 9, 19, 30}
23
- _VT_index_3 = [...]uint8{0, 11, 18, 27, 37, 55, 71, 85, 90, 98}
24
- _VT_index_4 = [...]uint8{0, 12, 21}
25
- _VT_index_5 = [...]uint8{0, 8}
26
- _VT_index_6 = [...]uint8{0, 8}
27
- _VT_index_7 = [...]uint8{0, 11}
28
- _VT_index_8 = [...]uint8{0, 10}
29
-)
30
-
31
-func (i VT) String() string {
32
- switch {
33
- case 0 <= i && i <= 14:
34
- return _VT_name_0[_VT_index_0[i]:_VT_index_0[i+1]]
35
- case 16 <= i && i <= 31:
36
- i -= 16
37
- return _VT_name_1[_VT_index_1[i]:_VT_index_1[i+1]]
38
- case 36 <= i && i <= 38:
39
- i -= 36
40
- return _VT_name_2[_VT_index_2[i]:_VT_index_2[i+1]]
41
- case 64 <= i && i <= 72:
42
- i -= 64
43
- return _VT_name_3[_VT_index_3[i]:_VT_index_3[i+1]]
44
- case 4095 <= i && i <= 4096:
45
- i -= 4095
46
- return _VT_name_4[_VT_index_4[i]:_VT_index_4[i+1]]
47
- case i == 8192:
48
- return _VT_name_5
49
- case i == 16384:
50
- return _VT_name_6
51
- case i == 32768:
52
- return _VT_name_7
53
- case i == 65535:
54
- return _VT_name_8
55
- default:
56
- return fmt.Sprintf("VT(%d)", i)
57
- }
58
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/winrt.go
deleted
-99
@@ -1,99 +0,0 @@
1
-// +build windows
2
-
3
-package ole
4
-
5
-import (
6
- "reflect"
7
- "syscall"
8
- "unicode/utf8"
9
- "unsafe"
10
-)
11
-
12
-var (
13
- procRoInitialize = modcombase.NewProc("RoInitialize")
14
- procRoActivateInstance = modcombase.NewProc("RoActivateInstance")
15
- procRoGetActivationFactory = modcombase.NewProc("RoGetActivationFactory")
16
- procWindowsCreateString = modcombase.NewProc("WindowsCreateString")
17
- procWindowsDeleteString = modcombase.NewProc("WindowsDeleteString")
18
- procWindowsGetStringRawBuffer = modcombase.NewProc("WindowsGetStringRawBuffer")
19
-)
20
-
21
-func RoInitialize(thread_type uint32) (err error) {
22
- hr, _, _ := procRoInitialize.Call(uintptr(thread_type))
23
- if hr != 0 {
24
- err = NewError(hr)
25
- }
26
- return
27
-}
28
-
29
-func RoActivateInstance(clsid string) (ins *IInspectable, err error) {
30
- hClsid, err := NewHString(clsid)
31
- if err != nil {
32
- return nil, err
33
- }
34
- defer DeleteHString(hClsid)
35
-
36
- hr, _, _ := procRoActivateInstance.Call(
37
- uintptr(unsafe.Pointer(hClsid)),
38
- uintptr(unsafe.Pointer(&ins)))
39
- if hr != 0 {
40
- err = NewError(hr)
41
- }
42
- return
43
-}
44
-
45
-func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) {
46
- hClsid, err := NewHString(clsid)
47
- if err != nil {
48
- return nil, err
49
- }
50
- defer DeleteHString(hClsid)
51
-
52
- hr, _, _ := procRoGetActivationFactory.Call(
53
- uintptr(unsafe.Pointer(hClsid)),
54
- uintptr(unsafe.Pointer(iid)),
55
- uintptr(unsafe.Pointer(&ins)))
56
- if hr != 0 {
57
- err = NewError(hr)
58
- }
59
- return
60
-}
61
-
62
-// HString is handle string for pointers.
63
-type HString uintptr
64
-
65
-// NewHString returns a new HString for Go string.
66
-func NewHString(s string) (hstring HString, err error) {
67
- u16 := syscall.StringToUTF16Ptr(s)
68
- len := uint32(utf8.RuneCountInString(s))
69
- hr, _, _ := procWindowsCreateString.Call(
70
- uintptr(unsafe.Pointer(u16)),
71
- uintptr(len),
72
- uintptr(unsafe.Pointer(&hstring)))
73
- if hr != 0 {
74
- err = NewError(hr)
75
- }
76
- return
77
-}
78
-
79
-// DeleteHString deletes HString.
80
-func DeleteHString(hstring HString) (err error) {
81
- hr, _, _ := procWindowsDeleteString.Call(uintptr(hstring))
82
- if hr != 0 {
83
- err = NewError(hr)
84
- }
85
- return
86
-}
87
-
88
-// String returns Go string value of HString.
89
-func (h HString) String() string {
90
- var u16buf uintptr
91
- var u16len uint32
92
- u16buf, _, _ = procWindowsGetStringRawBuffer.Call(
93
- uintptr(h),
94
- uintptr(unsafe.Pointer(&u16len)))
95
-
96
- u16hdr := reflect.SliceHeader{Data: u16buf, Len: int(u16len), Cap: int(u16len)}
97
- u16 := *(*[]uint16)(unsafe.Pointer(&u16hdr))
98
- return syscall.UTF16ToString(u16)
99
-}
Godeps/_workspace/src/github.com/go-ole/go-ole/winrt_doc.go
deleted
-36
@@ -1,36 +0,0 @@
1
-// +build !windows
2
-
3
-package ole
4
-
5
-// RoInitialize
6
-func RoInitialize(thread_type uint32) (err error) {
7
- return NewError(E_NOTIMPL)
8
-}
9
-
10
-// RoActivateInstance
11
-func RoActivateInstance(clsid string) (ins *IInspectable, err error) {
12
- return nil, NewError(E_NOTIMPL)
13
-}
14
-
15
-// RoGetActivationFactory
16
-func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) {
17
- return nil, NewError(E_NOTIMPL)
18
-}
19
-
20
-// HString is handle string for pointers.
21
-type HString uintptr
22
-
23
-// NewHString returns a new HString for Go string.
24
-func NewHString(s string) (hstring HString, err error) {
25
- return HString(uintptr(0)), NewError(E_NOTIMPL)
26
-}
27
-
28
-// DeleteHString deletes HString.
29
-func DeleteHString(hstring HString) (err error) {
30
- return NewError(E_NOTIMPL)
31
-}
32
-
33
-// String returns Go string value of HString.
34
-func (h HString) String() string {
35
- return ""
36
-}
Godeps/_workspace/src/github.com/inconshreveable/go-update/LICENSE
deleted
-13
@@ -1,13 +0,0 @@
1
-Copyright 2014 Alan Shreve
2
-
3
-Licensed under the Apache License, Version 2.0 (the "License");
4
-you may not use this file except in compliance with the License.
5
-You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
-Unless required by applicable law or agreed to in writing, software
10
-distributed under the License is distributed on an "AS IS" BASIS,
11
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-See the License for the specific language governing permissions and
13
-limitations under the License.
Godeps/_workspace/src/github.com/inconshreveable/go-update/README.md
deleted
-37
@@ -1,37 +0,0 @@
1
-# go-update: Automatically update Go programs from the internet
2
-
3
-go-update allows a program to update itself by replacing its executable file
4
-with a new version. It provides the flexibility to implement different updating user experiences
5
-like auto-updating, or manual user-initiated updates. It also boasts
6
-advanced features like binary patching and code signing verification.
7
-
8
-Updating your program to a new version is as easy as:
9
-
10
- err, errRecover := update.New().FromUrl("http://release.example.com/2.0/myprogram")
11
- if err != nil {
12
- fmt.Printf("Update failed: %v\n", err)
13
- }
14
-
15
-## Documentation and API Reference
16
-
17
-Comprehensive API documentation and code examples are available in the code documentation available on godoc.org:
18
-
19
-[](https://godoc.org/github.com/inconshreveable/go-update)
20
-
21
-## Features
22
-
23
-- Cross platform support (Windows too!)
24
-- Binary patch application
25
-- Checksum verification
26
-- Code signing verification
27
-- Support for updating arbitrary files
28
-
29
-## [equinox.io](https://equinox.io)
30
-go-update provides the primitives for building self-updating applications, but there a number of other challenges
31
-involved in a complete updating solution such as hosting, code signing, update channels, gradual rollout,
32
-dynamically computing binary patches, tracking update metrics like versions and failures, plus more.
33
-
34
-I provide this service, a complete solution, free for open source projects, at [equinox.io](https://equinox.io).
35
-
36
-## License
37
-Apache
Godeps/_workspace/src/github.com/inconshreveable/go-update/check/check.go
deleted
-209
@@ -1,209 +0,0 @@
1
-package check
2
-
3
-import (
4
- "bytes"
5
- _ "crypto/sha512" // for tls cipher support
6
- "encoding/hex"
7
- "encoding/json"
8
- "fmt"
9
- "io/ioutil"
10
- "net/http"
11
- "runtime"
12
-
13
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update"
14
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kardianos/osext"
15
-)
16
-
17
-type Initiative string
18
-
19
-const (
20
- INITIATIVE_NEVER Initiative = "never"
21
- INITIATIVE_AUTO = "auto"
22
- INITIATIVE_MANUAL = "manual"
23
-)
24
-
25
-var NoUpdateAvailable error = fmt.Errorf("No update available")
26
-
27
-type Params struct {
28
- // protocol version
29
- Version int `json:"version"`
30
- // identifier of the application to update
31
- AppId string `json:"app_id"`
32
- // version of the application updating itself
33
- AppVersion string `json:"app_version"`
34
- // operating system of target platform
35
- OS string `json:"-"`
36
- // hardware architecture of target platform
37
- Arch string `json:"-"`
38
- // application-level user identifier
39
- UserId string `json:"user_id"`
40
- // checksum of the binary to replace (used for returning diff patches)
41
- Checksum string `json:"checksum"`
42
- // release channel (empty string means 'stable')
43
- Channel string `json:"-"`
44
- // tags for custom update channels
45
- Tags map[string]string `json:"tags"`
46
-}
47
-
48
-type Result struct {
49
- up *update.Update
50
-
51
- // should the update be applied automatically/manually
52
- Initiative Initiative `json:"initiative"`
53
- // url where to download the updated application
54
- Url string `json:"url"`
55
- // a URL to a patch to apply
56
- PatchUrl string `json:"patch_url"`
57
- // the patch format (only bsdiff supported at the moment)
58
- PatchType update.PatchType `json:"patch_type"`
59
- // version of the new application
60
- Version string `json:"version"`
61
- // expected checksum of the new application
62
- Checksum string `json:"checksum"`
63
- // signature for verifying update authenticity
64
- Signature string `json:"signature"`
65
-}
66
-
67
-// CheckForUpdate makes an HTTP post to a URL with the JSON serialized
68
-// representation of Params. It returns the deserialized result object
69
-// returned by the remote endpoint or an error. If you do not set
70
-// OS/Arch, CheckForUpdate will populate them for you. Similarly, if
71
-// Version is 0, it will be set to 1. Lastly, if Checksum is the empty
72
-// string, it will be automatically be computed for the running program's
73
-// executable file.
74
-func (p *Params) CheckForUpdate(url string, up *update.Update) (*Result, error) {
75
- if p.Tags == nil {
76
- p.Tags = make(map[string]string)
77
- }
78
-
79
- if p.Channel == "" {
80
- p.Channel = "stable"
81
- }
82
-
83
- if p.OS == "" {
84
- p.OS = runtime.GOOS
85
- }
86
-
87
- if p.Arch == "" {
88
- p.Arch = runtime.GOARCH
89
- }
90
-
91
- if p.Version == 0 {
92
- p.Version = 1
93
- }
94
-
95
- // ignore errors auto-populating the checksum
96
- // if it fails, you just won't be able to patch
97
- if up.TargetPath == "" {
98
- p.Checksum = defaultChecksum()
99
- } else {
100
- checksum, err := update.ChecksumForFile(up.TargetPath)
101
- if err != nil {
102
- return nil, err
103
- }
104
- p.Checksum = hex.EncodeToString(checksum)
105
- }
106
-
107
- p.Tags["os"] = p.OS
108
- p.Tags["arch"] = p.Arch
109
- p.Tags["channel"] = p.Channel
110
-
111
- body, err := json.Marshal(p)
112
- if err != nil {
113
- return nil, err
114
- }
115
-
116
- resp, err := http.Post(url, "application/json", bytes.NewReader(body))
117
- if err != nil {
118
- return nil, err
119
- }
120
-
121
- // no content means no available update
122
- if resp.StatusCode == 204 {
123
- return nil, NoUpdateAvailable
124
- }
125
-
126
- defer resp.Body.Close()
127
- respBytes, err := ioutil.ReadAll(resp.Body)
128
- if err != nil {
129
- return nil, err
130
- }
131
-
132
- result := &Result{up: up}
133
- if err := json.Unmarshal(respBytes, result); err != nil {
134
- return nil, err
135
- }
136
-
137
- return result, nil
138
-}
139
-
140
-func (p *Params) CheckAndApplyUpdate(url string, up *update.Update) (result *Result, err error, errRecover error) {
141
- // check for an update
142
- result, err = p.CheckForUpdate(url, up)
143
- if err != nil {
144
- return
145
- }
146
-
147
- // run the available update
148
- err, errRecover = result.Update()
149
- return
150
-}
151
-
152
-func (r *Result) Update() (err error, errRecover error) {
153
- if r.Checksum != "" {
154
- r.up.Checksum, err = hex.DecodeString(r.Checksum)
155
- if err != nil {
156
- return
157
- }
158
- }
159
-
160
- if r.Signature != "" {
161
- r.up.Signature, err = hex.DecodeString(r.Signature)
162
- if err != nil {
163
- return
164
- }
165
- }
166
-
167
- if r.PatchType != "" {
168
- r.up.PatchType = r.PatchType
169
- }
170
-
171
- if r.Url == "" && r.PatchUrl == "" {
172
- err = fmt.Errorf("Result does not contain an update url or patch update url")
173
- return
174
- }
175
-
176
- if r.PatchUrl != "" {
177
- err, errRecover = r.up.FromUrl(r.PatchUrl)
178
- if err == nil {
179
- // success!
180
- return
181
- } else {
182
- // failed to update from patch URL, try with the whole thing
183
- if r.Url == "" || errRecover != nil {
184
- // we can't try updating from a URL with the full contents
185
- // in these cases, so fail
186
- return
187
- } else {
188
- r.up.PatchType = update.PATCHTYPE_NONE
189
- }
190
- }
191
- }
192
-
193
- // try updating from a URL with the full contents
194
- return r.up.FromUrl(r.Url)
195
-}
196
-
197
-func defaultChecksum() string {
198
- path, err := osext.Executable()
199
- if err != nil {
200
- return ""
201
- }
202
-
203
- checksum, err := update.ChecksumForFile(path)
204
- if err != nil {
205
- return ""
206
- }
207
-
208
- return hex.EncodeToString(checksum)
209
-}
Godeps/_workspace/src/github.com/inconshreveable/go-update/download/download.go
deleted
-230
@@ -1,230 +0,0 @@
1
-package download
2
-
3
-import (
4
- "bytes"
5
- "compress/gzip"
6
- "fmt"
7
- "io"
8
- "net/http"
9
- "os"
10
- "runtime"
11
-)
12
-
13
-type roundTripper struct {
14
- RoundTripFn func(*http.Request) (*http.Response, error)
15
-}
16
-
17
-func (rt *roundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
18
- return rt.RoundTripFn(r)
19
-}
20
-
21
-// Download encapsulates the state and parameters to download content
22
-// from a URL which:
23
-//
24
-// - Publishes the percentage of the download completed to a channel.
25
-// - May resume a previous download that was partially completed.
26
-//
27
-// Create an instance with the New() factory function.
28
-type Download struct {
29
- // net/http.Client to use when downloading the update.
30
- // If nil, a default http.Client is used
31
- HttpClient *http.Client
32
-
33
- // As bytes are downloaded, they are written to Target.
34
- // Download also uses the Target's Seek method to determine
35
- // the size of partial-downloads so that it may properly
36
- // request the remaining bytes to resume the download.
37
- Target Target
38
-
39
- // Progress returns the percentage of the download
40
- // completed as an integer between 0 and 100
41
- Progress chan (int)
42
-
43
- // HTTP Method to use in the download request. Default is "GET"
44
- Method string
45
-
46
- // HTTP URL to issue the download request to
47
- Url string
48
-}
49
-
50
-// New initializes a new Download object which will download
51
-// the content from url into target.
52
-func New(url string, target Target) *Download {
53
- return &Download{
54
- HttpClient: new(http.Client),
55
- Progress: make(chan int),
56
- Method: "GET",
57
- Url: url,
58
- Target: target,
59
- }
60
-}
61
-
62
-// Get() downloads the content of a url to a target destination.
63
-//
64
-// Only HTTP/1.1 servers that implement the Range header support resuming a
65
-// partially completed download.
66
-//
67
-// On success, the server must return 200 and the content, or 206 when resuming a partial download.
68
-// If the HTTP server returns a 3XX redirect, it will be followed according to d.HttpClient's redirect policy.
69
-//
70
-func (d *Download) Get() (err error) {
71
- // Close the progress channel whenever this function completes
72
- defer close(d.Progress)
73
-
74
- // determine the size of the download target to determine if we're resuming a partial download
75
- offset, err := d.Target.Size()
76
- if err != nil {
77
- return
78
- }
79
-
80
- // create the download request
81
- req, err := http.NewRequest(d.Method, d.Url, nil)
82
- if err != nil {
83
- return
84
- }
85
-
86
- // we have to add headers like this so they get used across redirects
87
- trans := d.HttpClient.Transport
88
- if trans == nil {
89
- trans = http.DefaultTransport
90
- }
91
-
92
- d.HttpClient.Transport = &roundTripper{
93
- RoundTripFn: func(r *http.Request) (*http.Response, error) {
94
- // add header for download continuation
95
- if offset > 0 {
96
- r.Header.Add("Range", fmt.Sprintf("%d-", offset))
97
- }
98
-
99
- // ask for gzipped content so that net/http won't unzip it for us
100
- // and destroy the content length header we need for progress calculations
101
- r.Header.Add("Accept-Encoding", "gzip")
102
-
103
- return trans.RoundTrip(r)
104
- },
105
- }
106
-
107
- // issue the download request
108
- resp, err := d.HttpClient.Do(req)
109
- if err != nil {
110
- return
111
- }
112
- defer resp.Body.Close()
113
-
114
- switch resp.StatusCode {
115
- // ok
116
- case 200, 206:
117
-
118
- // server error
119
- default:
120
- err = fmt.Errorf("Non 2XX response when downloading update: %s", resp.Status)
121
- return
122
- }
123
-
124
- // Determine how much we have to download
125
- // net/http sets this to -1 when it is unknown
126
- clength := resp.ContentLength
127
-
128
- // Read the content from the response body
129
- rd := resp.Body
130
-
131
- // meter the rate at which we download content for
132
- // progress reporting if we know how much to expect
133
- if clength > 0 {
134
- rd = &meteredReader{rd: rd, totalSize: clength, progress: d.Progress}
135
- }
136
-
137
- // Decompress the content if necessary
138
- if resp.Header.Get("Content-Encoding") == "gzip" {
139
- rd, err = gzip.NewReader(rd)
140
- if err != nil {
141
- return
142
- }
143
- }
144
-
145
- // Download the update
146
- _, err = io.Copy(d.Target, rd)
147
- if err != nil {
148
- return
149
- }
150
-
151
- return
152
-}
153
-
154
-// meteredReader wraps a ReadCloser. Calls to a meteredReader's Read() method
155
-// publish updates to a progress channel with the percentage read so far.
156
-type meteredReader struct {
157
- rd io.ReadCloser
158
- totalSize int64
159
- progress chan int
160
- totalRead int64
161
- ticks int64
162
-}
163
-
164
-func (m *meteredReader) Close() error {
165
- return m.rd.Close()
166
-}
167
-
168
-func (m *meteredReader) Read(b []byte) (n int, err error) {
169
- chunkSize := (m.totalSize / 100) + 1
170
- lenB := int64(len(b))
171
-
172
- var nChunk int
173
- for start := int64(0); start < lenB; start += int64(nChunk) {
174
- end := start + chunkSize
175
- if end > lenB {
176
- end = lenB
177
- }
178
-
179
- nChunk, err = m.rd.Read(b[start:end])
180
-
181
- n += nChunk
182
- m.totalRead += int64(nChunk)
183
-
184
- if m.totalRead > (m.ticks * chunkSize) {
185
- m.ticks += 1
186
- // try to send on channel, but don't block if it's full
187
- select {
188
- case m.progress <- int(m.ticks + 1):
189
- default:
190
- }
191
-
192
- // give the progress channel consumer a chance to run
193
- runtime.Gosched()
194
- }
195
-
196
- if err != nil {
197
- return
198
- }
199
- }
200
-
201
- return
202
-}
203
-
204
-// A Target is what you can supply to Download,
205
-// it's just an io.Writer with a Size() method so that
206
-// the a Download can "resume" an interrupted download
207
-type Target interface {
208
- io.Writer
209
- Size() (int, error)
210
-}
211
-
212
-type FileTarget struct {
213
- *os.File
214
-}
215
-
216
-func (t *FileTarget) Size() (int, error) {
217
- if fi, err := t.File.Stat(); err != nil {
218
- return 0, err
219
- } else {
220
- return int(fi.Size()), nil
221
- }
222
-}
223
-
224
-type MemoryTarget struct {
225
- bytes.Buffer
226
-}
227
-
228
-func (t *MemoryTarget) Size() (int, error) {
229
- return t.Buffer.Len(), nil
230
-}
Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_noop.go
deleted
-7
@@ -1,7 +0,0 @@
1
-// +build !windows
2
-
3
-package update
4
-
5
-func hideFile(path string) error {
6
- return nil
7
-}
Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_windows.go
deleted
-19
@@ -1,19 +0,0 @@
1
-package update
2
-
3
-import (
4
- "syscall"
5
- "unsafe"
6
-)
7
-
8
-func hideFile(path string) error {
9
- kernel32 := syscall.NewLazyDLL("kernel32.dll")
10
- setFileAttributes := kernel32.NewProc("SetFileAttributesW")
11
-
12
- r1, _, err := setFileAttributes.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))), 2)
13
-
14
- if r1 == 0 {
15
- return err
16
- } else {
17
- return nil
18
- }
19
-}
Godeps/_workspace/src/github.com/inconshreveable/go-update/update.go
deleted
-487
@@ -1,487 +0,0 @@
1
-/*
2
-go-update allows a program to update itself by replacing its executable file
3
-with a new version. It provides the flexibility to implement different updating user experiences
4
-like auto-updating, or manual user-initiated updates. It also boasts
5
-advanced features like binary patching and code signing verification.
6
-
7
-Updating your program to a new version is as easy as:
8
-
9
- err, errRecover := update.New().FromUrl("http://release.example.com/2.0/myprogram")
10
- if err != nil {
11
- fmt.Printf("Update failed: %v\n", err)
12
- }
13
-
14
-You may also choose to update from other data sources such as a file or an io.Reader:
15
-
16
- err, errRecover := update.New().FromFile("/path/to/update")
17
-
18
-Binary Diff Patching
19
-
20
-Binary diff updates are supported and easy to use:
21
-
22
- up := update.New().ApplyPatch(update.PATCHTYPE_BSDIFF)
23
- err, errRecover := up.FromUrl("http://release.example.com/2.0/mypatch")
24
-
25
-Checksum Verification
26
-
27
-You should also verify the checksum of new updates as well as verify
28
-the digital signature of an update. Note that even when you choose to apply
29
-a patch, the checksum is verified against the complete update after that patch
30
-has been applied.
31
-
32
- up := update.New().ApplyPatch(update.PATCHTYPE_BSDIFF).VerifyChecksum(checksum)
33
- err, errRecover := up.FromUrl("http://release.example.com/2.0/mypatch")
34
-
35
-Updating other files
36
-
37
-Updating arbitrary files is also supported. You may update files which are
38
-not the currently running program:
39
-
40
- up := update.New().Target("/usr/local/bin/some-program")
41
- err, errRecover := up.FromUrl("http://release.example.com/2.0/some-program")
42
-
43
-Code Signing
44
-
45
-Truly secure updates use code signing to verify that the update was issued by a trusted party.
46
-To do this, you'll need to generate a public/private key pair. You can do this with openssl,
47
-or the equinox.io client (https://equinox.io/client) can easily generate one for you:
48
-
49
- # with equinox client
50
- equinox genkey --private-key=private.pem --public-key=public.pem
51
-
52
- # with openssl
53
- openssl genrsa -out private.pem 2048
54
- openssl rsa -in private.pem -out public.pem -pubout
55
-
56
-Once you have your key pair, you can instruct your program to validate its updates
57
-with the public key:
58
-
59
- const publicKey = `-----BEGIN PUBLIC KEY-----
60
- ...
61
- -----END PUBLIC KEY-----`
62
-
63
- up, err := update.New().VerifySignatureWithPEM(publicKey)
64
- if err != nil {
65
- return fmt.Errorf("Bad public key: '%v': %v", publicKey, err)
66
- }
67
-
68
-Once you've configured your program this way, it will disallow all updates unless they
69
-are properly signed. You must now pass in the signature to verify with:
70
-
71
- up.VerifySignature(signature).FromUrl("http://dl.example.com/update")
72
-
73
-Error Handling and Recovery
74
-
75
-To perform an update, the process must be able to read its executable file and to write
76
-to the directory that contains its executable file. It can be useful to check whether the process
77
-has the necessary permissions to perform an update before trying to apply one. Use the
78
-CanUpdate call to provide a useful message to the user if the update can't proceed without
79
-elevated permissions:
80
-
81
- up := update.New().Target("/etc/hosts")
82
- err := up.CanUpdate()
83
- if err != nil {
84
- fmt.Printf("Can't update because: '%v'. Try as root or Administrator\n", err)
85
- return
86
- }
87
- err, errRecover := up.FromUrl("https://example.com/new/hosts")
88
-
89
-Although exceedingly unlikely, the update operation itself is not atomic and can fail
90
-in such a way that a user's computer is left in an inconsistent state. If that happens,
91
-go-update attempts to recover to leave the system in a good state. If the recovery step
92
-fails (even more unlikely), a second error, referred to as "errRecover" will be non-nil
93
-so that you may inform your users of the bad news. You should handle this case as shown
94
-here:
95
-
96
- err, errRecover := up.FromUrl("https://example.com/update")
97
- if err != nil {
98
- fmt.Printf("Update failed: %v\n", err)
99
- if errRecover != nil {
100
- fmt.Printf("Failed to recover bad update: %v!\n", errRecover)
101
- fmt.Printf("Program exectuable may be missing!\n")
102
- }
103
- }
104
-
105
-Subpackages
106
-
107
-Sub-package check contains the client functionality for a simple protocol for negotiating
108
-whether a new update is available, where it is, and the metadata needed for verifying it.
109
-
110
-Sub-package download contains functionality for downloading from an HTTP endpoint
111
-while outputting a progress meter and supports resuming partial downloads.
112
-*/
113
-package update
114
-
115
-import (
116
- "bytes"
117
- "crypto"
118
- "crypto/rsa"
119
- "crypto/sha256"
120
- _ "crypto/sha512" // for tls cipher support
121
- "crypto/x509"
122
- "encoding/pem"
123
- "fmt"
124
- "io"
125
- "io/ioutil"
126
- "os"
127
- "path/filepath"
128
-
129
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update/download"
130
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kardianos/osext"
131
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kr/binarydist"
132
-)
133
-
134
-// The type of a binary patch, if any. Only bsdiff is supported
135
-type PatchType string
136
-
137
-const (
138
- PATCHTYPE_BSDIFF PatchType = "bsdiff"
139
- PATCHTYPE_NONE = ""
140
-)
141
-
142
-type Update struct {
143
- // empty string means "path of the current executable"
144
- TargetPath string
145
-
146
- // type of patch to apply. PATCHTYPE_NONE means "not a patch"
147
- PatchType
148
-
149
- // sha256 checksum of the new binary to verify against
150
- Checksum []byte
151
-
152
- // public key to use for signature verification
153
- PublicKey *rsa.PublicKey
154
-
155
- // signature to use for signature verification
156
- Signature []byte
157
-}
158
-
159
-func (u *Update) getPath() (string, error) {
160
- if u.TargetPath == "" {
161
- return osext.Executable()
162
- } else {
163
- return u.TargetPath, nil
164
- }
165
-}
166
-
167
-// New creates a new Update object.
168
-// A default update object assumes the complete binary
169
-// content will be used for update (not a patch) and that
170
-// the intended target is the running executable.
171
-//
172
-// Use this as the start of a chain of calls on the Update
173
-// object to build up your configuration. Example:
174
-//
175
-// up := update.New().ApplyPatch(update.PATCHTYPE_BSDIFF).VerifyChecksum(checksum)
176
-//
177
-func New() *Update {
178
- return &Update{
179
- TargetPath: "",
180
- PatchType: PATCHTYPE_NONE,
181
- }
182
-}
183
-
184
-// Target configures the update to update the file at the given path.
185
-// The emptry string means 'the executable file of the running program'.
186
-func (u *Update) Target(path string) *Update {
187
- u.TargetPath = path
188
- return u
189
-}
190
-
191
-// ApplyPatch configures the update to treat the contents of the update
192
-// as a patch to apply to the existing to target. You must specify the
193
-// format of the patch. Only PATCHTYPE_BSDIFF is supported at the moment.
194
-func (u *Update) ApplyPatch(patchType PatchType) *Update {
195
- u.PatchType = patchType
196
- return u
197
-}
198
-
199
-// VerifyChecksum configures the update to verify that the
200
-// the update has the given sha256 checksum.
201
-func (u *Update) VerifyChecksum(checksum []byte) *Update {
202
- u.Checksum = checksum
203
- return u
204
-}
205
-
206
-// VerifySignature configures the update to verify the given
207
-// signature of the update. You must also call one of the
208
-// VerifySignatureWith* functions to specify a public key
209
-// to use for verification.
210
-func (u *Update) VerifySignature(signature []byte) *Update {
211
- u.Signature = signature
212
- return u
213
-}
214
-
215
-// VerifySignatureWith configures the update to use the given RSA
216
-// public key to verify the update's signature. You must also call
217
-// VerifySignature() with a signature to check.
218
-//
219
-// You'll probably want to use VerifySignatureWithPEM instead of
220
-// parsing the public key yourself.
221
-func (u *Update) VerifySignatureWith(publicKey *rsa.PublicKey) *Update {
222
- u.PublicKey = publicKey
223
- return u
224
-}
225
-
226
-// VerifySignatureWithPEM configures the update to use the given PEM-formatted
227
-// RSA public key to verify the update's signature. You must also call
228
-// VerifySignature() with a signature to check.
229
-//
230
-// A PEM formatted public key typically begins with
231
-// -----BEGIN PUBLIC KEY-----
232
-func (u *Update) VerifySignatureWithPEM(publicKeyPEM []byte) (*Update, error) {
233
- block, _ := pem.Decode(publicKeyPEM)
234
- if block == nil {
235
- return u, fmt.Errorf("Couldn't parse PEM data")
236
- }
237
-
238
- pub, err := x509.ParsePKIXPublicKey(block.Bytes)
239
- if err != nil {
240
- return u, err
241
- }
242
-
243
- var ok bool
244
- u.PublicKey, ok = pub.(*rsa.PublicKey)
245
- if !ok {
246
- return u, fmt.Errorf("Public key isn't an RSA public key")
247
- }
248
-
249
- return u, nil
250
-}
251
-
252
-// FromUrl updates the target with the contents of the given URL.
253
-func (u *Update) FromUrl(url string) (err error, errRecover error) {
254
- target := new(download.MemoryTarget)
255
- err = download.New(url, target).Get()
256
- if err != nil {
257
- return
258
- }
259
-
260
- return u.FromStream(target)
261
-}
262
-
263
-// FromFile updates the target the contents of the given file.
264
-func (u *Update) FromFile(path string) (err error, errRecover error) {
265
- // open the new updated contents
266
- fp, err := os.Open(path)
267
- if err != nil {
268
- return
269
- }
270
- defer fp.Close()
271
-
272
- // do the update
273
- return u.FromStream(fp)
274
-}
275
-
276
-// FromStream updates the target file with the contents of the supplied io.Reader.
277
-//
278
-// FromStream performs the following actions to ensure a safe cross-platform update:
279
-//
280
-// 1. If configured, applies the contents of the io.Reader as a binary patch.
281
-//
282
-// 2. If configured, computes the sha256 checksum and verifies it matches.
283
-//
284
-// 3. If configured, verifies the RSA signature with a public key.
285
-//
286
-// 4. Creates a new file, /path/to/.target.new with mode 0755 with the contents of the updated file
287
-//
288
-// 5. Renames /path/to/target to /path/to/.target.old
289
-//
290
-// 6. Renames /path/to/.target.new to /path/to/target
291
-//
292
-// 7. If the rename is successful, deletes /path/to/.target.old, returns no error
293
-//
294
-// 8. If the rename fails, attempts to rename /path/to/.target.old back to /path/to/target
295
-// If this operation fails, it is reported in the errRecover return value so as not to
296
-// mask the original error that caused the recovery attempt.
297
-//
298
-// On Windows, the removal of /path/to/.target.old always fails, so instead,
299
-// we just make the old file hidden instead.
300
-func (u *Update) FromStream(updateWith io.Reader) (err error, errRecover error) {
301
- updatePath, err := u.getPath()
302
- if err != nil {
303
- return
304
- }
305
-
306
- var newBytes []byte
307
- // apply a patch if requested
308
- switch u.PatchType {
309
- case PATCHTYPE_BSDIFF:
310
- newBytes, err = applyPatch(updateWith, updatePath)
311
- if err != nil {
312
- return
313
- }
314
- case PATCHTYPE_NONE:
315
- // no patch to apply, go on through
316
- newBytes, err = ioutil.ReadAll(updateWith)
317
- if err != nil {
318
- return
319
- }
320
- default:
321
- err = fmt.Errorf("Unrecognized patch type: %s", u.PatchType)
322
- return
323
- }
324
-
325
- // verify checksum if requested
326
- if u.Checksum != nil {
327
- if err = verifyChecksum(newBytes, u.Checksum); err != nil {
328
- return
329
- }
330
- }
331
-
332
- // verify signature if requested
333
- if u.Signature != nil || u.PublicKey != nil {
334
- if u.Signature == nil {
335
- err = fmt.Errorf("No public key specified to verify signature")
336
- return
337
- }
338
-
339
- if u.PublicKey == nil {
340
- err = fmt.Errorf("No signature to verify!")
341
- return
342
- }
343
-
344
- if err = verifySignature(newBytes, u.Signature, u.PublicKey); err != nil {
345
- return
346
- }
347
- }
348
-
349
- // get the directory the executable exists in
350
- updateDir := filepath.Dir(updatePath)
351
- filename := filepath.Base(updatePath)
352
-
353
- // Copy the contents of of newbinary to a the new executable file
354
- newPath := filepath.Join(updateDir, fmt.Sprintf(".%s.new", filename))
355
- fp, err := os.OpenFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
356
- if err != nil {
357
- return
358
- }
359
- defer fp.Close()
360
- _, err = io.Copy(fp, bytes.NewReader(newBytes))
361
-
362
- // if we don't call fp.Close(), windows won't let us move the new executable
363
- // because the file will still be "in use"
364
- fp.Close()
365
-
366
- // this is where we'll move the executable to so that we can swap in the updated replacement
367
- oldPath := filepath.Join(updateDir, fmt.Sprintf(".%s.old", filename))
368
-
369
- // delete any existing old exec file - this is necessary on Windows for two reasons:
370
- // 1. after a successful update, Windows can't remove the .old file because the process is still running
371
- // 2. windows rename operations fail if the destination file already exists
372
- _ = os.Remove(oldPath)
373
-
374
- // move the existing executable to a new file in the same directory
375
- err = os.Rename(updatePath, oldPath)
376
- if err != nil {
377
- return
378
- }
379
-
380
- // move the new exectuable in to become the new program
381
- err = os.Rename(newPath, updatePath)
382
-
383
- if err != nil {
384
- // copy unsuccessful
385
- errRecover = os.Rename(oldPath, updatePath)
386
- } else {
387
- // copy successful, remove the old binary
388
- errRemove := os.Remove(oldPath)
389
-
390
- // windows has trouble with removing old binaries, so hide it instead
391
- if errRemove != nil {
392
- _ = hideFile(oldPath)
393
- }
394
- }
395
-
396
- return
397
-}
398
-
399
-// CanUpdate() determines whether the process has the correct permissions to
400
-// perform the requested update. If the update can proceed, it returns nil, otherwise
401
-// it returns the error that would occur if an update were attempted.
402
-func (u *Update) CanUpdate() (err error) {
403
- // get the directory the file exists in
404
- path, err := u.getPath()
405
- if err != nil {
406
- return
407
- }
408
-
409
- fileDir := filepath.Dir(path)
410
- fileName := filepath.Base(path)
411
-
412
- // attempt to open a file in the file's directory
413
- newPath := filepath.Join(fileDir, fmt.Sprintf(".%s.new", fileName))
414
- fp, err := os.OpenFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
415
- if err != nil {
416
- return
417
- }
418
- fp.Close()
419
-
420
- _ = os.Remove(newPath)
421
- return
422
-}
423
-
424
-func applyPatch(patch io.Reader, updatePath string) ([]byte, error) {
425
- // open the file to update
426
- old, err := os.Open(updatePath)
427
- if err != nil {
428
- return nil, err
429
- }
430
- defer old.Close()
431
-
432
- // apply the patch
433
- applied := new(bytes.Buffer)
434
- if err = binarydist.Patch(old, applied, patch); err != nil {
435
- return nil, err
436
- }
437
-
438
- return applied.Bytes(), nil
439
-}
440
-
441
-func verifyChecksum(updated []byte, expectedChecksum []byte) error {
442
- checksum, err := ChecksumForBytes(updated)
443
- if err != nil {
444
- return err
445
- }
446
-
447
- if !bytes.Equal(expectedChecksum, checksum) {
448
- return fmt.Errorf("Updated file has wrong checksum. Expected: %x, got: %x", expectedChecksum, checksum)
449
- }
450
-
451
- return nil
452
-}
453
-
454
-// ChecksumForFile returns the sha256 checksum for the given file
455
-func ChecksumForFile(path string) ([]byte, error) {
456
- f, err := os.Open(path)
457
- if err != nil {
458
- return nil, err
459
- }
460
- defer f.Close()
461
-
462
- return ChecksumForReader(f)
463
-}
464
-
465
-// ChecksumForReader returns the sha256 checksum for the entire
466
-// contents of the given reader.
467
-func ChecksumForReader(rd io.Reader) ([]byte, error) {
468
- h := sha256.New()
469
- if _, err := io.Copy(h, rd); err != nil {
470
- return nil, err
471
- }
472
- return h.Sum(nil), nil
473
-}
474
-
475
-// ChecksumForBytes returns the sha256 checksum for the given bytes
476
-func ChecksumForBytes(source []byte) ([]byte, error) {
477
- return ChecksumForReader(bytes.NewReader(source))
478
-}
479
-
480
-func verifySignature(source, signature []byte, publicKey *rsa.PublicKey) error {
481
- checksum, err := ChecksumForBytes(source)
482
- if err != nil {
483
- return err
484
- }
485
-
486
- return rsa.VerifyPKCS1v15(publicKey, crypto.SHA256, checksum, signature)
487
-}
Godeps/_workspace/src/github.com/inconshreveable/go-update/update_test.go
deleted
-380
@@ -1,380 +0,0 @@
1
-package update
2
-
3
-import (
4
- "bytes"
5
- "crypto"
6
- "crypto/rand"
7
- "crypto/rsa"
8
- "crypto/x509"
9
- "encoding/pem"
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kr/binarydist"
11
- "io/ioutil"
12
- "net"
13
- "net/http"
14
- "os"
15
- "testing"
16
-)
17
-
18
-var (
19
- oldFile = []byte{0xDE, 0xAD, 0xBE, 0xEF}
20
- newFile = []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}
21
-)
22
-
23
-func cleanup(path string) {
24
- os.Remove(path)
25
-}
26
-
27
-// we write with a separate name for each test so that we can run them in parallel
28
-func writeOldFile(path string, t *testing.T) {
29
- if err := ioutil.WriteFile(path, oldFile, 0777); err != nil {
30
- t.Fatalf("Failed to write file for testing preparation: %v", err)
31
- }
32
-}
33
-
34
-func validateUpdate(path string, err error, t *testing.T) {
35
- if err != nil {
36
- t.Fatalf("Failed to update: %v", err)
37
- }
38
-
39
- buf, err := ioutil.ReadFile(path)
40
- if err != nil {
41
- t.Fatalf("Failed to read file post-update: %v", err)
42
- }
43
-
44
- if !bytes.Equal(buf, newFile) {
45
- t.Fatalf("File was not updated! Bytes read: %v, Bytes expected: %v", buf, newFile)
46
- }
47
-}
48
-
49
-func TestFromStream(t *testing.T) {
50
- t.Parallel()
51
-
52
- fName := "TestFromStream"
53
- defer cleanup(fName)
54
- writeOldFile(fName, t)
55
-
56
- err, _ := New().Target(fName).FromStream(bytes.NewReader(newFile))
57
- validateUpdate(fName, err, t)
58
-}
59
-
60
-func TestFromFile(t *testing.T) {
61
- t.Parallel()
62
-
63
- fName := "TestFromFile"
64
- newFName := "NewTestFromFile"
65
- defer cleanup(fName)
66
- defer cleanup(newFName)
67
- writeOldFile(fName, t)
68
-
69
- if err := ioutil.WriteFile(newFName, newFile, 0777); err != nil {
70
- t.Fatalf("Failed to write file to update from: %v", err)
71
- }
72
-
73
- err, _ := New().Target(fName).FromFile(newFName)
74
- validateUpdate(fName, err, t)
75
-}
76
-
77
-func TestFromUrl(t *testing.T) {
78
- t.Parallel()
79
-
80
- fName := "TestFromUrl"
81
- defer cleanup(fName)
82
- writeOldFile(fName, t)
83
-
84
- l, err := net.Listen("tcp", ":0")
85
- if err != nil {
86
- t.Fatalf("Couldn't bind listener: %v", err)
87
- }
88
- addr := l.Addr().String()
89
-
90
- go http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
91
- w.Write(newFile)
92
- }))
93
-
94
- err, _ = New().Target(fName).FromUrl("http://" + addr)
95
- validateUpdate(fName, err, t)
96
-}
97
-
98
-func TestVerifyChecksum(t *testing.T) {
99
- t.Parallel()
100
-
101
- fName := "TestVerifyChecksum"
102
- defer cleanup(fName)
103
- writeOldFile(fName, t)
104
-
105
- checksum, err := ChecksumForBytes(newFile)
106
- if err != nil {
107
- t.Fatalf("Failed to compute checksum: %v", err)
108
- }
109
-
110
- err, _ = New().Target(fName).VerifyChecksum(checksum).FromStream(bytes.NewReader(newFile))
111
- validateUpdate(fName, err, t)
112
-}
113
-
114
-func TestVerifyChecksumNegative(t *testing.T) {
115
- t.Parallel()
116
-
117
- fName := "TestVerifyChecksumNegative"
118
- defer cleanup(fName)
119
- writeOldFile(fName, t)
120
-
121
- badChecksum := []byte{0x0A, 0x0B, 0x0C, 0xFF}
122
- err, _ := New().Target(fName).VerifyChecksum(badChecksum).FromStream(bytes.NewReader(newFile))
123
- if err == nil {
124
- t.Fatalf("Failed to detect bad checksum!")
125
- }
126
-}
127
-
128
-func TestApplyPatch(t *testing.T) {
129
- t.Parallel()
130
-
131
- fName := "TestApplyPatch"
132
- defer cleanup(fName)
133
- writeOldFile(fName, t)
134
-
135
- patch := new(bytes.Buffer)
136
- err := binarydist.Diff(bytes.NewReader(oldFile), bytes.NewReader(newFile), patch)
137
- if err != nil {
138
- t.Fatalf("Failed to create patch: %v", err)
139
- }
140
-
141
- up := New().Target(fName).ApplyPatch(PATCHTYPE_BSDIFF)
142
- err, _ = up.FromStream(bytes.NewReader(patch.Bytes()))
143
- validateUpdate(fName, err, t)
144
-}
145
-
146
-func TestCorruptPatch(t *testing.T) {
147
- t.Parallel()
148
-
149
- fName := "TestCorruptPatch"
150
- defer cleanup(fName)
151
- writeOldFile(fName, t)
152
-
153
- badPatch := []byte{0x44, 0x38, 0x86, 0x3c, 0x4f, 0x8d, 0x26, 0x54, 0xb, 0x11, 0xce, 0xfe, 0xc1, 0xc0, 0xf8, 0x31, 0x38, 0xa0, 0x12, 0x1a, 0xa2, 0x57, 0x2a, 0xe1, 0x3a, 0x48, 0x62, 0x40, 0x2b, 0x81, 0x12, 0xb1, 0x21, 0xa5, 0x16, 0xed, 0x73, 0xd6, 0x54, 0x84, 0x29, 0xa6, 0xd6, 0xb2, 0x1b, 0xfb, 0xe6, 0xbe, 0x7b, 0x70}
154
- up := New().Target(fName).ApplyPatch(PATCHTYPE_BSDIFF)
155
- err, _ := up.FromStream(bytes.NewReader(badPatch))
156
- if err == nil {
157
- t.Fatalf("Failed to detect corrupt patch!")
158
- }
159
-}
160
-
161
-func TestVerifyChecksumPatchNegative(t *testing.T) {
162
- t.Parallel()
163
-
164
- fName := "TestVerifyChecksumPatchNegative"
165
- defer cleanup(fName)
166
- writeOldFile(fName, t)
167
-
168
- checksum, err := ChecksumForBytes(newFile)
169
- if err != nil {
170
- t.Fatalf("Failed to compute checksum: %v", err)
171
- }
172
-
173
- patch := new(bytes.Buffer)
174
- anotherFile := []byte{0x77, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}
175
- err = binarydist.Diff(bytes.NewReader(oldFile), bytes.NewReader(anotherFile), patch)
176
- if err != nil {
177
- t.Fatalf("Failed to create patch: %v", err)
178
- }
179
-
180
- up := New().Target(fName).ApplyPatch(PATCHTYPE_BSDIFF).VerifyChecksum(checksum)
181
- err, _ = up.FromStream(bytes.NewReader(patch.Bytes()))
182
- if err == nil {
183
- t.Fatalf("Failed to detect patch to wrong file!")
184
- }
185
-}
186
-
187
-const publicKey = `-----BEGIN PUBLIC KEY-----
188
-MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxSWmu7trWKAwDFjiCN2D
189
-Tk2jj2sgcr/CMlI4cSSiIOHrXCFxP1I8i9PvQkd4hasXQrLbT5WXKrRGv1HKUKab
190
-b9ead+kD0kxk7i2bFYvKX43oq66IW0mOLTQBO7I9UyT4L7svcMD+HUQ2BqHoaQe4
191
-y20C59dPr9Dpcz8DZkdLsBV6YKF6Ieb3iGk8oRLMWNaUqPa8f1BGgxAkvPHcqDjT
192
-x4xRnjgTRRRlZvRtALHMUkIChgxDOhoEzKpGiqnX7HtMJfrhV6h0PAXNA4h9Kjv5
193
-5fhJ08Rz7mmZmtH5JxTK5XTquo59sihSajR4bSjZbbkQ1uLkeFlY3eli3xdQ7Nrf
194
-fQIDAQAB
195
------END PUBLIC KEY-----`
196
-
197
-const privateKey = `-----BEGIN RSA PRIVATE KEY-----
198
-MIIEogIBAAKCAQEAxSWmu7trWKAwDFjiCN2DTk2jj2sgcr/CMlI4cSSiIOHrXCFx
199
-P1I8i9PvQkd4hasXQrLbT5WXKrRGv1HKUKabb9ead+kD0kxk7i2bFYvKX43oq66I
200
-W0mOLTQBO7I9UyT4L7svcMD+HUQ2BqHoaQe4y20C59dPr9Dpcz8DZkdLsBV6YKF6
201
-Ieb3iGk8oRLMWNaUqPa8f1BGgxAkvPHcqDjTx4xRnjgTRRRlZvRtALHMUkIChgxD
202
-OhoEzKpGiqnX7HtMJfrhV6h0PAXNA4h9Kjv55fhJ08Rz7mmZmtH5JxTK5XTquo59
203
-sihSajR4bSjZbbkQ1uLkeFlY3eli3xdQ7NrffQIDAQABAoIBAAkN+6RvrTR61voa
204
-Mvd5RQiZpEN4Bht/Fyo8gH8h0Zh1B9xJZOwlmMZLS5fdtHlfLEhR8qSrGDBL61vq
205
-I8KkhEsUufF78EL+YzxVN+Q7cWYGHIOWFokqza7hzpSxUQO6lPOMQ1eIZaNueJTB
206
-Zu07/47ISPPg/bXzgGVcpYlTCPTjUwKjtfyMqvX9AD7fIyYRm6zfE7EHj1J2sBFt
207
-Yz1OGELg6HfJwXfpnPfBvftD0hWGzJ78Bp71fPJe6n5gnqmSqRvrcXNWFnH/yqkN
208
-d6vPIxD6Z3LjvyZpkA7JillLva2L/zcIFhg4HZvQnWd8/PpDnUDonu36hcj4SC5j
209
-W4aVPLkCgYEA4XzNKWxqYcajzFGZeSxlRHupSAl2MT7Cc5085MmE7dd31wK2T8O4
210
-n7N4bkm/rjTbX85NsfWdKtWb6mpp8W3VlLP0rp4a/12OicVOkg4pv9LZDmY0sRlE
211
-YuDJk1FeCZ50UrwTZI3rZ9IhZHhkgVA6uWAs7tYndONkxNHG0pjqs4sCgYEA39MZ
212
-JwMqo3qsPntpgP940cCLflEsjS9hYNO3+Sv8Dq3P0HLVhBYajJnotf8VuU0fsQZG
213
-grmtVn1yThFbMq7X1oY4F0XBA+paSiU18c4YyUnwax2u4sw9U/Q9tmQUZad5+ueT
214
-qriMBwGv+ewO+nQxqvAsMUmemrVzrfwA5Oct+hcCgYAfiyXoNZJsOy2O15twqBVC
215
-j0oPGcO+/9iT89sg5lACNbI+EdMPNYIOVTzzsL1v0VUfAe08h++Enn1BPcG0VHkc
216
-ZFBGXTfJoXzfKQrkw7ZzbzuOGB4m6DH44xlP0oIlNlVvfX/5ASF9VJf3RiBJNsAA
217
-TsP6ZVr/rw/ZuL7nlxy+IQKBgDhL/HOXlE3yOQiuOec8WsNHTs7C1BXe6PtVxVxi
218
-988pYK/pclL6zEq5G5NLSceF4obAMVQIJ9UtUGbabrncyGUo9UrFPLsjYvprSZo8
219
-YHegpVwL50UcYgCP2kXZ/ldjPIcjYDz8lhvdDMor2cidGTEJn9P11HLNWP9V91Ob
220
-4jCZAoGAPNRSC5cC8iP/9j+s2/kdkfWJiNaolPYAUrmrkL6H39PYYZM5tnhaIYJV
221
-Oh9AgABamU0eb3p3vXTISClVgV7ifq1HyZ7BSUhMfaY2Jk/s3sUHCWFxPZe9sgEG
222
-KinIY/373KIkIV/5g4h2v1w330IWcfptxKcY/Er3DJr38f695GE=
223
------END RSA PRIVATE KEY-----`
224
-
225
-func sign(privatePEM string, source []byte, t *testing.T) []byte {
226
- block, _ := pem.Decode([]byte(privatePEM))
227
- if block == nil {
228
- t.Fatalf("Failed to parse private key PEM")
229
- }
230
-
231
- priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
232
- if err != nil {
233
- t.Fatalf("Failed to parse private key DER")
234
- }
235
-
236
- checksum, err := ChecksumForBytes(source)
237
- if err != nil {
238
- t.Fatalf("Failed to make checksum")
239
- }
240
-
241
- sig, err := rsa.SignPKCS1v15(rand.Reader, priv, crypto.SHA256, checksum)
242
- if err != nil {
243
- t.Fatalf("Failed to sign: %v", sig)
244
- }
245
-
246
- return sig
247
-}
248
-
249
-func TestVerifySignature(t *testing.T) {
250
- t.Parallel()
251
-
252
- fName := "TestVerifySignature"
253
- defer cleanup(fName)
254
- writeOldFile(fName, t)
255
-
256
- up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey))
257
- if err != nil {
258
- t.Fatalf("Could not parse public key: %v", err)
259
- }
260
-
261
- signature := sign(privateKey, newFile, t)
262
- err, _ = up.VerifySignature(signature).FromStream(bytes.NewReader(newFile))
263
- validateUpdate(fName, err, t)
264
-}
265
-
266
-func TestVerifyFailBadSignature(t *testing.T) {
267
- t.Parallel()
268
-
269
- fName := "TestVerifyFailBadSignature"
270
- defer cleanup(fName)
271
- writeOldFile(fName, t)
272
-
273
- up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey))
274
- if err != nil {
275
- t.Fatalf("Could not parse public key: %v", err)
276
- }
277
-
278
- badSig := []byte{0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA}
279
- err, _ = up.VerifySignature(badSig).FromStream(bytes.NewReader(newFile))
280
- if err == nil {
281
- t.Fatalf("Did not fail with bad signature")
282
- }
283
-}
284
-
285
-func TestVerifyFailNoSignature(t *testing.T) {
286
- t.Parallel()
287
-
288
- fName := "TestVerifySignatureWithPEM"
289
- defer cleanup(fName)
290
- writeOldFile(fName, t)
291
-
292
- up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey))
293
- if err != nil {
294
- t.Fatalf("Could not parse public key: %v", err)
295
- }
296
-
297
- err, _ = up.VerifySignature([]byte{}).FromStream(bytes.NewReader(newFile))
298
- if err == nil {
299
- t.Fatalf("Did not fail with empty signature")
300
- }
301
-}
302
-
303
-const wrongKey = `-----BEGIN RSA PRIVATE KEY-----
304
-MIIEpAIBAAKCAQEArKqjT+xOFJILe0CX7lKfQy52YwWLF9devYtLeUHTbPOueGLy
305
-6CjrXJBrWIxNBxRd53y4dtgiMqCX6Gmmvuy8HnfbBuJjR2mcdEYo8UDy+aSVBQ6T
306
-/ND7Fd7KSzOruEFFzl2QFnZ/SrW/nsXdGyuF8l+YIwjZJRyV6StZkZ4ydOzOqUk9
307
-FXTeIkhX/Q7/jTETw7L3wxMyLgJAlV3lxDsPkMjxymngtbAIjwEjLsVeU+Prcz2e
308
-Ww34SZQ8qwzAdXieuDPryMwEsCcgc5NAKJFNL8TppYGDXOHI7CRXqHfNiJq2R+kQ
309
-LdxRvmfx8/iu4xM2hBzk4uSDS6TTn2AnWBm+cQIDAQABAoIBAFp//aUwaCRj/9yU
310
-GI3zhEJEIgz4pNTUL3YNgnuFwvlCJ9o1kreYavRTRdBdiSoCxM1GE7FGy3XZsoVA
311
-iwNbNaaKj6RmGD8f3b8b3u3EaxXp66mA4JQMPO5TnZgY9xJWM+5cH9+GMGXKKStg
312
-7ekFwOkuraD/TEElYHWcIRAv6KZbc/YOIa6YDKi+1Gc7u0MeIvwqN7nwaBAoJKUE
313
-ZrJIfYKIViD/ZrCpgWN47C9x8w3ne7iiDrYoYct+0reC9LFlqwVBtDnyVx/q3upW
314
-zzczbNQagu3w0QgprDGhy0ZhDNxuylV3XBWTB+xBrFQgz6rD3LzUPywlbt0N7ZmD
315
-936MVSECgYEA1IElCahF/+hC/OxFgy98DubAUDGmrvxWeZF3bvTseWZQp/gzxVS+
316
-SYumYyd2Ysx5+UjXQlVgR6BbDG13+DpSpZm6+MeWHBAR+KA2qCg009SDFv7l26/d
317
-xMT7lvIWz7ckQDb/+jvhF9HL2llyTN1Zex+n3XBeAMKNrPaubdEBFsUCgYEA0AIO
318
-tZMtzOpioAR1lGbwIguq04msDdrJNaY2TKrLeviJuQUw94fgL+3ULAPsiyxaU/Gv
319
-vln11R7aIp1SJ09T2UoFRbty+6SGRC56+Wh0pn5VnAi7aT6qdkYWhEjhqRHuXosf
320
-PYboXBuMwA0FBUTxWQL/lux2PZgvBkniYh5jI70CgYEAk9KmhhpFX2gdOT3OeRxO
321
-CzufaemwDqfAK97yGwBLg4OV9dJliQ6TNCvt+amY489jxfJSs3UafZjh3TpFKyq/
322
-FS1kb+y+0hSnu7EPdFhLr1N0QUndcb3b4iY48V7EWYgHspfP5y1CPsSVLvXr2eZc
323
-eZaiuhqReavczAXpfsDWJhUCgYEAwmUp2gfyhc+G3IVOXaLWSPseaxP+9/PAl6L+
324
-nCgCgqpEC+YOHUee/SwHXhtMtcR9pnX5CKyKUuLCehcM8C/y7N+AjerhSsw3rwDB
325
-bNVyLydiWrDOdU1bga1+3aI/QwK/AxyB1b5+6ZXVtKZ2SrZj2Aw1UZcr6eSQDhB+
326
-wbQkcwECgYBF13FMA6OOon992t9H3I+4KDgmz6G6mz3bVXSoFWfO1p/yXP04BzJl
327
-jtLFvFVTZdMs2o/wTd4SL6gYjx9mlOWwM8FblmjfiNSUVIyye33fRntEAr1n+FYI
328
-Xhv6aVnNdaGehGIqQxXFoGyiJxG3RYNkSwaTOamxY1V+ceLuO26n2Q==
329
------END RSA PRIVATE KEY-----`
330
-
331
-func TestVerifyFailWrongSignature(t *testing.T) {
332
- t.Parallel()
333
-
334
- fName := "TestVerifyFailWrongSignature"
335
- defer cleanup(fName)
336
- writeOldFile(fName, t)
337
-
338
- up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey))
339
- if err != nil {
340
- t.Fatalf("Could not parse public key: %v", err)
341
- }
342
-
343
- signature := sign(wrongKey, newFile, t)
344
- err, _ = up.VerifySignature(signature).FromStream(bytes.NewReader(newFile))
345
- if err == nil {
346
- t.Fatalf("Verified an update that was signed by an untrusted key!")
347
- }
348
-}
349
-
350
-func TestSignatureButNoPublicKey(t *testing.T) {
351
- t.Parallel()
352
-
353
- fName := "TestSignatureButNoPublicKey"
354
- defer cleanup(fName)
355
- writeOldFile(fName, t)
356
-
357
- sig := sign(privateKey, newFile, t)
358
- err, _ := New().Target(fName).VerifySignature(sig).FromStream(bytes.NewReader(newFile))
359
- if err == nil {
360
- t.Fatalf("Allowed an update with a signautre verification when no public key was specified!")
361
- }
362
-}
363
-
364
-func TestPublicKeyButNoSignature(t *testing.T) {
365
- t.Parallel()
366
-
367
- fName := "TestPublicKeyButNoSignature"
368
- defer cleanup(fName)
369
- writeOldFile(fName, t)
370
-
371
- up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey))
372
- if err != nil {
373
- t.Fatalf("Could not parse public key: %v", err)
374
- }
375
-
376
- err, _ = up.FromStream(bytes.NewReader(newFile))
377
- if err == nil {
378
- t.Fatalf("Allowed an update with no signautre when a public key was specified!")
379
- }
380
-}
Godeps/_workspace/src/github.com/kardianos/osext/LICENSE
deleted
-27
@@ -1,27 +0,0 @@
1
-Copyright (c) 2012 The Go Authors. 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.
Godeps/_workspace/src/github.com/kardianos/osext/README.md
deleted
-14
@@ -1,14 +0,0 @@
1
-### Extensions to the "os" package.
2
-
3
-## Find the current Executable and ExecutableFolder.
4
-
5
-There is sometimes utility in finding the current executable file
6
-that is running. This can be used for upgrading the current executable
7
-or finding resources located relative to the executable file.
8
-
9
-Multi-platform and supports:
10
- * Linux
11
- * OS X
12
- * Windows
13
- * Plan 9
14
- * BSDs.
Godeps/_workspace/src/github.com/kardianos/osext/osext.go
deleted
-27
@@ -1,27 +0,0 @@
1
-// Copyright 2012 The Go Authors. 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
-// Extensions to the standard "os" package.
6
-package osext
7
-
8
-import "path/filepath"
9
-
10
-// Executable returns an absolute path that can be used to
11
-// re-invoke the current program.
12
-// It may not be valid after the current program exits.
13
-func Executable() (string, error) {
14
- p, err := executable()
15
- return filepath.Clean(p), err
16
-}
17
-
18
-// Returns same path as Executable, returns just the folder
19
-// path. Excludes the executable name.
20
-func ExecutableFolder() (string, error) {
21
- p, err := Executable()
22
- if err != nil {
23
- return "", err
24
- }
25
- folder, _ := filepath.Split(p)
26
- return folder, nil
27
-}
Godeps/_workspace/src/github.com/kardianos/osext/osext_plan9.go
deleted
-20
@@ -1,20 +0,0 @@
1
-// Copyright 2012 The Go Authors. 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 osext
6
-
7
-import (
8
- "os"
9
- "strconv"
10
- "syscall"
11
-)
12
-
13
-func executable() (string, error) {
14
- f, err := os.Open("/proc/" + strconv.Itoa(os.Getpid()) + "/text")
15
- if err != nil {
16
- return "", err
17
- }
18
- defer f.Close()
19
- return syscall.Fd2path(int(f.Fd()))
20
-}
Godeps/_workspace/src/github.com/kardianos/osext/osext_procfs.go
deleted
-36
@@ -1,36 +0,0 @@
1
-// Copyright 2012 The Go Authors. 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
-// +build linux netbsd openbsd solaris dragonfly
6
-
7
-package osext
8
-
9
-import (
10
- "errors"
11
- "fmt"
12
- "os"
13
- "runtime"
14
- "strings"
15
-)
16
-
17
-func executable() (string, error) {
18
- switch runtime.GOOS {
19
- case "linux":
20
- const deletedTag = " (deleted)"
21
- execpath, err := os.Readlink("/proc/self/exe")
22
- if err != nil {
23
- return execpath, err
24
- }
25
- execpath = strings.TrimSuffix(execpath, deletedTag)
26
- execpath = strings.TrimPrefix(execpath, deletedTag)
27
- return execpath, nil
28
- case "netbsd":
29
- return os.Readlink("/proc/curproc/exe")
30
- case "openbsd", "dragonfly":
31
- return os.Readlink("/proc/curproc/file")
32
- case "solaris":
33
- return os.Readlink(fmt.Sprintf("/proc/%d/path/a.out", os.Getpid()))
34
- }
35
- return "", errors.New("ExecPath not implemented for " + runtime.GOOS)
36
-}
Godeps/_workspace/src/github.com/kardianos/osext/osext_sysctl.go
deleted
-79
@@ -1,79 +0,0 @@
1
-// Copyright 2012 The Go Authors. 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
-// +build darwin freebsd
6
-
7
-package osext
8
-
9
-import (
10
- "os"
11
- "path/filepath"
12
- "runtime"
13
- "syscall"
14
- "unsafe"
15
-)
16
-
17
-var initCwd, initCwdErr = os.Getwd()
18
-
19
-func executable() (string, error) {
20
- var mib [4]int32
21
- switch runtime.GOOS {
22
- case "freebsd":
23
- mib = [4]int32{1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1}
24
- case "darwin":
25
- mib = [4]int32{1 /* CTL_KERN */, 38 /* KERN_PROCARGS */, int32(os.Getpid()), -1}
26
- }
27
-
28
- n := uintptr(0)
29
- // Get length.
30
- _, _, errNum := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0)
31
- if errNum != 0 {
32
- return "", errNum
33
- }
34
- if n == 0 { // This shouldn't happen.
35
- return "", nil
36
- }
37
- buf := make([]byte, n)
38
- _, _, errNum = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0)
39
- if errNum != 0 {
40
- return "", errNum
41
- }
42
- if n == 0 { // This shouldn't happen.
43
- return "", nil
44
- }
45
- for i, v := range buf {
46
- if v == 0 {
47
- buf = buf[:i]
48
- break
49
- }
50
- }
51
- var err error
52
- execPath := string(buf)
53
- // execPath will not be empty due to above checks.
54
- // Try to get the absolute path if the execPath is not rooted.
55
- if execPath[0] != '/' {
56
- execPath, err = getAbs(execPath)
57
- if err != nil {
58
- return execPath, err
59
- }
60
- }
61
- // For darwin KERN_PROCARGS may return the path to a symlink rather than the
62
- // actual executable.
63
- if runtime.GOOS == "darwin" {
64
- if execPath, err = filepath.EvalSymlinks(execPath); err != nil {
65
- return execPath, err
66
- }
67
- }
68
- return execPath, nil
69
-}
70
-
71
-func getAbs(execPath string) (string, error) {
72
- if initCwdErr != nil {
73
- return execPath, initCwdErr
74
- }
75
- // The execPath may begin with a "../" or a "./" so clean it first.
76
- // Join the two paths, trailing and starting slashes undetermined, so use
77
- // the generic Join function.
78
- return filepath.Join(initCwd, filepath.Clean(execPath)), nil
79
-}
Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go
deleted
-180
@@ -1,180 +0,0 @@
1
-// Copyright 2012 The Go Authors. 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
-// +build darwin linux freebsd netbsd windows
6
-
7
-package osext
8
-
9
-import (
10
- "bytes"
11
- "fmt"
12
- "io"
13
- "os"
14
- "os/exec"
15
- "path/filepath"
16
- "runtime"
17
- "testing"
18
-)
19
-
20
-const (
21
- executableEnvVar = "OSTEST_OUTPUT_EXECUTABLE"
22
-
23
- executableEnvValueMatch = "match"
24
- executableEnvValueDelete = "delete"
25
-)
26
-
27
-func TestExecutableMatch(t *testing.T) {
28
- ep, err := Executable()
29
- if err != nil {
30
- t.Fatalf("Executable failed: %v", err)
31
- }
32
-
33
- // fullpath to be of the form "dir/prog".
34
- dir := filepath.Dir(filepath.Dir(ep))
35
- fullpath, err := filepath.Rel(dir, ep)
36
- if err != nil {
37
- t.Fatalf("filepath.Rel: %v", err)
38
- }
39
- // Make child start with a relative program path.
40
- // Alter argv[0] for child to verify getting real path without argv[0].
41
- cmd := &exec.Cmd{
42
- Dir: dir,
43
- Path: fullpath,
44
- Env: []string{fmt.Sprintf("%s=%s", executableEnvVar, executableEnvValueMatch)},
45
- }
46
- out, err := cmd.CombinedOutput()
47
- if err != nil {
48
- t.Fatalf("exec(self) failed: %v", err)
49
- }
50
- outs := string(out)
51
- if !filepath.IsAbs(outs) {
52
- t.Fatalf("Child returned %q, want an absolute path", out)
53
- }
54
- if !sameFile(outs, ep) {
55
- t.Fatalf("Child returned %q, not the same file as %q", out, ep)
56
- }
57
-}
58
-
59
-func TestExecutableDelete(t *testing.T) {
60
- if runtime.GOOS != "linux" {
61
- t.Skip()
62
- }
63
- fpath, err := Executable()
64
- if err != nil {
65
- t.Fatalf("Executable failed: %v", err)
66
- }
67
-
68
- r, w := io.Pipe()
69
- stderrBuff := &bytes.Buffer{}
70
- stdoutBuff := &bytes.Buffer{}
71
- cmd := &exec.Cmd{
72
- Path: fpath,
73
- Env: []string{fmt.Sprintf("%s=%s", executableEnvVar, executableEnvValueDelete)},
74
- Stdin: r,
75
- Stderr: stderrBuff,
76
- Stdout: stdoutBuff,
77
- }
78
- err = cmd.Start()
79
- if err != nil {
80
- t.Fatalf("exec(self) start failed: %v", err)
81
- }
82
-
83
- tempPath := fpath + "_copy"
84
- _ = os.Remove(tempPath)
85
-
86
- err = copyFile(tempPath, fpath)
87
- if err != nil {
88
- t.Fatalf("copy file failed: %v", err)
89
- }
90
- err = os.Remove(fpath)
91
- if err != nil {
92
- t.Fatalf("remove running test file failed: %v", err)
93
- }
94
- err = os.Rename(tempPath, fpath)
95
- if err != nil {
96
- t.Fatalf("rename copy to previous name failed: %v", err)
97
- }
98
-
99
- w.Write([]byte{0})
100
- w.Close()
101
-
102
- err = cmd.Wait()
103
- if err != nil {
104
- t.Fatalf("exec wait failed: %v", err)
105
- }
106
-
107
- childPath := stderrBuff.String()
108
- if !filepath.IsAbs(childPath) {
109
- t.Fatalf("Child returned %q, want an absolute path", childPath)
110
- }
111
- if !sameFile(childPath, fpath) {
112
- t.Fatalf("Child returned %q, not the same file as %q", childPath, fpath)
113
- }
114
-}
115
-
116
-func sameFile(fn1, fn2 string) bool {
117
- fi1, err := os.Stat(fn1)
118
- if err != nil {
119
- return false
120
- }
121
- fi2, err := os.Stat(fn2)
122
- if err != nil {
123
- return false
124
- }
125
- return os.SameFile(fi1, fi2)
126
-}
127
-func copyFile(dest, src string) error {
128
- df, err := os.Create(dest)
129
- if err != nil {
130
- return err
131
- }
132
- defer df.Close()
133
-
134
- sf, err := os.Open(src)
135
- if err != nil {
136
- return err
137
- }
138
- defer sf.Close()
139
-
140
- _, err = io.Copy(df, sf)
141
- return err
142
-}
143
-
144
-func TestMain(m *testing.M) {
145
- env := os.Getenv(executableEnvVar)
146
- switch env {
147
- case "":
148
- os.Exit(m.Run())
149
- case executableEnvValueMatch:
150
- // First chdir to another path.
151
- dir := "/"
152
- if runtime.GOOS == "windows" {
153
- dir = filepath.VolumeName(".")
154
- }
155
- os.Chdir(dir)
156
- if ep, err := Executable(); err != nil {
157
- fmt.Fprint(os.Stderr, "ERROR: ", err)
158
- } else {
159
- fmt.Fprint(os.Stderr, ep)
160
- }
161
- case executableEnvValueDelete:
162
- bb := make([]byte, 1)
163
- var err error
164
- n, err := os.Stdin.Read(bb)
165
- if err != nil {
166
- fmt.Fprint(os.Stderr, "ERROR: ", err)
167
- os.Exit(2)
168
- }
169
- if n != 1 {
170
- fmt.Fprint(os.Stderr, "ERROR: n != 1, n == ", n)
171
- os.Exit(2)
172
- }
173
- if ep, err := Executable(); err != nil {
174
- fmt.Fprint(os.Stderr, "ERROR: ", err)
175
- } else {
176
- fmt.Fprint(os.Stderr, ep)
177
- }
178
- }
179
- os.Exit(0)
180
-}
Godeps/_workspace/src/github.com/kardianos/osext/osext_windows.go
deleted
-34
@@ -1,34 +0,0 @@
1
-// Copyright 2012 The Go Authors. 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 osext
6
-
7
-import (
8
- "syscall"
9
- "unicode/utf16"
10
- "unsafe"
11
-)
12
-
13
-var (
14
- kernel = syscall.MustLoadDLL("kernel32.dll")
15
- getModuleFileNameProc = kernel.MustFindProc("GetModuleFileNameW")
16
-)
17
-
18
-// GetModuleFileName() with hModule = NULL
19
-func executable() (exePath string, err error) {
20
- return getModuleFileName()
21
-}
22
-
23
-func getModuleFileName() (string, error) {
24
- var n uint32
25
- b := make([]uint16, syscall.MAX_PATH)
26
- size := uint32(len(b))
27
-
28
- r0, _, e1 := getModuleFileNameProc.Call(0, uintptr(unsafe.Pointer(&b[0])), uintptr(size))
29
- n = uint32(r0)
30
- if n == 0 {
31
- return "", e1
32
- }
33
- return string(utf16.Decode(b[0:n])), nil
34
-}
Godeps/_workspace/src/github.com/kr/binarydist/.gitignore
deleted
-1
@@ -1 +0,0 @@
1
-test.*
Godeps/_workspace/src/github.com/kr/binarydist/License
deleted
-22
@@ -1,22 +0,0 @@
1
-Copyright 2012 Keith Rarick
2
-
3
-Permission is hereby granted, free of charge, to any person
4
-obtaining a copy of this software and associated documentation
5
-files (the "Software"), to deal in the Software without
6
-restriction, including without limitation the rights to use,
7
-copy, modify, merge, publish, distribute, sublicense, and/or sell
8
-copies of the Software, and to permit persons to whom the
9
-Software is furnished to do so, subject to the following
10
-conditions:
11
-
12
-The above copyright notice and this permission notice shall be
13
-included in all copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
-OTHER DEALINGS IN THE SOFTWARE.
Godeps/_workspace/src/github.com/kr/binarydist/Readme.md
deleted
-7
@@ -1,7 +0,0 @@
1
-# binarydist
2
-
3
-Package binarydist implements binary diff and patch as described on
4
-<http://www.daemonology.net/bsdiff/>. It reads and writes files
5
-compatible with the tools there.
6
-
7
-Documentation at <http://go.pkgdoc.org/github.com/kr/binarydist>.
Godeps/_workspace/src/github.com/kr/binarydist/bzip2.go
deleted
-40
@@ -1,40 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "io"
5
- "os/exec"
6
-)
7
-
8
-type bzip2Writer struct {
9
- c *exec.Cmd
10
- w io.WriteCloser
11
-}
12
-
13
-func (w bzip2Writer) Write(b []byte) (int, error) {
14
- return w.w.Write(b)
15
-}
16
-
17
-func (w bzip2Writer) Close() error {
18
- if err := w.w.Close(); err != nil {
19
- return err
20
- }
21
- return w.c.Wait()
22
-}
23
-
24
-// Package compress/bzip2 implements only decompression,
25
-// so we'll fake it by running bzip2 in another process.
26
-func newBzip2Writer(w io.Writer) (wc io.WriteCloser, err error) {
27
- var bw bzip2Writer
28
- bw.c = exec.Command("bzip2", "-c")
29
- bw.c.Stdout = w
30
-
31
- if bw.w, err = bw.c.StdinPipe(); err != nil {
32
- return nil, err
33
- }
34
-
35
- if err = bw.c.Start(); err != nil {
36
- return nil, err
37
- }
38
-
39
- return bw, nil
40
-}
Godeps/_workspace/src/github.com/kr/binarydist/common_test.go
deleted
-93
@@ -1,93 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "crypto/rand"
5
- "io"
6
- "io/ioutil"
7
- "os"
8
-)
9
-
10
-func mustOpen(path string) *os.File {
11
- f, err := os.Open(path)
12
- if err != nil {
13
- panic(err)
14
- }
15
-
16
- return f
17
-}
18
-
19
-func mustReadAll(r io.Reader) []byte {
20
- b, err := ioutil.ReadAll(r)
21
- if err != nil {
22
- panic(err)
23
- }
24
- return b
25
-}
26
-
27
-func fileCmp(a, b *os.File) int64 {
28
- sa, err := a.Seek(0, 2)
29
- if err != nil {
30
- panic(err)
31
- }
32
-
33
- sb, err := b.Seek(0, 2)
34
- if err != nil {
35
- panic(err)
36
- }
37
-
38
- if sa != sb {
39
- return sa
40
- }
41
-
42
- _, err = a.Seek(0, 0)
43
- if err != nil {
44
- panic(err)
45
- }
46
-
47
- _, err = b.Seek(0, 0)
48
- if err != nil {
49
- panic(err)
50
- }
51
-
52
- pa, err := ioutil.ReadAll(a)
53
- if err != nil {
54
- panic(err)
55
- }
56
-
57
- pb, err := ioutil.ReadAll(b)
58
- if err != nil {
59
- panic(err)
60
- }
61
-
62
- for i := range pa {
63
- if pa[i] != pb[i] {
64
- return int64(i)
65
- }
66
- }
67
- return -1
68
-}
69
-
70
-func mustWriteRandFile(path string, size int) *os.File {
71
- p := make([]byte, size)
72
- _, err := rand.Read(p)
73
- if err != nil {
74
- panic(err)
75
- }
76
-
77
- f, err := os.Create(path)
78
- if err != nil {
79
- panic(err)
80
- }
81
-
82
- _, err = f.Write(p)
83
- if err != nil {
84
- panic(err)
85
- }
86
-
87
- _, err = f.Seek(0, 0)
88
- if err != nil {
89
- panic(err)
90
- }
91
-
92
- return f
93
-}
Godeps/_workspace/src/github.com/kr/binarydist/diff.go
deleted
-408
@@ -1,408 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "bytes"
5
- "encoding/binary"
6
- "io"
7
- "io/ioutil"
8
-)
9
-
10
-func swap(a []int, i, j int) { a[i], a[j] = a[j], a[i] }
11
-
12
-func split(I, V []int, start, length, h int) {
13
- var i, j, k, x, jj, kk int
14
-
15
- if length < 16 {
16
- for k = start; k < start+length; k += j {
17
- j = 1
18
- x = V[I[k]+h]
19
- for i = 1; k+i < start+length; i++ {
20
- if V[I[k+i]+h] < x {
21
- x = V[I[k+i]+h]
22
- j = 0
23
- }
24
- if V[I[k+i]+h] == x {
25
- swap(I, k+i, k+j)
26
- j++
27
- }
28
- }
29
- for i = 0; i < j; i++ {
30
- V[I[k+i]] = k + j - 1
31
- }
32
- if j == 1 {
33
- I[k] = -1
34
- }
35
- }
36
- return
37
- }
38
-
39
- x = V[I[start+length/2]+h]
40
- jj = 0
41
- kk = 0
42
- for i = start; i < start+length; i++ {
43
- if V[I[i]+h] < x {
44
- jj++
45
- }
46
- if V[I[i]+h] == x {
47
- kk++
48
- }
49
- }
50
- jj += start
51
- kk += jj
52
-
53
- i = start
54
- j = 0
55
- k = 0
56
- for i < jj {
57
- if V[I[i]+h] < x {
58
- i++
59
- } else if V[I[i]+h] == x {
60
- swap(I, i, jj+j)
61
- j++
62
- } else {
63
- swap(I, i, kk+k)
64
- k++
65
- }
66
- }
67
-
68
- for jj+j < kk {
69
- if V[I[jj+j]+h] == x {
70
- j++
71
- } else {
72
- swap(I, jj+j, kk+k)
73
- k++
74
- }
75
- }
76
-
77
- if jj > start {
78
- split(I, V, start, jj-start, h)
79
- }
80
-
81
- for i = 0; i < kk-jj; i++ {
82
- V[I[jj+i]] = kk - 1
83
- }
84
- if jj == kk-1 {
85
- I[jj] = -1
86
- }
87
-
88
- if start+length > kk {
89
- split(I, V, kk, start+length-kk, h)
90
- }
91
-}
92
-
93
-func qsufsort(obuf []byte) []int {
94
- var buckets [256]int
95
- var i, h int
96
- I := make([]int, len(obuf)+1)
97
- V := make([]int, len(obuf)+1)
98
-
99
- for _, c := range obuf {
100
- buckets[c]++
101
- }
102
- for i = 1; i < 256; i++ {
103
- buckets[i] += buckets[i-1]
104
- }
105
- copy(buckets[1:], buckets[:])
106
- buckets[0] = 0
107
-
108
- for i, c := range obuf {
109
- buckets[c]++
110
- I[buckets[c]] = i
111
- }
112
-
113
- I[0] = len(obuf)
114
- for i, c := range obuf {
115
- V[i] = buckets[c]
116
- }
117
-
118
- V[len(obuf)] = 0
119
- for i = 1; i < 256; i++ {
120
- if buckets[i] == buckets[i-1]+1 {
121
- I[buckets[i]] = -1
122
- }
123
- }
124
- I[0] = -1
125
-
126
- for h = 1; I[0] != -(len(obuf) + 1); h += h {
127
- var n int
128
- for i = 0; i < len(obuf)+1; {
129
- if I[i] < 0 {
130
- n -= I[i]
131
- i -= I[i]
132
- } else {
133
- if n != 0 {
134
- I[i-n] = -n
135
- }
136
- n = V[I[i]] + 1 - i
137
- split(I, V, i, n, h)
138
- i += n
139
- n = 0
140
- }
141
- }
142
- if n != 0 {
143
- I[i-n] = -n
144
- }
145
- }
146
-
147
- for i = 0; i < len(obuf)+1; i++ {
148
- I[V[i]] = i
149
- }
150
- return I
151
-}
152
-
153
-func matchlen(a, b []byte) (i int) {
154
- for i < len(a) && i < len(b) && a[i] == b[i] {
155
- i++
156
- }
157
- return i
158
-}
159
-
160
-func search(I []int, obuf, nbuf []byte, st, en int) (pos, n int) {
161
- if en-st < 2 {
162
- x := matchlen(obuf[I[st]:], nbuf)
163
- y := matchlen(obuf[I[en]:], nbuf)
164
-
165
- if x > y {
166
- return I[st], x
167
- } else {
168
- return I[en], y
169
- }
170
- }
171
-
172
- x := st + (en-st)/2
173
- if bytes.Compare(obuf[I[x]:], nbuf) < 0 {
174
- return search(I, obuf, nbuf, x, en)
175
- } else {
176
- return search(I, obuf, nbuf, st, x)
177
- }
178
- panic("unreached")
179
-}
180
-
181
-// Diff computes the difference between old and new, according to the bsdiff
182
-// algorithm, and writes the result to patch.
183
-func Diff(old, new io.Reader, patch io.Writer) error {
184
- obuf, err := ioutil.ReadAll(old)
185
- if err != nil {
186
- return err
187
- }
188
-
189
- nbuf, err := ioutil.ReadAll(new)
190
- if err != nil {
191
- return err
192
- }
193
-
194
- pbuf, err := diffBytes(obuf, nbuf)
195
- if err != nil {
196
- return err
197
- }
198
-
199
- _, err = patch.Write(pbuf)
200
- return err
201
-}
202
-
203
-func diffBytes(obuf, nbuf []byte) ([]byte, error) {
204
- var patch seekBuffer
205
- err := diff(obuf, nbuf, &patch)
206
- if err != nil {
207
- return nil, err
208
- }
209
- return patch.buf, nil
210
-}
211
-
212
-func diff(obuf, nbuf []byte, patch io.WriteSeeker) error {
213
- var lenf int
214
- I := qsufsort(obuf)
215
- db := make([]byte, len(nbuf))
216
- eb := make([]byte, len(nbuf))
217
- var dblen, eblen int
218
-
219
- var hdr header
220
- hdr.Magic = magic
221
- hdr.NewSize = int64(len(nbuf))
222
- err := binary.Write(patch, signMagLittleEndian{}, &hdr)
223
- if err != nil {
224
- return err
225
- }
226
-
227
- // Compute the differences, writing ctrl as we go
228
- pfbz2, err := newBzip2Writer(patch)
229
- if err != nil {
230
- return err
231
- }
232
- var scan, pos, length int
233
- var lastscan, lastpos, lastoffset int
234
- for scan < len(nbuf) {
235
- var oldscore int
236
- scan += length
237
- for scsc := scan; scan < len(nbuf); scan++ {
238
- pos, length = search(I, obuf, nbuf[scan:], 0, len(obuf))
239
-
240
- for ; scsc < scan+length; scsc++ {
241
- if scsc+lastoffset < len(obuf) &&
242
- obuf[scsc+lastoffset] == nbuf[scsc] {
243
- oldscore++
244
- }
245
- }
246
-
247
- if (length == oldscore && length != 0) || length > oldscore+8 {
248
- break
249
- }
250
-
251
- if scan+lastoffset < len(obuf) && obuf[scan+lastoffset] == nbuf[scan] {
252
- oldscore--
253
- }
254
- }
255
-
256
- if length != oldscore || scan == len(nbuf) {
257
- var s, Sf int
258
- lenf = 0
259
- for i := 0; lastscan+i < scan && lastpos+i < len(obuf); {
260
- if obuf[lastpos+i] == nbuf[lastscan+i] {
261
- s++
262
- }
263
- i++
264
- if s*2-i > Sf*2-lenf {
265
- Sf = s
266
- lenf = i
267
- }
268
- }
269
-
270
- lenb := 0
271
- if scan < len(nbuf) {
272
- var s, Sb int
273
- for i := 1; (scan >= lastscan+i) && (pos >= i); i++ {
274
- if obuf[pos-i] == nbuf[scan-i] {
275
- s++
276
- }
277
- if s*2-i > Sb*2-lenb {
278
- Sb = s
279
- lenb = i
280
- }
281
- }
282
- }
283
-
284
- if lastscan+lenf > scan-lenb {
285
- overlap := (lastscan + lenf) - (scan - lenb)
286
- s := 0
287
- Ss := 0
288
- lens := 0
289
- for i := 0; i < overlap; i++ {
290
- if nbuf[lastscan+lenf-overlap+i] == obuf[lastpos+lenf-overlap+i] {
291
- s++
292
- }
293
- if nbuf[scan-lenb+i] == obuf[pos-lenb+i] {
294
- s--
295
- }
296
- if s > Ss {
297
- Ss = s
298
- lens = i + 1
299
- }
300
- }
301
-
302
- lenf += lens - overlap
303
- lenb -= lens
304
- }
305
-
306
- for i := 0; i < lenf; i++ {
307
- db[dblen+i] = nbuf[lastscan+i] - obuf[lastpos+i]
308
- }
309
- for i := 0; i < (scan-lenb)-(lastscan+lenf); i++ {
310
- eb[eblen+i] = nbuf[lastscan+lenf+i]
311
- }
312
-
313
- dblen += lenf
314
- eblen += (scan - lenb) - (lastscan + lenf)
315
-
316
- err = binary.Write(pfbz2, signMagLittleEndian{}, int64(lenf))
317
- if err != nil {
318
- pfbz2.Close()
319
- return err
320
- }
321
-
322
- val := (scan - lenb) - (lastscan + lenf)
323
- err = binary.Write(pfbz2, signMagLittleEndian{}, int64(val))
324
- if err != nil {
325
- pfbz2.Close()
326
- return err
327
- }
328
-
329
- val = (pos - lenb) - (lastpos + lenf)
330
- err = binary.Write(pfbz2, signMagLittleEndian{}, int64(val))
331
- if err != nil {
332
- pfbz2.Close()
333
- return err
334
- }
335
-
336
- lastscan = scan - lenb
337
- lastpos = pos - lenb
338
- lastoffset = pos - scan
339
- }
340
- }
341
- err = pfbz2.Close()
342
- if err != nil {
343
- return err
344
- }
345
-
346
- // Compute size of compressed ctrl data
347
- l64, err := patch.Seek(0, 1)
348
- if err != nil {
349
- return err
350
- }
351
- hdr.CtrlLen = int64(l64 - 32)
352
-
353
- // Write compressed diff data
354
- pfbz2, err = newBzip2Writer(patch)
355
- if err != nil {
356
- return err
357
- }
358
- n, err := pfbz2.Write(db[:dblen])
359
- if err != nil {
360
- pfbz2.Close()
361
- return err
362
- }
363
- if n != dblen {
364
- pfbz2.Close()
365
- return io.ErrShortWrite
366
- }
367
- err = pfbz2.Close()
368
- if err != nil {
369
- return err
370
- }
371
-
372
- // Compute size of compressed diff data
373
- n64, err := patch.Seek(0, 1)
374
- if err != nil {
375
- return err
376
- }
377
- hdr.DiffLen = n64 - l64
378
-
379
- // Write compressed extra data
380
- pfbz2, err = newBzip2Writer(patch)
381
- if err != nil {
382
- return err
383
- }
384
- n, err = pfbz2.Write(eb[:eblen])
385
- if err != nil {
386
- pfbz2.Close()
387
- return err
388
- }
389
- if n != eblen {
390
- pfbz2.Close()
391
- return io.ErrShortWrite
392
- }
393
- err = pfbz2.Close()
394
- if err != nil {
395
- return err
396
- }
397
-
398
- // Seek to the beginning, write the header, and close the file
399
- _, err = patch.Seek(0, 0)
400
- if err != nil {
401
- return err
402
- }
403
- err = binary.Write(patch, signMagLittleEndian{}, &hdr)
404
- if err != nil {
405
- return err
406
- }
407
- return nil
408
-}
Godeps/_workspace/src/github.com/kr/binarydist/diff_test.go
deleted
-67
@@ -1,67 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "bytes"
5
- "io/ioutil"
6
- "os"
7
- "os/exec"
8
- "testing"
9
-)
10
-
11
-var diffT = []struct {
12
- old *os.File
13
- new *os.File
14
-}{
15
- {
16
- old: mustWriteRandFile("test.old", 1e3),
17
- new: mustWriteRandFile("test.new", 1e3),
18
- },
19
- {
20
- old: mustOpen("testdata/sample.old"),
21
- new: mustOpen("testdata/sample.new"),
22
- },
23
-}
24
-
25
-func TestDiff(t *testing.T) {
26
- for _, s := range diffT {
27
- got, err := ioutil.TempFile("/tmp", "bspatch.")
28
- if err != nil {
29
- panic(err)
30
- }
31
- os.Remove(got.Name())
32
-
33
- exp, err := ioutil.TempFile("/tmp", "bspatch.")
34
- if err != nil {
35
- panic(err)
36
- }
37
-
38
- cmd := exec.Command("bsdiff", s.old.Name(), s.new.Name(), exp.Name())
39
- cmd.Stdout = os.Stdout
40
- err = cmd.Run()
41
- os.Remove(exp.Name())
42
- if err != nil {
43
- panic(err)
44
- }
45
-
46
- err = Diff(s.old, s.new, got)
47
- if err != nil {
48
- t.Fatal("err", err)
49
- }
50
-
51
- _, err = got.Seek(0, 0)
52
- if err != nil {
53
- panic(err)
54
- }
55
- gotBuf := mustReadAll(got)
56
- expBuf := mustReadAll(exp)
57
-
58
- if !bytes.Equal(gotBuf, expBuf) {
59
- t.Fail()
60
- t.Logf("diff %s %s", s.old.Name(), s.new.Name())
61
- t.Logf("%s: len(got) = %d", got.Name(), len(gotBuf))
62
- t.Logf("%s: len(exp) = %d", exp.Name(), len(expBuf))
63
- i := matchlen(gotBuf, expBuf)
64
- t.Logf("produced different output at pos %d; %d != %d", i, gotBuf[i], expBuf[i])
65
- }
66
- }
67
-}
Godeps/_workspace/src/github.com/kr/binarydist/doc.go
deleted
-24
@@ -1,24 +0,0 @@
1
-// Package binarydist implements binary diff and patch as described on
2
-// http://www.daemonology.net/bsdiff/. It reads and writes files
3
-// compatible with the tools there.
4
-package binarydist
5
-
6
-var magic = [8]byte{'B', 'S', 'D', 'I', 'F', 'F', '4', '0'}
7
-
8
-// File format:
9
-// 0 8 "BSDIFF40"
10
-// 8 8 X
11
-// 16 8 Y
12
-// 24 8 sizeof(newfile)
13
-// 32 X bzip2(control block)
14
-// 32+X Y bzip2(diff block)
15
-// 32+X+Y ??? bzip2(extra block)
16
-// with control block a set of triples (x,y,z) meaning "add x bytes
17
-// from oldfile to x bytes from the diff block; copy y bytes from the
18
-// extra block; seek forwards in oldfile by z bytes".
19
-type header struct {
20
- Magic [8]byte
21
- CtrlLen int64
22
- DiffLen int64
23
- NewSize int64
24
-}
Godeps/_workspace/src/github.com/kr/binarydist/encoding.go
deleted
-53
@@ -1,53 +0,0 @@
1
-package binarydist
2
-
3
-// SignMagLittleEndian is the numeric encoding used by the bsdiff tools.
4
-// It implements binary.ByteOrder using a sign-magnitude format
5
-// and little-endian byte order. Only methods Uint64 and String
6
-// have been written; the rest panic.
7
-type signMagLittleEndian struct{}
8
-
9
-func (signMagLittleEndian) Uint16(b []byte) uint16 { panic("unimplemented") }
10
-
11
-func (signMagLittleEndian) PutUint16(b []byte, v uint16) { panic("unimplemented") }
12
-
13
-func (signMagLittleEndian) Uint32(b []byte) uint32 { panic("unimplemented") }
14
-
15
-func (signMagLittleEndian) PutUint32(b []byte, v uint32) { panic("unimplemented") }
16
-
17
-func (signMagLittleEndian) Uint64(b []byte) uint64 {
18
- y := int64(b[0]) |
19
- int64(b[1])<<8 |
20
- int64(b[2])<<16 |
21
- int64(b[3])<<24 |
22
- int64(b[4])<<32 |
23
- int64(b[5])<<40 |
24
- int64(b[6])<<48 |
25
- int64(b[7]&0x7f)<<56
26
-
27
- if b[7]&0x80 != 0 {
28
- y = -y
29
- }
30
- return uint64(y)
31
-}
32
-
33
-func (signMagLittleEndian) PutUint64(b []byte, v uint64) {
34
- x := int64(v)
35
- neg := x < 0
36
- if neg {
37
- x = -x
38
- }
39
-
40
- b[0] = byte(x)
41
- b[1] = byte(x >> 8)
42
- b[2] = byte(x >> 16)
43
- b[3] = byte(x >> 24)
44
- b[4] = byte(x >> 32)
45
- b[5] = byte(x >> 40)
46
- b[6] = byte(x >> 48)
47
- b[7] = byte(x >> 56)
48
- if neg {
49
- b[7] |= 0x80
50
- }
51
-}
52
-
53
-func (signMagLittleEndian) String() string { return "signMagLittleEndian" }
Godeps/_workspace/src/github.com/kr/binarydist/patch.go
deleted
-109
@@ -1,109 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "bytes"
5
- "compress/bzip2"
6
- "encoding/binary"
7
- "errors"
8
- "io"
9
- "io/ioutil"
10
-)
11
-
12
-var ErrCorrupt = errors.New("corrupt patch")
13
-
14
-// Patch applies patch to old, according to the bspatch algorithm,
15
-// and writes the result to new.
16
-func Patch(old io.Reader, new io.Writer, patch io.Reader) error {
17
- var hdr header
18
- err := binary.Read(patch, signMagLittleEndian{}, &hdr)
19
- if err != nil {
20
- return err
21
- }
22
- if hdr.Magic != magic {
23
- return ErrCorrupt
24
- }
25
- if hdr.CtrlLen < 0 || hdr.DiffLen < 0 || hdr.NewSize < 0 {
26
- return ErrCorrupt
27
- }
28
-
29
- ctrlbuf := make([]byte, hdr.CtrlLen)
30
- _, err = io.ReadFull(patch, ctrlbuf)
31
- if err != nil {
32
- return err
33
- }
34
- cpfbz2 := bzip2.NewReader(bytes.NewReader(ctrlbuf))
35
-
36
- diffbuf := make([]byte, hdr.DiffLen)
37
- _, err = io.ReadFull(patch, diffbuf)
38
- if err != nil {
39
- return err
40
- }
41
- dpfbz2 := bzip2.NewReader(bytes.NewReader(diffbuf))
42
-
43
- // The entire rest of the file is the extra block.
44
- epfbz2 := bzip2.NewReader(patch)
45
-
46
- obuf, err := ioutil.ReadAll(old)
47
- if err != nil {
48
- return err
49
- }
50
-
51
- nbuf := make([]byte, hdr.NewSize)
52
-
53
- var oldpos, newpos int64
54
- for newpos < hdr.NewSize {
55
- var ctrl struct{ Add, Copy, Seek int64 }
56
- err = binary.Read(cpfbz2, signMagLittleEndian{}, &ctrl)
57
- if err != nil {
58
- return err
59
- }
60
-
61
- // Sanity-check
62
- if newpos+ctrl.Add > hdr.NewSize {
63
- return ErrCorrupt
64
- }
65
-
66
- // Read diff string
67
- _, err = io.ReadFull(dpfbz2, nbuf[newpos:newpos+ctrl.Add])
68
- if err != nil {
69
- return ErrCorrupt
70
- }
71
-
72
- // Add old data to diff string
73
- for i := int64(0); i < ctrl.Add; i++ {
74
- if oldpos+i >= 0 && oldpos+i < int64(len(obuf)) {
75
- nbuf[newpos+i] += obuf[oldpos+i]
76
- }
77
- }
78
-
79
- // Adjust pointers
80
- newpos += ctrl.Add
81
- oldpos += ctrl.Add
82
-
83
- // Sanity-check
84
- if newpos+ctrl.Copy > hdr.NewSize {
85
- return ErrCorrupt
86
- }
87
-
88
- // Read extra string
89
- _, err = io.ReadFull(epfbz2, nbuf[newpos:newpos+ctrl.Copy])
90
- if err != nil {
91
- return ErrCorrupt
92
- }
93
-
94
- // Adjust pointers
95
- newpos += ctrl.Copy
96
- oldpos += ctrl.Seek
97
- }
98
-
99
- // Write the new file
100
- for len(nbuf) > 0 {
101
- n, err := new.Write(nbuf)
102
- if err != nil {
103
- return err
104
- }
105
- nbuf = nbuf[n:]
106
- }
107
-
108
- return nil
109
-}
Godeps/_workspace/src/github.com/kr/binarydist/patch_test.go
deleted
-62
@@ -1,62 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "io/ioutil"
5
- "os"
6
- "os/exec"
7
- "testing"
8
-)
9
-
10
-func TestPatch(t *testing.T) {
11
- mustWriteRandFile("test.old", 1e3)
12
- mustWriteRandFile("test.new", 1e3)
13
-
14
- got, err := ioutil.TempFile("/tmp", "bspatch.")
15
- if err != nil {
16
- panic(err)
17
- }
18
- os.Remove(got.Name())
19
-
20
- err = exec.Command("bsdiff", "test.old", "test.new", "test.patch").Run()
21
- if err != nil {
22
- panic(err)
23
- }
24
-
25
- err = Patch(mustOpen("test.old"), got, mustOpen("test.patch"))
26
- if err != nil {
27
- t.Fatal("err", err)
28
- }
29
-
30
- ref, err := got.Seek(0, 2)
31
- if err != nil {
32
- panic(err)
33
- }
34
-
35
- t.Logf("got %d bytes", ref)
36
- if n := fileCmp(got, mustOpen("test.new")); n > -1 {
37
- t.Fatalf("produced different output at pos %d", n)
38
- }
39
-}
40
-
41
-func TestPatchHk(t *testing.T) {
42
- got, err := ioutil.TempFile("/tmp", "bspatch.")
43
- if err != nil {
44
- panic(err)
45
- }
46
- os.Remove(got.Name())
47
-
48
- err = Patch(mustOpen("testdata/sample.old"), got, mustOpen("testdata/sample.patch"))
49
- if err != nil {
50
- t.Fatal("err", err)
51
- }
52
-
53
- ref, err := got.Seek(0, 2)
54
- if err != nil {
55
- panic(err)
56
- }
57
-
58
- t.Logf("got %d bytes", ref)
59
- if n := fileCmp(got, mustOpen("testdata/sample.new")); n > -1 {
60
- t.Fatalf("produced different output at pos %d", n)
61
- }
62
-}
Godeps/_workspace/src/github.com/kr/binarydist/seek.go
deleted
-43
@@ -1,43 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "errors"
5
-)
6
-
7
-type seekBuffer struct {
8
- buf []byte
9
- pos int
10
-}
11
-
12
-func (b *seekBuffer) Write(p []byte) (n int, err error) {
13
- n = copy(b.buf[b.pos:], p)
14
- if n == len(p) {
15
- b.pos += n
16
- return n, nil
17
- }
18
- b.buf = append(b.buf, p[n:]...)
19
- b.pos += len(p)
20
- return len(p), nil
21
-}
22
-
23
-func (b *seekBuffer) Seek(offset int64, whence int) (ret int64, err error) {
24
- var abs int64
25
- switch whence {
26
- case 0:
27
- abs = offset
28
- case 1:
29
- abs = int64(b.pos) + offset
30
- case 2:
31
- abs = int64(len(b.buf)) + offset
32
- default:
33
- return 0, errors.New("binarydist: invalid whence")
34
- }
35
- if abs < 0 {
36
- return 0, errors.New("binarydist: negative position")
37
- }
38
- if abs >= 1<<31 {
39
- return 0, errors.New("binarydist: position out of range")
40
- }
41
- b.pos = int(abs)
42
- return abs, nil
43
-}
Godeps/_workspace/src/github.com/kr/binarydist/sort_test.go
deleted
-33
@@ -1,33 +0,0 @@
1
-package binarydist
2
-
3
-import (
4
- "bytes"
5
- "crypto/rand"
6
- "testing"
7
-)
8
-
9
-var sortT = [][]byte{
10
- mustRandBytes(1000),
11
- mustReadAll(mustOpen("test.old")),
12
- []byte("abcdefabcdef"),
13
-}
14
-
15
-func TestQsufsort(t *testing.T) {
16
- for _, s := range sortT {
17
- I := qsufsort(s)
18
- for i := 1; i < len(I); i++ {
19
- if bytes.Compare(s[I[i-1]:], s[I[i]:]) > 0 {
20
- t.Fatalf("unsorted at %d", i)
21
- }
22
- }
23
- }
24
-}
25
-
26
-func mustRandBytes(n int) []byte {
27
- b := make([]byte, n)
28
- _, err := rand.Read(b)
29
- if err != nil {
30
- panic(err)
31
- }
32
- return b
33
-}
Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.new
Binary files a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.new and /dev/null differ
Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.old
Binary files a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.old and /dev/null differ
Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.patch
Binary files a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.patch and /dev/null differ
Godeps/_workspace/src/github.com/shirou/gopsutil/common/common.go
deleted
-209
@@ -1,209 +0,0 @@
1
-//
2
-// gopsutil is a port of psutil(http://pythonhosted.org/psutil/).
3
-// This covers these architectures.
4
-// - linux (amd64, arm)
5
-// - freebsd (amd64)
6
-// - windows (amd64)
7
-package common
8
-
9
-import (
10
- "bufio"
11
- "errors"
12
- "io/ioutil"
13
- "net/url"
14
- "os"
15
- "os/exec"
16
- "path"
17
- "reflect"
18
- "runtime"
19
- "strconv"
20
- "strings"
21
-)
22
-
23
-type Invoker interface {
24
- Command(string, ...string) ([]byte, error)
25
-}
26
-
27
-type Invoke struct{}
28
-
29
-func (i Invoke) Command(name string, arg ...string) ([]byte, error) {
30
- return exec.Command(name, arg...).Output()
31
-}
32
-
33
-type FakeInvoke struct {
34
- CommandExpectedDir string // CommandExpectedDir specifies dir which includes expected outputs.
35
- Suffix string // Suffix species expected file name suffix such as "fail"
36
- Error error // If Error specfied, return the error.
37
-}
38
-
39
-// Command in FakeInvoke returns from expected file if exists.
40
-func (i FakeInvoke) Command(name string, arg ...string) ([]byte, error) {
41
- if i.Error != nil {
42
- return []byte{}, i.Error
43
- }
44
-
45
- arch := runtime.GOOS
46
-
47
- fname := strings.Join(append([]string{name}, arg...), "")
48
- fname = url.QueryEscape(fname)
49
- var dir string
50
- if i.CommandExpectedDir == "" {
51
- dir = "expected"
52
- } else {
53
- dir = i.CommandExpectedDir
54
- }
55
- fpath := path.Join(dir, arch, fname)
56
- if i.Suffix != "" {
57
- fpath += "_" + i.Suffix
58
- }
59
- if PathExists(fpath) {
60
- return ioutil.ReadFile(fpath)
61
- } else {
62
- return exec.Command(name, arg...).Output()
63
- }
64
-}
65
-
66
-var NotImplementedError = errors.New("not implemented yet")
67
-
68
-// ReadLines reads contents from a file and splits them by new lines.
69
-// A convenience wrapper to ReadLinesOffsetN(filename, 0, -1).
70
-func ReadLines(filename string) ([]string, error) {
71
- return ReadLinesOffsetN(filename, 0, -1)
72
-}
73
-
74
-// ReadLines reads contents from file and splits them by new line.
75
-// The offset tells at which line number to start.
76
-// The count determines the number of lines to read (starting from offset):
77
-// n >= 0: at most n lines
78
-// n < 0: whole file
79
-func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
80
- f, err := os.Open(filename)
81
- if err != nil {
82
- return []string{""}, err
83
- }
84
- defer f.Close()
85
-
86
- var ret []string
87
-
88
- r := bufio.NewReader(f)
89
- for i := 0; i < n+int(offset) || n < 0; i++ {
90
- line, err := r.ReadString('\n')
91
- if err != nil {
92
- break
93
- }
94
- if i < int(offset) {
95
- continue
96
- }
97
- ret = append(ret, strings.Trim(line, "\n"))
98
- }
99
-
100
- return ret, nil
101
-}
102
-
103
-func IntToString(orig []int8) string {
104
- ret := make([]byte, len(orig))
105
- size := -1
106
- for i, o := range orig {
107
- if o == 0 {
108
- size = i
109
- break
110
- }
111
- ret[i] = byte(o)
112
- }
113
- if size == -1 {
114
- size = len(orig)
115
- }
116
-
117
- return string(ret[0:size])
118
-}
119
-
120
-func ByteToString(orig []byte) string {
121
- n := -1
122
- l := -1
123
- for i, b := range orig {
124
- // skip left side null
125
- if l == -1 && b == 0 {
126
- continue
127
- }
128
- if l == -1 {
129
- l = i
130
- }
131
-
132
- if b == 0 {
133
- break
134
- }
135
- n = i + 1
136
- }
137
- if n == -1 {
138
- return string(orig)
139
- }
140
- return string(orig[l:n])
141
-}
142
-
143
-// Parse to int32 without error
144
-func mustParseInt32(val string) int32 {
145
- vv, _ := strconv.ParseInt(val, 10, 32)
146
- return int32(vv)
147
-}
148
-
149
-// Parse to uint64 without error
150
-func mustParseUint64(val string) uint64 {
151
- vv, _ := strconv.ParseInt(val, 10, 64)
152
- return uint64(vv)
153
-}
154
-
155
-// Parse to Float64 without error
156
-func mustParseFloat64(val string) float64 {
157
- vv, _ := strconv.ParseFloat(val, 64)
158
- return vv
159
-}
160
-
161
-// StringsHas checks the target string slice containes src or not
162
-func StringsHas(target []string, src string) bool {
163
- for _, t := range target {
164
- if strings.TrimSpace(t) == src {
165
- return true
166
- }
167
- }
168
- return false
169
-}
170
-
171
-// StringsContains checks the src in any string of the target string slice
172
-func StringsContains(target []string, src string) bool {
173
- for _, t := range target {
174
- if strings.Contains(t, src) {
175
- return true
176
- }
177
- }
178
- return false
179
-}
180
-
181
-// get struct attributes.
182
-// This method is used only for debugging platform dependent code.
183
-func attributes(m interface{}) map[string]reflect.Type {
184
- typ := reflect.TypeOf(m)
185
- if typ.Kind() == reflect.Ptr {
186
- typ = typ.Elem()
187
- }
188
-
189
- attrs := make(map[string]reflect.Type)
190
- if typ.Kind() != reflect.Struct {
191
- return nil
192
- }
193
-
194
- for i := 0; i < typ.NumField(); i++ {
195
- p := typ.Field(i)
196
- if !p.Anonymous {
197
- attrs[p.Name] = p.Type
198
- }
199
- }
200
-
201
- return attrs
202
-}
203
-
204
-func PathExists(filename string) bool {
205
- if _, err := os.Stat(filename); err == nil {
206
- return true
207
- }
208
- return false
209
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_darwin.go
deleted
-60
@@ -1,60 +0,0 @@
1
-// +build darwin
2
-
3
-package common
4
-
5
-import (
6
- "os/exec"
7
- "strings"
8
- "syscall"
9
- "unsafe"
10
-)
11
-
12
-func DoSysctrl(mib string) ([]string, error) {
13
- out, err := exec.Command("/usr/sbin/sysctl", "-n", mib).Output()
14
- if err != nil {
15
- return []string{}, err
16
- }
17
- v := strings.Replace(string(out), "{ ", "", 1)
18
- v = strings.Replace(string(v), " }", "", 1)
19
- values := strings.Fields(string(v))
20
-
21
- return values, nil
22
-}
23
-
24
-func CallSyscall(mib []int32) ([]byte, uint64, error) {
25
- miblen := uint64(len(mib))
26
-
27
- // get required buffer size
28
- length := uint64(0)
29
- _, _, err := syscall.Syscall6(
30
- syscall.SYS___SYSCTL,
31
- uintptr(unsafe.Pointer(&mib[0])),
32
- uintptr(miblen),
33
- 0,
34
- uintptr(unsafe.Pointer(&length)),
35
- 0,
36
- 0)
37
- if err != 0 {
38
- var b []byte
39
- return b, length, err
40
- }
41
- if length == 0 {
42
- var b []byte
43
- return b, length, err
44
- }
45
- // get proc info itself
46
- buf := make([]byte, length)
47
- _, _, err = syscall.Syscall6(
48
- syscall.SYS___SYSCTL,
49
- uintptr(unsafe.Pointer(&mib[0])),
50
- uintptr(miblen),
51
- uintptr(unsafe.Pointer(&buf[0])),
52
- uintptr(unsafe.Pointer(&length)),
53
- 0,
54
- 0)
55
- if err != 0 {
56
- return buf, length, err
57
- }
58
-
59
- return buf, length, nil
60
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_freebsd.go
deleted
-60
@@ -1,60 +0,0 @@
1
-// +build freebsd
2
-
3
-package common
4
-
5
-import (
6
- "syscall"
7
- "os/exec"
8
- "strings"
9
- "unsafe"
10
-)
11
-
12
-func DoSysctrl(mib string) ([]string, error) {
13
- out, err := exec.Command("/sbin/sysctl", "-n", mib).Output()
14
- if err != nil {
15
- return []string{}, err
16
- }
17
- v := strings.Replace(string(out), "{ ", "", 1)
18
- v = strings.Replace(string(v), " }", "", 1)
19
- values := strings.Fields(string(v))
20
-
21
- return values, nil
22
-}
23
-
24
-func CallSyscall(mib []int32) ([]byte, uint64, error) {
25
- miblen := uint64(len(mib))
26
-
27
- // get required buffer size
28
- length := uint64(0)
29
- _, _, err := syscall.Syscall6(
30
- syscall.SYS___SYSCTL,
31
- uintptr(unsafe.Pointer(&mib[0])),
32
- uintptr(miblen),
33
- 0,
34
- uintptr(unsafe.Pointer(&length)),
35
- 0,
36
- 0)
37
- if err != 0 {
38
- var b []byte
39
- return b, length, err
40
- }
41
- if length == 0 {
42
- var b []byte
43
- return b, length, err
44
- }
45
- // get proc info itself
46
- buf := make([]byte, length)
47
- _, _, err = syscall.Syscall6(
48
- syscall.SYS___SYSCTL,
49
- uintptr(unsafe.Pointer(&mib[0])),
50
- uintptr(miblen),
51
- uintptr(unsafe.Pointer(&buf[0])),
52
- uintptr(unsafe.Pointer(&length)),
53
- 0,
54
- 0)
55
- if err != 0 {
56
- return buf, length, err
57
- }
58
-
59
- return buf, length, nil
60
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_linux.go
deleted
-3
@@ -1,3 +0,0 @@
1
-// +build linux
2
-
3
-package common
Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_test.go
deleted
-90
@@ -1,90 +0,0 @@
1
-package common
2
-
3
-import (
4
- "fmt"
5
- "strings"
6
- "testing"
7
-)
8
-
9
-func TestReadlines(t *testing.T) {
10
- ret, err := ReadLines("common_test.go")
11
- if err != nil {
12
- t.Error(err)
13
- }
14
- if !strings.Contains(ret[0], "package common") {
15
- t.Error("could not read correctly")
16
- }
17
-}
18
-
19
-func TestReadLinesOffsetN(t *testing.T) {
20
- ret, err := ReadLinesOffsetN("common_test.go", 2, 1)
21
- if err != nil {
22
- t.Error(err)
23
- }
24
- fmt.Println(ret[0])
25
- if !strings.Contains(ret[0], `import (`) {
26
- t.Error("could not read correctly")
27
- }
28
-}
29
-
30
-func TestIntToString(t *testing.T) {
31
- src := []int8{65, 66, 67}
32
- dst := IntToString(src)
33
- if dst != "ABC" {
34
- t.Error("could not convert")
35
- }
36
-}
37
-func TestByteToString(t *testing.T) {
38
- src := []byte{65, 66, 67}
39
- dst := ByteToString(src)
40
- if dst != "ABC" {
41
- t.Error("could not convert")
42
- }
43
-
44
- src = []byte{0, 65, 66, 67}
45
- dst = ByteToString(src)
46
- if dst != "ABC" {
47
- t.Error("could not convert")
48
- }
49
-}
50
-
51
-func TestmustParseInt32(t *testing.T) {
52
- ret := mustParseInt32("11111")
53
- if ret != int32(11111) {
54
- t.Error("could not parse")
55
- }
56
-}
57
-func TestmustParseUint64(t *testing.T) {
58
- ret := mustParseUint64("11111")
59
- if ret != uint64(11111) {
60
- t.Error("could not parse")
61
- }
62
-}
63
-func TestmustParseFloat64(t *testing.T) {
64
- ret := mustParseFloat64("11111.11")
65
- if ret != float64(11111.11) {
66
- t.Error("could not parse")
67
- }
68
- ret = mustParseFloat64("11111")
69
- if ret != float64(11111) {
70
- t.Error("could not parse")
71
- }
72
-}
73
-func TestStringsContains(t *testing.T) {
74
- target, err := ReadLines("common_test.go")
75
- if err != nil {
76
- t.Error(err)
77
- }
78
- if !StringsContains(target, "func TestStringsContains(t *testing.T) {") {
79
- t.Error("cloud not test correctly")
80
- }
81
-}
82
-
83
-func TestPathExists(t *testing.T) {
84
- if !PathExists("common_test.go") {
85
- t.Error("exists but return not exists")
86
- }
87
- if PathExists("should_not_exists.go") {
88
- t.Error("not exists but return exists")
89
- }
90
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_unix.go
deleted
-40
@@ -1,40 +0,0 @@
1
-// +build linux freebsd darwin
2
-
3
-package common
4
-
5
-import (
6
- "os/exec"
7
- "strconv"
8
- "strings"
9
-)
10
-
11
-func CallLsof(invoke Invoker, pid int32, args ...string) ([]string, error) {
12
- var cmd []string
13
- if pid == 0 { // will get from all processes.
14
- cmd = []string{"-a", "-n", "-P"}
15
- } else {
16
- cmd = []string{"-a", "-n", "-P", "-p", strconv.Itoa(int(pid))}
17
- }
18
- cmd = append(cmd, args...)
19
- lsof, err := exec.LookPath("lsof")
20
- if err != nil {
21
- return []string{}, err
22
- }
23
- out, err := invoke.Command(lsof, cmd...)
24
- if err != nil {
25
- // if no pid found, lsof returnes code 1.
26
- if err.Error() == "exit status 1" && len(out) == 0 {
27
- return []string{}, nil
28
- }
29
- }
30
- lines := strings.Split(string(out), "\n")
31
-
32
- var ret []string
33
- for _, l := range lines[1:] {
34
- if len(l) == 0 {
35
- continue
36
- }
37
- ret = append(ret, l)
38
- }
39
- return ret, nil
40
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_windows.go
deleted
-110
@@ -1,110 +0,0 @@
1
-// +build windows
2
-
3
-package common
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-)
9
-
10
-// for double values
11
-type PDH_FMT_COUNTERVALUE_DOUBLE struct {
12
- CStatus uint32
13
- DoubleValue float64
14
-}
15
-
16
-// for 64 bit integer values
17
-type PDH_FMT_COUNTERVALUE_LARGE struct {
18
- CStatus uint32
19
- LargeValue int64
20
-}
21
-
22
-// for long values
23
-type PDH_FMT_COUNTERVALUE_LONG struct {
24
- CStatus uint32
25
- LongValue int32
26
- padding [4]byte
27
-}
28
-
29
-// windows system const
30
-const (
31
- ERROR_SUCCESS = 0
32
- ERROR_FILE_NOT_FOUND = 2
33
- DRIVE_REMOVABLE = 2
34
- DRIVE_FIXED = 3
35
- HKEY_LOCAL_MACHINE = 0x80000002
36
- RRF_RT_REG_SZ = 0x00000002
37
- RRF_RT_REG_DWORD = 0x00000010
38
- PDH_FMT_LONG = 0x00000100
39
- PDH_FMT_DOUBLE = 0x00000200
40
- PDH_FMT_LARGE = 0x00000400
41
- PDH_INVALID_DATA = 0xc0000bc6
42
- PDH_INVALID_HANDLE = 0xC0000bbc
43
- PDH_NO_DATA = 0x800007d5
44
-)
45
-
46
-var (
47
- Modkernel32 = syscall.NewLazyDLL("kernel32.dll")
48
- ModNt = syscall.NewLazyDLL("ntdll.dll")
49
- ModPdh = syscall.NewLazyDLL("pdh.dll")
50
-
51
- ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes")
52
- ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation")
53
- PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery")
54
- PdhAddCounter = ModPdh.NewProc("PdhAddCounterW")
55
- PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData")
56
- PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue")
57
- PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery")
58
-)
59
-
60
-type FILETIME struct {
61
- DwLowDateTime uint32
62
- DwHighDateTime uint32
63
-}
64
-
65
-// borrowed from net/interface_windows.go
66
-func BytePtrToString(p *uint8) string {
67
- a := (*[10000]uint8)(unsafe.Pointer(p))
68
- i := 0
69
- for a[i] != 0 {
70
- i++
71
- }
72
- return string(a[:i])
73
-}
74
-
75
-// CounterInfo
76
-// copied from https://github.com/mackerelio/mackerel-agent/
77
-type CounterInfo struct {
78
- PostName string
79
- CounterName string
80
- Counter syscall.Handle
81
-}
82
-
83
-// CreateQuery XXX
84
-// copied from https://github.com/mackerelio/mackerel-agent/
85
-func CreateQuery() (syscall.Handle, error) {
86
- var query syscall.Handle
87
- r, _, err := PdhOpenQuery.Call(0, 0, uintptr(unsafe.Pointer(&query)))
88
- if r != 0 {
89
- return 0, err
90
- }
91
- return query, nil
92
-}
93
-
94
-// CreateCounter XXX
95
-func CreateCounter(query syscall.Handle, pname, cname string) (*CounterInfo, error) {
96
- var counter syscall.Handle
97
- r, _, err := PdhAddCounter.Call(
98
- uintptr(query),
99
- uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(cname))),
100
- 0,
101
- uintptr(unsafe.Pointer(&counter)))
102
- if r != 0 {
103
- return nil, err
104
- }
105
- return &CounterInfo{
106
- PostName: pname,
107
- CounterName: cname,
108
- Counter: counter,
109
- }, nil
110
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/binary.go
deleted
-634
@@ -1,634 +0,0 @@
1
-// Copyright 2009 The Go Authors. 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 binary implements simple translation between numbers and byte
6
-// sequences and encoding and decoding of varints.
7
-//
8
-// Numbers are translated by reading and writing fixed-size values.
9
-// A fixed-size value is either a fixed-size arithmetic
10
-// type (int8, uint8, int16, float32, complex64, ...)
11
-// or an array or struct containing only fixed-size values.
12
-//
13
-// The varint functions encode and decode single integer values using
14
-// a variable-length encoding; smaller values require fewer bytes.
15
-// For a specification, see
16
-// http://code.google.com/apis/protocolbuffers/docs/encoding.html.
17
-//
18
-// This package favors simplicity over efficiency. Clients that require
19
-// high-performance serialization, especially for large data structures,
20
-// should look at more advanced solutions such as the encoding/gob
21
-// package or protocol buffers.
22
-package disk
23
-
24
-import (
25
- "errors"
26
- "io"
27
- "math"
28
- "reflect"
29
-)
30
-
31
-// A ByteOrder specifies how to convert byte sequences into
32
-// 16-, 32-, or 64-bit unsigned integers.
33
-type ByteOrder interface {
34
- Uint16([]byte) uint16
35
- Uint32([]byte) uint32
36
- Uint64([]byte) uint64
37
- PutUint16([]byte, uint16)
38
- PutUint32([]byte, uint32)
39
- PutUint64([]byte, uint64)
40
- String() string
41
-}
42
-
43
-// LittleEndian is the little-endian implementation of ByteOrder.
44
-var LittleEndian littleEndian
45
-
46
-// BigEndian is the big-endian implementation of ByteOrder.
47
-var BigEndian bigEndian
48
-
49
-type littleEndian struct{}
50
-
51
-func (littleEndian) Uint16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 }
52
-
53
-func (littleEndian) PutUint16(b []byte, v uint16) {
54
- b[0] = byte(v)
55
- b[1] = byte(v >> 8)
56
-}
57
-
58
-func (littleEndian) Uint32(b []byte) uint32 {
59
- return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
60
-}
61
-
62
-func (littleEndian) PutUint32(b []byte, v uint32) {
63
- b[0] = byte(v)
64
- b[1] = byte(v >> 8)
65
- b[2] = byte(v >> 16)
66
- b[3] = byte(v >> 24)
67
-}
68
-
69
-func (littleEndian) Uint64(b []byte) uint64 {
70
- return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
71
- uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
72
-}
73
-
74
-func (littleEndian) PutUint64(b []byte, v uint64) {
75
- b[0] = byte(v)
76
- b[1] = byte(v >> 8)
77
- b[2] = byte(v >> 16)
78
- b[3] = byte(v >> 24)
79
- b[4] = byte(v >> 32)
80
- b[5] = byte(v >> 40)
81
- b[6] = byte(v >> 48)
82
- b[7] = byte(v >> 56)
83
-}
84
-
85
-func (littleEndian) String() string { return "LittleEndian" }
86
-
87
-func (littleEndian) GoString() string { return "binary.LittleEndian" }
88
-
89
-type bigEndian struct{}
90
-
91
-func (bigEndian) Uint16(b []byte) uint16 { return uint16(b[1]) | uint16(b[0])<<8 }
92
-
93
-func (bigEndian) PutUint16(b []byte, v uint16) {
94
- b[0] = byte(v >> 8)
95
- b[1] = byte(v)
96
-}
97
-
98
-func (bigEndian) Uint32(b []byte) uint32 {
99
- return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
100
-}
101
-
102
-func (bigEndian) PutUint32(b []byte, v uint32) {
103
- b[0] = byte(v >> 24)
104
- b[1] = byte(v >> 16)
105
- b[2] = byte(v >> 8)
106
- b[3] = byte(v)
107
-}
108
-
109
-func (bigEndian) Uint64(b []byte) uint64 {
110
- return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
111
- uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
112
-}
113
-
114
-func (bigEndian) PutUint64(b []byte, v uint64) {
115
- b[0] = byte(v >> 56)
116
- b[1] = byte(v >> 48)
117
- b[2] = byte(v >> 40)
118
- b[3] = byte(v >> 32)
119
- b[4] = byte(v >> 24)
120
- b[5] = byte(v >> 16)
121
- b[6] = byte(v >> 8)
122
- b[7] = byte(v)
123
-}
124
-
125
-func (bigEndian) String() string { return "BigEndian" }
126
-
127
-func (bigEndian) GoString() string { return "binary.BigEndian" }
128
-
129
-// Read reads structured binary data from r into data.
130
-// Data must be a pointer to a fixed-size value or a slice
131
-// of fixed-size values.
132
-// Bytes read from r are decoded using the specified byte order
133
-// and written to successive fields of the data.
134
-// When reading into structs, the field data for fields with
135
-// blank (_) field names is skipped; i.e., blank field names
136
-// may be used for padding.
137
-// When reading into a struct, all non-blank fields must be exported.
138
-func Read(r io.Reader, order ByteOrder, data interface{}) error {
139
- // Fast path for basic types and slices.
140
- if n := intDataSize(data); n != 0 {
141
- var b [8]byte
142
- var bs []byte
143
- if n > len(b) {
144
- bs = make([]byte, n)
145
- } else {
146
- bs = b[:n]
147
- }
148
- if _, err := io.ReadFull(r, bs); err != nil {
149
- return err
150
- }
151
- switch data := data.(type) {
152
- case *int8:
153
- *data = int8(b[0])
154
- case *uint8:
155
- *data = b[0]
156
- case *int16:
157
- *data = int16(order.Uint16(bs))
158
- case *uint16:
159
- *data = order.Uint16(bs)
160
- case *int32:
161
- *data = int32(order.Uint32(bs))
162
- case *uint32:
163
- *data = order.Uint32(bs)
164
- case *int64:
165
- *data = int64(order.Uint64(bs))
166
- case *uint64:
167
- *data = order.Uint64(bs)
168
- case []int8:
169
- for i, x := range bs { // Easier to loop over the input for 8-bit values.
170
- data[i] = int8(x)
171
- }
172
- case []uint8:
173
- copy(data, bs)
174
- case []int16:
175
- for i := range data {
176
- data[i] = int16(order.Uint16(bs[2*i:]))
177
- }
178
- case []uint16:
179
- for i := range data {
180
- data[i] = order.Uint16(bs[2*i:])
181
- }
182
- case []int32:
183
- for i := range data {
184
- data[i] = int32(order.Uint32(bs[4*i:]))
185
- }
186
- case []uint32:
187
- for i := range data {
188
- data[i] = order.Uint32(bs[4*i:])
189
- }
190
- case []int64:
191
- for i := range data {
192
- data[i] = int64(order.Uint64(bs[8*i:]))
193
- }
194
- case []uint64:
195
- for i := range data {
196
- data[i] = order.Uint64(bs[8*i:])
197
- }
198
- }
199
- return nil
200
- }
201
-
202
- // Fallback to reflect-based decoding.
203
- v := reflect.ValueOf(data)
204
- size := -1
205
- switch v.Kind() {
206
- case reflect.Ptr:
207
- v = v.Elem()
208
- size = dataSize(v)
209
- case reflect.Slice:
210
- size = dataSize(v)
211
- }
212
- if size < 0 {
213
- return errors.New("binary.Read: invalid type " + reflect.TypeOf(data).String())
214
- }
215
- d := &decoder{order: order, buf: make([]byte, size)}
216
- if _, err := io.ReadFull(r, d.buf); err != nil {
217
- return err
218
- }
219
- d.value(v)
220
- return nil
221
-}
222
-
223
-// Write writes the binary representation of data into w.
224
-// Data must be a fixed-size value or a slice of fixed-size
225
-// values, or a pointer to such data.
226
-// Bytes written to w are encoded using the specified byte order
227
-// and read from successive fields of the data.
228
-// When writing structs, zero values are written for fields
229
-// with blank (_) field names.
230
-func Write(w io.Writer, order ByteOrder, data interface{}) error {
231
- // Fast path for basic types and slices.
232
- if n := intDataSize(data); n != 0 {
233
- var b [8]byte
234
- var bs []byte
235
- if n > len(b) {
236
- bs = make([]byte, n)
237
- } else {
238
- bs = b[:n]
239
- }
240
- switch v := data.(type) {
241
- case *int8:
242
- bs = b[:1]
243
- b[0] = byte(*v)
244
- case int8:
245
- bs = b[:1]
246
- b[0] = byte(v)
247
- case []int8:
248
- for i, x := range v {
249
- bs[i] = byte(x)
250
- }
251
- case *uint8:
252
- bs = b[:1]
253
- b[0] = *v
254
- case uint8:
255
- bs = b[:1]
256
- b[0] = byte(v)
257
- case []uint8:
258
- bs = v
259
- case *int16:
260
- bs = b[:2]
261
- order.PutUint16(bs, uint16(*v))
262
- case int16:
263
- bs = b[:2]
264
- order.PutUint16(bs, uint16(v))
265
- case []int16:
266
- for i, x := range v {
267
- order.PutUint16(bs[2*i:], uint16(x))
268
- }
269
- case *uint16:
270
- bs = b[:2]
271
- order.PutUint16(bs, *v)
272
- case uint16:
273
- bs = b[:2]
274
- order.PutUint16(bs, v)
275
- case []uint16:
276
- for i, x := range v {
277
- order.PutUint16(bs[2*i:], x)
278
- }
279
- case *int32:
280
- bs = b[:4]
281
- order.PutUint32(bs, uint32(*v))
282
- case int32:
283
- bs = b[:4]
284
- order.PutUint32(bs, uint32(v))
285
- case []int32:
286
- for i, x := range v {
287
- order.PutUint32(bs[4*i:], uint32(x))
288
- }
289
- case *uint32:
290
- bs = b[:4]
291
- order.PutUint32(bs, *v)
292
- case uint32:
293
- bs = b[:4]
294
- order.PutUint32(bs, v)
295
- case []uint32:
296
- for i, x := range v {
297
- order.PutUint32(bs[4*i:], x)
298
- }
299
- case *int64:
300
- bs = b[:8]
301
- order.PutUint64(bs, uint64(*v))
302
- case int64:
303
- bs = b[:8]
304
- order.PutUint64(bs, uint64(v))
305
- case []int64:
306
- for i, x := range v {
307
- order.PutUint64(bs[8*i:], uint64(x))
308
- }
309
- case *uint64:
310
- bs = b[:8]
311
- order.PutUint64(bs, *v)
312
- case uint64:
313
- bs = b[:8]
314
- order.PutUint64(bs, v)
315
- case []uint64:
316
- for i, x := range v {
317
- order.PutUint64(bs[8*i:], x)
318
- }
319
- }
320
- _, err := w.Write(bs)
321
- return err
322
- }
323
-
324
- // Fallback to reflect-based encoding.
325
- v := reflect.Indirect(reflect.ValueOf(data))
326
- size := dataSize(v)
327
- if size < 0 {
328
- return errors.New("binary.Write: invalid type " + reflect.TypeOf(data).String())
329
- }
330
- buf := make([]byte, size)
331
- e := &encoder{order: order, buf: buf}
332
- e.value(v)
333
- _, err := w.Write(buf)
334
- return err
335
-}
336
-
337
-// Size returns how many bytes Write would generate to encode the value v, which
338
-// must be a fixed-size value or a slice of fixed-size values, or a pointer to such data.
339
-// If v is neither of these, Size returns -1.
340
-func Size(v interface{}) int {
341
- return dataSize(reflect.Indirect(reflect.ValueOf(v)))
342
-}
343
-
344
-// dataSize returns the number of bytes the actual data represented by v occupies in memory.
345
-// For compound structures, it sums the sizes of the elements. Thus, for instance, for a slice
346
-// it returns the length of the slice times the element size and does not count the memory
347
-// occupied by the header. If the type of v is not acceptable, dataSize returns -1.
348
-func dataSize(v reflect.Value) int {
349
- if v.Kind() == reflect.Slice {
350
- if s := sizeof(v.Type().Elem()); s >= 0 {
351
- return s * v.Len()
352
- }
353
- return -1
354
- }
355
- return sizeof(v.Type())
356
-}
357
-
358
-// sizeof returns the size >= 0 of variables for the given type or -1 if the type is not acceptable.
359
-func sizeof(t reflect.Type) int {
360
- switch t.Kind() {
361
- case reflect.Array:
362
- if s := sizeof(t.Elem()); s >= 0 {
363
- return s * t.Len()
364
- }
365
-
366
- case reflect.Struct:
367
- sum := 0
368
- for i, n := 0, t.NumField(); i < n; i++ {
369
- s := sizeof(t.Field(i).Type)
370
- if s < 0 {
371
- return -1
372
- }
373
- sum += s
374
- }
375
- return sum
376
-
377
- case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
378
- reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
379
- reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.Ptr:
380
- return int(t.Size())
381
- }
382
-
383
- return -1
384
-}
385
-
386
-type coder struct {
387
- order ByteOrder
388
- buf []byte
389
-}
390
-
391
-type decoder coder
392
-type encoder coder
393
-
394
-func (d *decoder) uint8() uint8 {
395
- x := d.buf[0]
396
- d.buf = d.buf[1:]
397
- return x
398
-}
399
-
400
-func (e *encoder) uint8(x uint8) {
401
- e.buf[0] = x
402
- e.buf = e.buf[1:]
403
-}
404
-
405
-func (d *decoder) uint16() uint16 {
406
- x := d.order.Uint16(d.buf[0:2])
407
- d.buf = d.buf[2:]
408
- return x
409
-}
410
-
411
-func (e *encoder) uint16(x uint16) {
412
- e.order.PutUint16(e.buf[0:2], x)
413
- e.buf = e.buf[2:]
414
-}
415
-
416
-func (d *decoder) uint32() uint32 {
417
- x := d.order.Uint32(d.buf[0:4])
418
- d.buf = d.buf[4:]
419
- return x
420
-}
421
-
422
-func (e *encoder) uint32(x uint32) {
423
- e.order.PutUint32(e.buf[0:4], x)
424
- e.buf = e.buf[4:]
425
-}
426
-
427
-func (d *decoder) uint64() uint64 {
428
- x := d.order.Uint64(d.buf[0:8])
429
- d.buf = d.buf[8:]
430
- return x
431
-}
432
-
433
-func (e *encoder) uint64(x uint64) {
434
- e.order.PutUint64(e.buf[0:8], x)
435
- e.buf = e.buf[8:]
436
-}
437
-
438
-func (d *decoder) int8() int8 { return int8(d.uint8()) }
439
-
440
-func (e *encoder) int8(x int8) { e.uint8(uint8(x)) }
441
-
442
-func (d *decoder) int16() int16 { return int16(d.uint16()) }
443
-
444
-func (e *encoder) int16(x int16) { e.uint16(uint16(x)) }
445
-
446
-func (d *decoder) int32() int32 { return int32(d.uint32()) }
447
-
448
-func (e *encoder) int32(x int32) { e.uint32(uint32(x)) }
449
-
450
-func (d *decoder) int64() int64 { return int64(d.uint64()) }
451
-
452
-func (e *encoder) int64(x int64) { e.uint64(uint64(x)) }
453
-
454
-func (d *decoder) value(v reflect.Value) {
455
- switch v.Kind() {
456
- case reflect.Array:
457
- l := v.Len()
458
- for i := 0; i < l; i++ {
459
- d.value(v.Index(i))
460
- }
461
-
462
- case reflect.Struct:
463
- t := v.Type()
464
- l := v.NumField()
465
- for i := 0; i < l; i++ {
466
- // Note: Calling v.CanSet() below is an optimization.
467
- // It would be sufficient to check the field name,
468
- // but creating the StructField info for each field is
469
- // costly (run "go test -bench=ReadStruct" and compare
470
- // results when making changes to this code).
471
- if v := v.Field(i); v.CanSet() || t.Field(i).Name != "_" {
472
- d.value(v)
473
- } else {
474
- d.skip(v)
475
- }
476
- }
477
-
478
- case reflect.Slice:
479
- l := v.Len()
480
- for i := 0; i < l; i++ {
481
- d.value(v.Index(i))
482
- }
483
-
484
- case reflect.Int8:
485
- v.SetInt(int64(d.int8()))
486
- case reflect.Int16:
487
- v.SetInt(int64(d.int16()))
488
- case reflect.Int32:
489
- v.SetInt(int64(d.int32()))
490
- case reflect.Int64:
491
- v.SetInt(d.int64())
492
-
493
- case reflect.Uint8:
494
- v.SetUint(uint64(d.uint8()))
495
- case reflect.Uint16:
496
- v.SetUint(uint64(d.uint16()))
497
- case reflect.Uint32:
498
- v.SetUint(uint64(d.uint32()))
499
- case reflect.Uint64:
500
- v.SetUint(d.uint64())
501
-
502
- case reflect.Float32:
503
- v.SetFloat(float64(math.Float32frombits(d.uint32())))
504
- case reflect.Float64:
505
- v.SetFloat(math.Float64frombits(d.uint64()))
506
-
507
- case reflect.Complex64:
508
- v.SetComplex(complex(
509
- float64(math.Float32frombits(d.uint32())),
510
- float64(math.Float32frombits(d.uint32())),
511
- ))
512
- case reflect.Complex128:
513
- v.SetComplex(complex(
514
- math.Float64frombits(d.uint64()),
515
- math.Float64frombits(d.uint64()),
516
- ))
517
- }
518
-}
519
-
520
-func (e *encoder) value(v reflect.Value) {
521
- switch v.Kind() {
522
- case reflect.Array:
523
- l := v.Len()
524
- for i := 0; i < l; i++ {
525
- e.value(v.Index(i))
526
- }
527
-
528
- case reflect.Struct:
529
- t := v.Type()
530
- l := v.NumField()
531
- for i := 0; i < l; i++ {
532
- // see comment for corresponding code in decoder.value()
533
- if v := v.Field(i); v.CanSet() || t.Field(i).Name != "_" {
534
- e.value(v)
535
- } else {
536
- e.skip(v)
537
- }
538
- }
539
-
540
- case reflect.Slice:
541
- l := v.Len()
542
- for i := 0; i < l; i++ {
543
- e.value(v.Index(i))
544
- }
545
-
546
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
547
- switch v.Type().Kind() {
548
- case reflect.Int8:
549
- e.int8(int8(v.Int()))
550
- case reflect.Int16:
551
- e.int16(int16(v.Int()))
552
- case reflect.Int32:
553
- e.int32(int32(v.Int()))
554
- case reflect.Int64:
555
- e.int64(v.Int())
556
- }
557
-
558
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
559
- switch v.Type().Kind() {
560
- case reflect.Uint8:
561
- e.uint8(uint8(v.Uint()))
562
- case reflect.Uint16:
563
- e.uint16(uint16(v.Uint()))
564
- case reflect.Uint32:
565
- e.uint32(uint32(v.Uint()))
566
- case reflect.Uint64:
567
- e.uint64(v.Uint())
568
- }
569
-
570
- case reflect.Float32, reflect.Float64:
571
- switch v.Type().Kind() {
572
- case reflect.Float32:
573
- e.uint32(math.Float32bits(float32(v.Float())))
574
- case reflect.Float64:
575
- e.uint64(math.Float64bits(v.Float()))
576
- }
577
-
578
- case reflect.Complex64, reflect.Complex128:
579
- switch v.Type().Kind() {
580
- case reflect.Complex64:
581
- x := v.Complex()
582
- e.uint32(math.Float32bits(float32(real(x))))
583
- e.uint32(math.Float32bits(float32(imag(x))))
584
- case reflect.Complex128:
585
- x := v.Complex()
586
- e.uint64(math.Float64bits(real(x)))
587
- e.uint64(math.Float64bits(imag(x)))
588
- }
589
- }
590
-}
591
-
592
-func (d *decoder) skip(v reflect.Value) {
593
- d.buf = d.buf[dataSize(v):]
594
-}
595
-
596
-func (e *encoder) skip(v reflect.Value) {
597
- n := dataSize(v)
598
- for i := range e.buf[0:n] {
599
- e.buf[i] = 0
600
- }
601
- e.buf = e.buf[n:]
602
-}
603
-
604
-// intDataSize returns the size of the data required to represent the data when encoded.
605
-// It returns zero if the type cannot be implemented by the fast path in Read or Write.
606
-func intDataSize(data interface{}) int {
607
- switch data := data.(type) {
608
- case int8, *int8, *uint8:
609
- return 1
610
- case []int8:
611
- return len(data)
612
- case []uint8:
613
- return len(data)
614
- case int16, *int16, *uint16:
615
- return 2
616
- case []int16:
617
- return 2 * len(data)
618
- case []uint16:
619
- return 2 * len(data)
620
- case int32, *int32, *uint32:
621
- return 4
622
- case []int32:
623
- return 4 * len(data)
624
- case []uint32:
625
- return 4 * len(data)
626
- case int64, *int64, *uint64:
627
- return 8
628
- case []int64:
629
- return 8 * len(data)
630
- case []uint64:
631
- return 8 * len(data)
632
- }
633
- return 0
634
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk.go
deleted
-52
@@ -1,52 +0,0 @@
1
-package disk
2
-
3
-import (
4
- "encoding/json"
5
-)
6
-
7
-type DiskUsageStat struct {
8
- Path string `json:"path"`
9
- Fstype string `json:"fstype"`
10
- Total uint64 `json:"total"`
11
- Free uint64 `json:"free"`
12
- Used uint64 `json:"used"`
13
- UsedPercent float64 `json:"used_percent"`
14
- InodesTotal uint64 `json:"inodes_total"`
15
- InodesUsed uint64 `json:"inodes_used"`
16
- InodesFree uint64 `json:"inodes_free"`
17
- InodesUsedPercent float64 `json:"inodes_used_percent"`
18
-}
19
-
20
-type DiskPartitionStat struct {
21
- Device string `json:"device"`
22
- Mountpoint string `json:"mountpoint"`
23
- Fstype string `json:"fstype"`
24
- Opts string `json:"opts"`
25
-}
26
-
27
-type DiskIOCountersStat struct {
28
- ReadCount uint64 `json:"read_count"`
29
- WriteCount uint64 `json:"write_count"`
30
- ReadBytes uint64 `json:"read_bytes"`
31
- WriteBytes uint64 `json:"write_bytes"`
32
- ReadTime uint64 `json:"read_time"`
33
- WriteTime uint64 `json:"write_time"`
34
- Name string `json:"name"`
35
- IoTime uint64 `json:"io_time"`
36
- SerialNumber string `json:"serial_number"`
37
-}
38
-
39
-func (d DiskUsageStat) String() string {
40
- s, _ := json.Marshal(d)
41
- return string(s)
42
-}
43
-
44
-func (d DiskPartitionStat) String() string {
45
- s, _ := json.Marshal(d)
46
- return string(s)
47
-}
48
-
49
-func (d DiskIOCountersStat) String() string {
50
- s, _ := json.Marshal(d)
51
- return string(s)
52
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin.go
deleted
-104
@@ -1,104 +0,0 @@
1
-// +build darwin
2
-
3
-package disk
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-
9
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
10
-)
11
-
12
-func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
13
- var ret []DiskPartitionStat
14
-
15
- count, err := Getfsstat(nil, MntWait)
16
- if err != nil {
17
- return ret, err
18
- }
19
- fs := make([]Statfs_t, count)
20
- _, err = Getfsstat(fs, MntWait)
21
- for _, stat := range fs {
22
- opts := "rw"
23
- if stat.Flags&MntReadOnly != 0 {
24
- opts = "ro"
25
- }
26
- if stat.Flags&MntSynchronous != 0 {
27
- opts += ",sync"
28
- }
29
- if stat.Flags&MntNoExec != 0 {
30
- opts += ",noexec"
31
- }
32
- if stat.Flags&MntNoSuid != 0 {
33
- opts += ",nosuid"
34
- }
35
- if stat.Flags&MntUnion != 0 {
36
- opts += ",union"
37
- }
38
- if stat.Flags&MntAsync != 0 {
39
- opts += ",async"
40
- }
41
- if stat.Flags&MntSuidDir != 0 {
42
- opts += ",suiddir"
43
- }
44
- if stat.Flags&MntSoftDep != 0 {
45
- opts += ",softdep"
46
- }
47
- if stat.Flags&MntNoSymFollow != 0 {
48
- opts += ",nosymfollow"
49
- }
50
- if stat.Flags&MntGEOMJournal != 0 {
51
- opts += ",gjounalc"
52
- }
53
- if stat.Flags&MntMultilabel != 0 {
54
- opts += ",multilabel"
55
- }
56
- if stat.Flags&MntACLs != 0 {
57
- opts += ",acls"
58
- }
59
- if stat.Flags&MntNoATime != 0 {
60
- opts += ",noattime"
61
- }
62
- if stat.Flags&MntClusterRead != 0 {
63
- opts += ",nocluster"
64
- }
65
- if stat.Flags&MntClusterWrite != 0 {
66
- opts += ",noclusterw"
67
- }
68
- if stat.Flags&MntNFS4ACLs != 0 {
69
- opts += ",nfs4acls"
70
- }
71
- d := DiskPartitionStat{
72
- Device: common.IntToString(stat.Mntfromname[:]),
73
- Mountpoint: common.IntToString(stat.Mntonname[:]),
74
- Fstype: common.IntToString(stat.Fstypename[:]),
75
- Opts: opts,
76
- }
77
- ret = append(ret, d)
78
- }
79
-
80
- return ret, nil
81
-}
82
-
83
-func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
84
- return nil, common.NotImplementedError
85
-}
86
-
87
-func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
88
- var _p0 unsafe.Pointer
89
- var bufsize uintptr
90
- if len(buf) > 0 {
91
- _p0 = unsafe.Pointer(&buf[0])
92
- bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
93
- }
94
- r0, _, e1 := syscall.Syscall(SYS_GETFSSTAT64, uintptr(_p0), bufsize, uintptr(flags))
95
- n = int(r0)
96
- if e1 != 0 {
97
- err = e1
98
- }
99
- return
100
-}
101
-
102
-func getFsType(stat syscall.Statfs_t) string {
103
- return common.IntToString(stat.Fstypename[:])
104
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin_amd64.go
deleted
-58
@@ -1,58 +0,0 @@
1
-// +build darwin
2
-// +build amd64
3
-
4
-package disk
5
-
6
-const (
7
- MntWait = 1
8
- MfsNameLen = 15 /* length of fs type name, not inc. nul */
9
- MNameLen = 90 /* length of buffer for returned name */
10
-
11
- MFSTYPENAMELEN = 16 /* length of fs type name including null */
12
- MAXPATHLEN = 1024
13
- MNAMELEN = MAXPATHLEN
14
-
15
- SYS_GETFSSTAT64 = 347
16
-)
17
-
18
-type Fsid struct{ val [2]int32 } /* file system id type */
19
-type uid_t int32
20
-
21
-// sys/mount.h
22
-const (
23
- MntReadOnly = 0x00000001 /* read only filesystem */
24
- MntSynchronous = 0x00000002 /* filesystem written synchronously */
25
- MntNoExec = 0x00000004 /* can't exec from filesystem */
26
- MntNoSuid = 0x00000008 /* don't honor setuid bits on fs */
27
- MntUnion = 0x00000020 /* union with underlying filesystem */
28
- MntAsync = 0x00000040 /* filesystem written asynchronously */
29
- MntSuidDir = 0x00100000 /* special handling of SUID on dirs */
30
- MntSoftDep = 0x00200000 /* soft updates being done */
31
- MntNoSymFollow = 0x00400000 /* do not follow symlinks */
32
- MntGEOMJournal = 0x02000000 /* GEOM journal support enabled */
33
- MntMultilabel = 0x04000000 /* MAC support for individual objects */
34
- MntACLs = 0x08000000 /* ACL support enabled */
35
- MntNoATime = 0x10000000 /* disable update of file access time */
36
- MntClusterRead = 0x40000000 /* disable cluster read */
37
- MntClusterWrite = 0x80000000 /* disable cluster write */
38
- MntNFS4ACLs = 0x00000010
39
-)
40
-
41
-type Statfs_t struct {
42
- Bsize uint32
43
- Iosize int32
44
- Blocks uint64
45
- Bfree uint64
46
- Bavail uint64
47
- Files uint64
48
- Ffree uint64
49
- Fsid Fsid
50
- Owner uint32
51
- Type uint32
52
- Flags uint32
53
- Fssubtype uint32
54
- Fstypename [16]int8
55
- Mntonname [1024]int8
56
- Mntfromname [1024]int8
57
- Reserved [8]uint32
58
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd.go
deleted
-179
@@ -1,179 +0,0 @@
1
-// +build freebsd
2
-
3
-package disk
4
-
5
-import (
6
- "bytes"
7
- "encoding/binary"
8
- "strconv"
9
- "syscall"
10
- "unsafe"
11
-
12
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
13
-)
14
-
15
-const (
16
- CTLKern = 1
17
- // KernDevstat = 773 // for freebsd 8.4
18
- // KernDevstatAll = 772 // for freebsd 8.4
19
- KernDevstat = 974
20
- KernDevstatAll = 975
21
-)
22
-
23
-func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
24
- var ret []DiskPartitionStat
25
-
26
- // get length
27
- count, err := syscall.Getfsstat(nil, MNT_WAIT)
28
- if err != nil {
29
- return ret, err
30
- }
31
-
32
- fs := make([]Statfs, count)
33
- _, err = Getfsstat(fs, MNT_WAIT)
34
-
35
- for _, stat := range fs {
36
- opts := "rw"
37
- if stat.Flags&MNT_RDONLY != 0 {
38
- opts = "ro"
39
- }
40
- if stat.Flags&MNT_SYNCHRONOUS != 0 {
41
- opts += ",sync"
42
- }
43
- if stat.Flags&MNT_NOEXEC != 0 {
44
- opts += ",noexec"
45
- }
46
- if stat.Flags&MNT_NOSUID != 0 {
47
- opts += ",nosuid"
48
- }
49
- if stat.Flags&MNT_UNION != 0 {
50
- opts += ",union"
51
- }
52
- if stat.Flags&MNT_ASYNC != 0 {
53
- opts += ",async"
54
- }
55
- if stat.Flags&MNT_SUIDDIR != 0 {
56
- opts += ",suiddir"
57
- }
58
- if stat.Flags&MNT_SOFTDEP != 0 {
59
- opts += ",softdep"
60
- }
61
- if stat.Flags&MNT_NOSYMFOLLOW != 0 {
62
- opts += ",nosymfollow"
63
- }
64
- if stat.Flags&MNT_GJOURNAL != 0 {
65
- opts += ",gjounalc"
66
- }
67
- if stat.Flags&MNT_MULTILABEL != 0 {
68
- opts += ",multilabel"
69
- }
70
- if stat.Flags&MNT_ACLS != 0 {
71
- opts += ",acls"
72
- }
73
- if stat.Flags&MNT_NOATIME != 0 {
74
- opts += ",noattime"
75
- }
76
- if stat.Flags&MNT_NOCLUSTERR != 0 {
77
- opts += ",nocluster"
78
- }
79
- if stat.Flags&MNT_NOCLUSTERW != 0 {
80
- opts += ",noclusterw"
81
- }
82
- if stat.Flags&MNT_NFS4ACLS != 0 {
83
- opts += ",nfs4acls"
84
- }
85
-
86
- d := DiskPartitionStat{
87
- Device: common.IntToString(stat.Mntfromname[:]),
88
- Mountpoint: common.IntToString(stat.Mntonname[:]),
89
- Fstype: common.IntToString(stat.Fstypename[:]),
90
- Opts: opts,
91
- }
92
- ret = append(ret, d)
93
- }
94
-
95
- return ret, nil
96
-}
97
-
98
-func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
99
- // statinfo->devinfo->devstat
100
- // /usr/include/devinfo.h
101
-
102
- // sysctl.sysctl ('kern.devstat.all', 0)
103
- ret := make(map[string]DiskIOCountersStat)
104
- mib := []int32{CTLKern, KernDevstat, KernDevstatAll}
105
-
106
- buf, length, err := common.CallSyscall(mib)
107
- if err != nil {
108
- return nil, err
109
- }
110
-
111
- ds := Devstat{}
112
- devstatLen := int(unsafe.Sizeof(ds))
113
- count := int(length / uint64(devstatLen))
114
-
115
- buf = buf[8:] // devstat.all has version in the head.
116
- // parse buf to Devstat
117
- for i := 0; i < count; i++ {
118
- b := buf[i*devstatLen : i*devstatLen+devstatLen]
119
- d, err := parseDevstat(b)
120
- if err != nil {
121
- continue
122
- }
123
- un := strconv.Itoa(int(d.Unit_number))
124
- name := common.IntToString(d.Device_name[:]) + un
125
-
126
- ds := DiskIOCountersStat{
127
- ReadCount: d.Operations[DEVSTAT_READ],
128
- WriteCount: d.Operations[DEVSTAT_WRITE],
129
- ReadBytes: d.Bytes[DEVSTAT_READ],
130
- WriteBytes: d.Bytes[DEVSTAT_WRITE],
131
- ReadTime: d.Duration[DEVSTAT_READ].Compute(),
132
- WriteTime: d.Duration[DEVSTAT_WRITE].Compute(),
133
- Name: name,
134
- }
135
- ret[name] = ds
136
- }
137
-
138
- return ret, nil
139
-}
140
-
141
-func (b Bintime) Compute() uint64 {
142
- BINTIME_SCALE := 5.42101086242752217003726400434970855712890625e-20
143
- return uint64(b.Sec) + b.Frac*uint64(BINTIME_SCALE)
144
-}
145
-
146
-// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE)
147
-
148
-// Getfsstat is borrowed from pkg/syscall/syscall_freebsd.go
149
-// change Statfs_t to Statfs in order to get more information
150
-func Getfsstat(buf []Statfs, flags int) (n int, err error) {
151
- var _p0 unsafe.Pointer
152
- var bufsize uintptr
153
- if len(buf) > 0 {
154
- _p0 = unsafe.Pointer(&buf[0])
155
- bufsize = unsafe.Sizeof(Statfs{}) * uintptr(len(buf))
156
- }
157
- r0, _, e1 := syscall.Syscall(syscall.SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
158
- n = int(r0)
159
- if e1 != 0 {
160
- err = e1
161
- }
162
- return
163
-}
164
-
165
-func parseDevstat(buf []byte) (Devstat, error) {
166
- var ds Devstat
167
- br := bytes.NewReader(buf)
168
- // err := binary.Read(br, binary.LittleEndian, &ds)
169
- err := Read(br, binary.LittleEndian, &ds)
170
- if err != nil {
171
- return ds, err
172
- }
173
-
174
- return ds, nil
175
-}
176
-
177
-func getFsType(stat syscall.Statfs_t) string {
178
- return common.IntToString(stat.Fstypename[:])
179
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd_amd64.go
deleted
-111
@@ -1,111 +0,0 @@
1
-// Created by cgo -godefs - DO NOT EDIT
2
-// cgo -godefs types_freebsd.go
3
-
4
-package disk
5
-
6
-const (
7
- sizeofPtr = 0x8
8
- sizeofShort = 0x2
9
- sizeofInt = 0x4
10
- sizeofLong = 0x8
11
- sizeofLongLong = 0x8
12
- sizeofLongDouble = 0x8
13
-
14
- DEVSTAT_NO_DATA = 0x00
15
- DEVSTAT_READ = 0x01
16
- DEVSTAT_WRITE = 0x02
17
- DEVSTAT_FREE = 0x03
18
-
19
- MNT_RDONLY = 0x00000001
20
- MNT_SYNCHRONOUS = 0x00000002
21
- MNT_NOEXEC = 0x00000004
22
- MNT_NOSUID = 0x00000008
23
- MNT_UNION = 0x00000020
24
- MNT_ASYNC = 0x00000040
25
- MNT_SUIDDIR = 0x00100000
26
- MNT_SOFTDEP = 0x00200000
27
- MNT_NOSYMFOLLOW = 0x00400000
28
- MNT_GJOURNAL = 0x02000000
29
- MNT_MULTILABEL = 0x04000000
30
- MNT_ACLS = 0x08000000
31
- MNT_NOATIME = 0x10000000
32
- MNT_NOCLUSTERR = 0x40000000
33
- MNT_NOCLUSTERW = 0x80000000
34
- MNT_NFS4ACLS = 0x00000010
35
-
36
- MNT_WAIT = 1
37
- MNT_NOWAIT = 2
38
- MNT_LAZY = 3
39
- MNT_SUSPEND = 4
40
-)
41
-
42
-type (
43
- _C_short int16
44
- _C_int int32
45
- _C_long int64
46
- _C_long_long int64
47
- _C_long_double int64
48
-)
49
-
50
-type Statfs struct {
51
- Version uint32
52
- Type uint32
53
- Flags uint64
54
- Bsize uint64
55
- Iosize uint64
56
- Blocks uint64
57
- Bfree uint64
58
- Bavail int64
59
- Files uint64
60
- Ffree int64
61
- Syncwrites uint64
62
- Asyncwrites uint64
63
- Syncreads uint64
64
- Asyncreads uint64
65
- Spare [10]uint64
66
- Namemax uint32
67
- Owner uint32
68
- Fsid Fsid
69
- Charspare [80]int8
70
- Fstypename [16]int8
71
- Mntfromname [88]int8
72
- Mntonname [88]int8
73
-}
74
-type Fsid struct {
75
- Val [2]int32
76
-}
77
-
78
-type Devstat struct {
79
- Sequence0 uint32
80
- Allocated int32
81
- Start_count uint32
82
- End_count uint32
83
- Busy_from Bintime
84
- Dev_links _Ctype_struct___0
85
- Device_number uint32
86
- Device_name [16]int8
87
- Unit_number int32
88
- Bytes [4]uint64
89
- Operations [4]uint64
90
- Duration [4]Bintime
91
- Busy_time Bintime
92
- Creation_time Bintime
93
- Block_size uint32
94
- Pad_cgo_0 [4]byte
95
- Tag_types [3]uint64
96
- Flags uint32
97
- Device_type uint32
98
- Priority uint32
99
- Pad_cgo_1 [4]byte
100
- Id *byte
101
- Sequence1 uint32
102
- Pad_cgo_2 [4]byte
103
-}
104
-type Bintime struct {
105
- Sec int64
106
- Frac uint64
107
-}
108
-
109
-type _Ctype_struct___0 struct {
110
- Empty uint64
111
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_linux.go
deleted
-327
@@ -1,327 +0,0 @@
1
-// +build linux
2
-
3
-package disk
4
-
5
-import (
6
- "fmt"
7
- "os/exec"
8
- "strconv"
9
- "strings"
10
- "syscall"
11
-
12
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
13
-)
14
-
15
-const (
16
- SectorSize = 512
17
-)
18
-const (
19
- // man statfs
20
- ADFS_SUPER_MAGIC = 0xadf5
21
- AFFS_SUPER_MAGIC = 0xADFF
22
- BDEVFS_MAGIC = 0x62646576
23
- BEFS_SUPER_MAGIC = 0x42465331
24
- BFS_MAGIC = 0x1BADFACE
25
- BINFMTFS_MAGIC = 0x42494e4d
26
- BTRFS_SUPER_MAGIC = 0x9123683E
27
- CGROUP_SUPER_MAGIC = 0x27e0eb
28
- CIFS_MAGIC_NUMBER = 0xFF534D42
29
- CODA_SUPER_MAGIC = 0x73757245
30
- COH_SUPER_MAGIC = 0x012FF7B7
31
- CRAMFS_MAGIC = 0x28cd3d45
32
- DEBUGFS_MAGIC = 0x64626720
33
- DEVFS_SUPER_MAGIC = 0x1373
34
- DEVPTS_SUPER_MAGIC = 0x1cd1
35
- EFIVARFS_MAGIC = 0xde5e81e4
36
- EFS_SUPER_MAGIC = 0x00414A53
37
- EXT_SUPER_MAGIC = 0x137D
38
- EXT2_OLD_SUPER_MAGIC = 0xEF51
39
- EXT2_SUPER_MAGIC = 0xEF53
40
- EXT3_SUPER_MAGIC = 0xEF53
41
- EXT4_SUPER_MAGIC = 0xEF53
42
- FUSE_SUPER_MAGIC = 0x65735546
43
- FUTEXFS_SUPER_MAGIC = 0xBAD1DEA
44
- HFS_SUPER_MAGIC = 0x4244
45
- HOSTFS_SUPER_MAGIC = 0x00c0ffee
46
- HPFS_SUPER_MAGIC = 0xF995E849
47
- HUGETLBFS_MAGIC = 0x958458f6
48
- ISOFS_SUPER_MAGIC = 0x9660
49
- JFFS2_SUPER_MAGIC = 0x72b6
50
- JFS_SUPER_MAGIC = 0x3153464a
51
- MINIX_SUPER_MAGIC = 0x137F /* orig. minix */
52
- MINIX_SUPER_MAGIC2 = 0x138F /* 30 char minix */
53
- MINIX2_SUPER_MAGIC = 0x2468 /* minix V2 */
54
- MINIX2_SUPER_MAGIC2 = 0x2478 /* minix V2, 30 char names */
55
- MINIX3_SUPER_MAGIC = 0x4d5a /* minix V3 fs, 60 char names */
56
- MQUEUE_MAGIC = 0x19800202
57
- MSDOS_SUPER_MAGIC = 0x4d44
58
- NCP_SUPER_MAGIC = 0x564c
59
- NFS_SUPER_MAGIC = 0x6969
60
- NILFS_SUPER_MAGIC = 0x3434
61
- NTFS_SB_MAGIC = 0x5346544e
62
- OCFS2_SUPER_MAGIC = 0x7461636f
63
- OPENPROM_SUPER_MAGIC = 0x9fa1
64
- PIPEFS_MAGIC = 0x50495045
65
- PROC_SUPER_MAGIC = 0x9fa0
66
- PSTOREFS_MAGIC = 0x6165676C
67
- QNX4_SUPER_MAGIC = 0x002f
68
- QNX6_SUPER_MAGIC = 0x68191122
69
- RAMFS_MAGIC = 0x858458f6
70
- REISERFS_SUPER_MAGIC = 0x52654973
71
- ROMFS_MAGIC = 0x7275
72
- SELINUX_MAGIC = 0xf97cff8c
73
- SMACK_MAGIC = 0x43415d53
74
- SMB_SUPER_MAGIC = 0x517B
75
- SOCKFS_MAGIC = 0x534F434B
76
- SQUASHFS_MAGIC = 0x73717368
77
- SYSFS_MAGIC = 0x62656572
78
- SYSV2_SUPER_MAGIC = 0x012FF7B6
79
- SYSV4_SUPER_MAGIC = 0x012FF7B5
80
- TMPFS_MAGIC = 0x01021994
81
- UDF_SUPER_MAGIC = 0x15013346
82
- UFS_MAGIC = 0x00011954
83
- USBDEVICE_SUPER_MAGIC = 0x9fa2
84
- V9FS_MAGIC = 0x01021997
85
- VXFS_SUPER_MAGIC = 0xa501FCF5
86
- XENFS_SUPER_MAGIC = 0xabba1974
87
- XENIX_SUPER_MAGIC = 0x012FF7B4
88
- XFS_SUPER_MAGIC = 0x58465342
89
- _XIAFS_SUPER_MAGIC = 0x012FD16D
90
-
91
- AFS_SUPER_MAGIC = 0x5346414F
92
- AUFS_SUPER_MAGIC = 0x61756673
93
- ANON_INODE_FS_SUPER_MAGIC = 0x09041934
94
- CEPH_SUPER_MAGIC = 0x00C36400
95
- ECRYPTFS_SUPER_MAGIC = 0xF15F
96
- FAT_SUPER_MAGIC = 0x4006
97
- FHGFS_SUPER_MAGIC = 0x19830326
98
- FUSEBLK_SUPER_MAGIC = 0x65735546
99
- FUSECTL_SUPER_MAGIC = 0x65735543
100
- GFS_SUPER_MAGIC = 0x1161970
101
- GPFS_SUPER_MAGIC = 0x47504653
102
- MTD_INODE_FS_SUPER_MAGIC = 0x11307854
103
- INOTIFYFS_SUPER_MAGIC = 0x2BAD1DEA
104
- ISOFS_R_WIN_SUPER_MAGIC = 0x4004
105
- ISOFS_WIN_SUPER_MAGIC = 0x4000
106
- JFFS_SUPER_MAGIC = 0x07C0
107
- KAFS_SUPER_MAGIC = 0x6B414653
108
- LUSTRE_SUPER_MAGIC = 0x0BD00BD0
109
- NFSD_SUPER_MAGIC = 0x6E667364
110
- PANFS_SUPER_MAGIC = 0xAAD7AAEA
111
- RPC_PIPEFS_SUPER_MAGIC = 0x67596969
112
- SECURITYFS_SUPER_MAGIC = 0x73636673
113
- UFS_BYTESWAPPED_SUPER_MAGIC = 0x54190100
114
- VMHGFS_SUPER_MAGIC = 0xBACBACBC
115
- VZFS_SUPER_MAGIC = 0x565A4653
116
- ZFS_SUPER_MAGIC = 0x2FC12FC1
117
-)
118
-
119
-// coreutils/src/stat.c
120
-var fsTypeMap = map[int64]string{
121
- ADFS_SUPER_MAGIC: "adfs", /* 0xADF5 local */
122
- AFFS_SUPER_MAGIC: "affs", /* 0xADFF local */
123
- AFS_SUPER_MAGIC: "afs", /* 0x5346414F remote */
124
- ANON_INODE_FS_SUPER_MAGIC: "anon-inode FS", /* 0x09041934 local */
125
- AUFS_SUPER_MAGIC: "aufs", /* 0x61756673 remote */
126
- // AUTOFS_SUPER_MAGIC: "autofs", /* 0x0187 local */
127
- BEFS_SUPER_MAGIC: "befs", /* 0x42465331 local */
128
- BDEVFS_MAGIC: "bdevfs", /* 0x62646576 local */
129
- BFS_MAGIC: "bfs", /* 0x1BADFACE local */
130
- BINFMTFS_MAGIC: "binfmt_misc", /* 0x42494E4D local */
131
- BTRFS_SUPER_MAGIC: "btrfs", /* 0x9123683E local */
132
- CEPH_SUPER_MAGIC: "ceph", /* 0x00C36400 remote */
133
- CGROUP_SUPER_MAGIC: "cgroupfs", /* 0x0027E0EB local */
134
- CIFS_MAGIC_NUMBER: "cifs", /* 0xFF534D42 remote */
135
- CODA_SUPER_MAGIC: "coda", /* 0x73757245 remote */
136
- COH_SUPER_MAGIC: "coh", /* 0x012FF7B7 local */
137
- CRAMFS_MAGIC: "cramfs", /* 0x28CD3D45 local */
138
- DEBUGFS_MAGIC: "debugfs", /* 0x64626720 local */
139
- DEVFS_SUPER_MAGIC: "devfs", /* 0x1373 local */
140
- DEVPTS_SUPER_MAGIC: "devpts", /* 0x1CD1 local */
141
- ECRYPTFS_SUPER_MAGIC: "ecryptfs", /* 0xF15F local */
142
- EFS_SUPER_MAGIC: "efs", /* 0x00414A53 local */
143
- EXT_SUPER_MAGIC: "ext", /* 0x137D local */
144
- EXT2_SUPER_MAGIC: "ext2/ext3", /* 0xEF53 local */
145
- EXT2_OLD_SUPER_MAGIC: "ext2", /* 0xEF51 local */
146
- FAT_SUPER_MAGIC: "fat", /* 0x4006 local */
147
- FHGFS_SUPER_MAGIC: "fhgfs", /* 0x19830326 remote */
148
- FUSEBLK_SUPER_MAGIC: "fuseblk", /* 0x65735546 remote */
149
- FUSECTL_SUPER_MAGIC: "fusectl", /* 0x65735543 remote */
150
- FUTEXFS_SUPER_MAGIC: "futexfs", /* 0x0BAD1DEA local */
151
- GFS_SUPER_MAGIC: "gfs/gfs2", /* 0x1161970 remote */
152
- GPFS_SUPER_MAGIC: "gpfs", /* 0x47504653 remote */
153
- HFS_SUPER_MAGIC: "hfs", /* 0x4244 local */
154
- HPFS_SUPER_MAGIC: "hpfs", /* 0xF995E849 local */
155
- HUGETLBFS_MAGIC: "hugetlbfs", /* 0x958458F6 local */
156
- MTD_INODE_FS_SUPER_MAGIC: "inodefs", /* 0x11307854 local */
157
- INOTIFYFS_SUPER_MAGIC: "inotifyfs", /* 0x2BAD1DEA local */
158
- ISOFS_SUPER_MAGIC: "isofs", /* 0x9660 local */
159
- ISOFS_R_WIN_SUPER_MAGIC: "isofs", /* 0x4004 local */
160
- ISOFS_WIN_SUPER_MAGIC: "isofs", /* 0x4000 local */
161
- JFFS_SUPER_MAGIC: "jffs", /* 0x07C0 local */
162
- JFFS2_SUPER_MAGIC: "jffs2", /* 0x72B6 local */
163
- JFS_SUPER_MAGIC: "jfs", /* 0x3153464A local */
164
- KAFS_SUPER_MAGIC: "k-afs", /* 0x6B414653 remote */
165
- LUSTRE_SUPER_MAGIC: "lustre", /* 0x0BD00BD0 remote */
166
- MINIX_SUPER_MAGIC: "minix", /* 0x137F local */
167
- MINIX_SUPER_MAGIC2: "minix (30 char.)", /* 0x138F local */
168
- MINIX2_SUPER_MAGIC: "minix v2", /* 0x2468 local */
169
- MINIX2_SUPER_MAGIC2: "minix v2 (30 char.)", /* 0x2478 local */
170
- MINIX3_SUPER_MAGIC: "minix3", /* 0x4D5A local */
171
- MQUEUE_MAGIC: "mqueue", /* 0x19800202 local */
172
- MSDOS_SUPER_MAGIC: "msdos", /* 0x4D44 local */
173
- NCP_SUPER_MAGIC: "novell", /* 0x564C remote */
174
- NFS_SUPER_MAGIC: "nfs", /* 0x6969 remote */
175
- NFSD_SUPER_MAGIC: "nfsd", /* 0x6E667364 remote */
176
- NILFS_SUPER_MAGIC: "nilfs", /* 0x3434 local */
177
- NTFS_SB_MAGIC: "ntfs", /* 0x5346544E local */
178
- OPENPROM_SUPER_MAGIC: "openprom", /* 0x9FA1 local */
179
- OCFS2_SUPER_MAGIC: "ocfs2", /* 0x7461636f remote */
180
- PANFS_SUPER_MAGIC: "panfs", /* 0xAAD7AAEA remote */
181
- PIPEFS_MAGIC: "pipefs", /* 0x50495045 remote */
182
- PROC_SUPER_MAGIC: "proc", /* 0x9FA0 local */
183
- PSTOREFS_MAGIC: "pstorefs", /* 0x6165676C local */
184
- QNX4_SUPER_MAGIC: "qnx4", /* 0x002F local */
185
- QNX6_SUPER_MAGIC: "qnx6", /* 0x68191122 local */
186
- RAMFS_MAGIC: "ramfs", /* 0x858458F6 local */
187
- REISERFS_SUPER_MAGIC: "reiserfs", /* 0x52654973 local */
188
- ROMFS_MAGIC: "romfs", /* 0x7275 local */
189
- RPC_PIPEFS_SUPER_MAGIC: "rpc_pipefs", /* 0x67596969 local */
190
- SECURITYFS_SUPER_MAGIC: "securityfs", /* 0x73636673 local */
191
- SELINUX_MAGIC: "selinux", /* 0xF97CFF8C local */
192
- SMB_SUPER_MAGIC: "smb", /* 0x517B remote */
193
- SOCKFS_MAGIC: "sockfs", /* 0x534F434B local */
194
- SQUASHFS_MAGIC: "squashfs", /* 0x73717368 local */
195
- SYSFS_MAGIC: "sysfs", /* 0x62656572 local */
196
- SYSV2_SUPER_MAGIC: "sysv2", /* 0x012FF7B6 local */
197
- SYSV4_SUPER_MAGIC: "sysv4", /* 0x012FF7B5 local */
198
- TMPFS_MAGIC: "tmpfs", /* 0x01021994 local */
199
- UDF_SUPER_MAGIC: "udf", /* 0x15013346 local */
200
- UFS_MAGIC: "ufs", /* 0x00011954 local */
201
- UFS_BYTESWAPPED_SUPER_MAGIC: "ufs", /* 0x54190100 local */
202
- USBDEVICE_SUPER_MAGIC: "usbdevfs", /* 0x9FA2 local */
203
- V9FS_MAGIC: "v9fs", /* 0x01021997 local */
204
- VMHGFS_SUPER_MAGIC: "vmhgfs", /* 0xBACBACBC remote */
205
- VXFS_SUPER_MAGIC: "vxfs", /* 0xA501FCF5 local */
206
- VZFS_SUPER_MAGIC: "vzfs", /* 0x565A4653 local */
207
- XENFS_SUPER_MAGIC: "xenfs", /* 0xABBA1974 local */
208
- XENIX_SUPER_MAGIC: "xenix", /* 0x012FF7B4 local */
209
- XFS_SUPER_MAGIC: "xfs", /* 0x58465342 local */
210
- _XIAFS_SUPER_MAGIC: "xia", /* 0x012FD16D local */
211
- ZFS_SUPER_MAGIC: "zfs", /* 0x2FC12FC1 local */
212
-}
213
-
214
-// Get disk partitions.
215
-// should use setmntent(3) but this implement use /etc/mtab file
216
-func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
217
-
218
- filename := "/etc/mtab"
219
- lines, err := common.ReadLines(filename)
220
- if err != nil {
221
- return nil, err
222
- }
223
-
224
- ret := make([]DiskPartitionStat, 0, len(lines))
225
-
226
- for _, line := range lines {
227
- fields := strings.Fields(line)
228
- d := DiskPartitionStat{
229
- Device: fields[0],
230
- Mountpoint: fields[1],
231
- Fstype: fields[2],
232
- Opts: fields[3],
233
- }
234
- ret = append(ret, d)
235
- }
236
-
237
- return ret, nil
238
-}
239
-
240
-func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
241
- filename := "/proc/diskstats"
242
- lines, err := common.ReadLines(filename)
243
- if err != nil {
244
- return nil, err
245
- }
246
- ret := make(map[string]DiskIOCountersStat, 0)
247
- empty := DiskIOCountersStat{}
248
-
249
- for _, line := range lines {
250
- fields := strings.Fields(line)
251
- name := fields[2]
252
- reads, err := strconv.ParseUint((fields[3]), 10, 64)
253
- if err != nil {
254
- return ret, err
255
- }
256
- rbytes, err := strconv.ParseUint((fields[5]), 10, 64)
257
- if err != nil {
258
- return ret, err
259
- }
260
- rtime, err := strconv.ParseUint((fields[6]), 10, 64)
261
- if err != nil {
262
- return ret, err
263
- }
264
- writes, err := strconv.ParseUint((fields[7]), 10, 64)
265
- if err != nil {
266
- return ret, err
267
- }
268
- wbytes, err := strconv.ParseUint((fields[9]), 10, 64)
269
- if err != nil {
270
- return ret, err
271
- }
272
- wtime, err := strconv.ParseUint((fields[10]), 10, 64)
273
- if err != nil {
274
- return ret, err
275
- }
276
- iotime, err := strconv.ParseUint((fields[12]), 10, 64)
277
- if err != nil {
278
- return ret, err
279
- }
280
- d := DiskIOCountersStat{
281
- ReadBytes: rbytes * SectorSize,
282
- WriteBytes: wbytes * SectorSize,
283
- ReadCount: reads,
284
- WriteCount: writes,
285
- ReadTime: rtime,
286
- WriteTime: wtime,
287
- IoTime: iotime,
288
- }
289
- if d == empty {
290
- continue
291
- }
292
- d.Name = name
293
-
294
- d.SerialNumber = GetDiskSerialNumber(name)
295
- ret[name] = d
296
- }
297
- return ret, nil
298
-}
299
-
300
-func GetDiskSerialNumber(name string) string {
301
- n := fmt.Sprintf("--name=%s", name)
302
- out, err := exec.Command("/sbin/udevadm", "info", "--query=property", n).Output()
303
-
304
- // does not return error, just an empty string
305
- if err != nil {
306
- return ""
307
- }
308
- lines := strings.Split(string(out), "\n")
309
- for _, line := range lines {
310
- values := strings.Split(line, "=")
311
- if len(values) < 2 || values[0] != "ID_SERIAL" {
312
- // only get ID_SERIAL, not ID_SERIAL_SHORT
313
- continue
314
- }
315
- return values[1]
316
- }
317
- return ""
318
-}
319
-
320
-func getFsType(stat syscall.Statfs_t) string {
321
- t := int64(stat.Type)
322
- ret, ok := fsTypeMap[t]
323
- if !ok {
324
- return ""
325
- }
326
- return ret
327
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_test.go
deleted
-97
@@ -1,97 +0,0 @@
1
-package disk
2
-
3
-import (
4
- "fmt"
5
- "runtime"
6
- "testing"
7
-)
8
-
9
-func TestDisk_usage(t *testing.T) {
10
- path := "/"
11
- if runtime.GOOS == "windows" {
12
- path = "C:"
13
- }
14
- v, err := DiskUsage(path)
15
- if err != nil {
16
- t.Errorf("error %v", err)
17
- }
18
- if v.Path != path {
19
- t.Errorf("error %v", err)
20
- }
21
-}
22
-
23
-func TestDisk_partitions(t *testing.T) {
24
- ret, err := DiskPartitions(false)
25
- if err != nil || len(ret) == 0 {
26
- t.Errorf("error %v", err)
27
- }
28
- empty := DiskPartitionStat{}
29
- for _, disk := range ret {
30
- if disk == empty {
31
- t.Errorf("Could not get device info %v", disk)
32
- }
33
- }
34
-}
35
-
36
-func TestDisk_io_counters(t *testing.T) {
37
- ret, err := DiskIOCounters()
38
- if err != nil {
39
- t.Errorf("error %v", err)
40
- }
41
- if len(ret) == 0 {
42
- t.Errorf("ret is empty, %v", ret)
43
- }
44
- empty := DiskIOCountersStat{}
45
- for part, io := range ret {
46
- if io == empty {
47
- t.Errorf("io_counter error %v, %v", part, io)
48
- }
49
- }
50
-}
51
-
52
-func TestDiskUsageStat_String(t *testing.T) {
53
- v := DiskUsageStat{
54
- Path: "/",
55
- Total: 1000,
56
- Free: 2000,
57
- Used: 3000,
58
- UsedPercent: 50.1,
59
- InodesTotal: 4000,
60
- InodesUsed: 5000,
61
- InodesFree: 6000,
62
- InodesUsedPercent: 49.1,
63
- Fstype: "ext4",
64
- }
65
- e := `{"path":"/","fstype":"ext4","total":1000,"free":2000,"used":3000,"used_percent":50.1,"inodes_total":4000,"inodes_used":5000,"inodes_free":6000,"inodes_used_percent":49.1}`
66
- if e != fmt.Sprintf("%v", v) {
67
- t.Errorf("DiskUsageStat string is invalid: %v", v)
68
- }
69
-}
70
-
71
-func TestDiskPartitionStat_String(t *testing.T) {
72
- v := DiskPartitionStat{
73
- Device: "sd01",
74
- Mountpoint: "/",
75
- Fstype: "ext4",
76
- Opts: "ro",
77
- }
78
- e := `{"device":"sd01","mountpoint":"/","fstype":"ext4","opts":"ro"}`
79
- if e != fmt.Sprintf("%v", v) {
80
- t.Errorf("DiskUsageStat string is invalid: %v", v)
81
- }
82
-}
83
-
84
-func TestDiskIOCountersStat_String(t *testing.T) {
85
- v := DiskIOCountersStat{
86
- Name: "sd01",
87
- ReadCount: 100,
88
- WriteCount: 200,
89
- ReadBytes: 300,
90
- WriteBytes: 400,
91
- SerialNumber: "SERIAL",
92
- }
93
- e := `{"read_count":100,"write_count":200,"read_bytes":300,"write_bytes":400,"read_time":0,"write_time":0,"name":"sd01","io_time":0,"serial_number":"SERIAL"}`
94
- if e != fmt.Sprintf("%v", v) {
95
- t.Errorf("DiskUsageStat string is invalid: %v", v)
96
- }
97
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_unix.go
deleted
-30
@@ -1,30 +0,0 @@
1
-// +build freebsd linux darwin
2
-
3
-package disk
4
-
5
-import "syscall"
6
-
7
-func DiskUsage(path string) (*DiskUsageStat, error) {
8
- stat := syscall.Statfs_t{}
9
- err := syscall.Statfs(path, &stat)
10
- if err != nil {
11
- return nil, err
12
- }
13
- bsize := stat.Bsize
14
-
15
- ret := &DiskUsageStat{
16
- Path: path,
17
- Fstype: getFsType(stat),
18
- Total: (uint64(stat.Blocks) * uint64(bsize)),
19
- Free: (uint64(stat.Bfree) * uint64(bsize)),
20
- InodesTotal: (uint64(stat.Files)),
21
- InodesFree: (uint64(stat.Ffree)),
22
- }
23
-
24
- ret.InodesUsed = (ret.InodesTotal - ret.InodesFree)
25
- ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0
26
- ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize)
27
- ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0
28
-
29
- return ret, nil
30
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_windows.go
deleted
-155
@@ -1,155 +0,0 @@
1
-// +build windows
2
-
3
-package disk
4
-
5
-import (
6
- "bytes"
7
- "syscall"
8
- "unsafe"
9
-
10
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/StackExchange/wmi"
11
-
12
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
13
-)
14
-
15
-var (
16
- procGetDiskFreeSpaceExW = common.Modkernel32.NewProc("GetDiskFreeSpaceExW")
17
- procGetLogicalDriveStringsW = common.Modkernel32.NewProc("GetLogicalDriveStringsW")
18
- procGetDriveType = common.Modkernel32.NewProc("GetDriveTypeW")
19
- provGetVolumeInformation = common.Modkernel32.NewProc("GetVolumeInformationW")
20
-)
21
-
22
-var (
23
- FileFileCompression = int64(16) // 0x00000010
24
- FileReadOnlyVolume = int64(524288) // 0x00080000
25
-)
26
-
27
-type Win32_PerfFormattedData struct {
28
- Name string
29
- AvgDiskBytesPerRead uint64
30
- AvgDiskBytesPerWrite uint64
31
- AvgDiskReadQueueLength uint64
32
- AvgDiskWriteQueueLength uint64
33
- AvgDisksecPerRead uint64
34
- AvgDisksecPerWrite uint64
35
-}
36
-
37
-const WaitMSec = 500
38
-
39
-func DiskUsage(path string) (*DiskUsageStat, error) {
40
- ret := &DiskUsageStat{}
41
-
42
- lpFreeBytesAvailable := int64(0)
43
- lpTotalNumberOfBytes := int64(0)
44
- lpTotalNumberOfFreeBytes := int64(0)
45
- diskret, _, err := procGetDiskFreeSpaceExW.Call(
46
- uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
47
- uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
48
- uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
49
- uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)))
50
- if diskret == 0 {
51
- return nil, err
52
- }
53
- ret = &DiskUsageStat{
54
- Path: path,
55
- Total: uint64(lpTotalNumberOfBytes),
56
- Free: uint64(lpTotalNumberOfFreeBytes),
57
- Used: uint64(lpTotalNumberOfBytes) - uint64(lpTotalNumberOfFreeBytes),
58
- UsedPercent: (float64(lpTotalNumberOfBytes) - float64(lpTotalNumberOfFreeBytes)) / float64(lpTotalNumberOfBytes) * 100,
59
- // InodesTotal: 0,
60
- // InodesFree: 0,
61
- // InodesUsed: 0,
62
- // InodesUsedPercent: 0,
63
- }
64
- return ret, nil
65
-}
66
-
67
-func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
68
- var ret []DiskPartitionStat
69
- lpBuffer := make([]byte, 254)
70
- diskret, _, err := procGetLogicalDriveStringsW.Call(
71
- uintptr(len(lpBuffer)),
72
- uintptr(unsafe.Pointer(&lpBuffer[0])))
73
- if diskret == 0 {
74
- return ret, err
75
- }
76
- for _, v := range lpBuffer {
77
- if v >= 65 && v <= 90 {
78
- path := string(v) + ":"
79
- if path == "A:" || path == "B:" { // skip floppy drives
80
- continue
81
- }
82
- typepath, _ := syscall.UTF16PtrFromString(path)
83
- typeret, _, _ := procGetDriveType.Call(uintptr(unsafe.Pointer(typepath)))
84
- if typeret == 0 {
85
- return ret, syscall.GetLastError()
86
- }
87
- // 2: DRIVE_REMOVABLE 3: DRIVE_FIXED 5: DRIVE_CDROM
88
-
89
- if typeret == 2 || typeret == 3 || typeret == 5 {
90
- lpVolumeNameBuffer := make([]byte, 256)
91
- lpVolumeSerialNumber := int64(0)
92
- lpMaximumComponentLength := int64(0)
93
- lpFileSystemFlags := int64(0)
94
- lpFileSystemNameBuffer := make([]byte, 256)
95
- volpath, _ := syscall.UTF16PtrFromString(string(v) + ":/")
96
- driveret, _, err := provGetVolumeInformation.Call(
97
- uintptr(unsafe.Pointer(volpath)),
98
- uintptr(unsafe.Pointer(&lpVolumeNameBuffer[0])),
99
- uintptr(len(lpVolumeNameBuffer)),
100
- uintptr(unsafe.Pointer(&lpVolumeSerialNumber)),
101
- uintptr(unsafe.Pointer(&lpMaximumComponentLength)),
102
- uintptr(unsafe.Pointer(&lpFileSystemFlags)),
103
- uintptr(unsafe.Pointer(&lpFileSystemNameBuffer[0])),
104
- uintptr(len(lpFileSystemNameBuffer)))
105
- if driveret == 0 {
106
- if typeret == 5 {
107
- continue //device is not ready will happen if there is no disk in the drive
108
- }
109
- return ret, err
110
- }
111
- opts := "rw"
112
- if lpFileSystemFlags&FileReadOnlyVolume != 0 {
113
- opts = "ro"
114
- }
115
- if lpFileSystemFlags&FileFileCompression != 0 {
116
- opts += ".compress"
117
- }
118
-
119
- d := DiskPartitionStat{
120
- Mountpoint: path,
121
- Device: path,
122
- Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)),
123
- Opts: opts,
124
- }
125
- ret = append(ret, d)
126
- }
127
- }
128
- }
129
- return ret, nil
130
-}
131
-
132
-func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
133
- ret := make(map[string]DiskIOCountersStat, 0)
134
- var dst []Win32_PerfFormattedData
135
-
136
- err := wmi.Query("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk ", &dst)
137
- if err != nil {
138
- return ret, err
139
- }
140
- for _, d := range dst {
141
- if len(d.Name) > 3 { // not get _Total or Harddrive
142
- continue
143
- }
144
- ret[d.Name] = DiskIOCountersStat{
145
- Name: d.Name,
146
- ReadCount: uint64(d.AvgDiskReadQueueLength),
147
- WriteCount: d.AvgDiskWriteQueueLength,
148
- ReadBytes: uint64(d.AvgDiskBytesPerRead),
149
- WriteBytes: uint64(d.AvgDiskBytesPerWrite),
150
- ReadTime: d.AvgDisksecPerRead,
151
- WriteTime: d.AvgDisksecPerWrite,
152
- }
153
- }
154
- return ret, nil
155
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/types_freebsd.go
deleted
-85
@@ -1,85 +0,0 @@
1
-// +build ignore
2
-// Hand writing: _Ctype_struct___0
3
-
4
-/*
5
-Input to cgo -godefs.
6
-
7
-*/
8
-
9
-package disk
10
-
11
-/*
12
-#include <sys/types.h>
13
-#include <sys/mount.h>
14
-#include <devstat.h>
15
-
16
-enum {
17
- sizeofPtr = sizeof(void*),
18
-};
19
-
20
-// because statinfo has long double snap_time, redefine with changing long long
21
-struct statinfo2 {
22
- long cp_time[CPUSTATES];
23
- long tk_nin;
24
- long tk_nout;
25
- struct devinfo *dinfo;
26
- long long snap_time;
27
-};
28
-*/
29
-import "C"
30
-
31
-// Machine characteristics; for internal use.
32
-
33
-const (
34
- sizeofPtr = C.sizeofPtr
35
- sizeofShort = C.sizeof_short
36
- sizeofInt = C.sizeof_int
37
- sizeofLong = C.sizeof_long
38
- sizeofLongLong = C.sizeof_longlong
39
- sizeofLongDouble = C.sizeof_longlong
40
-
41
- DEVSTAT_NO_DATA = 0x00
42
- DEVSTAT_READ = 0x01
43
- DEVSTAT_WRITE = 0x02
44
- DEVSTAT_FREE = 0x03
45
-
46
- // from sys/mount.h
47
- MNT_RDONLY = 0x00000001 /* read only filesystem */
48
- MNT_SYNCHRONOUS = 0x00000002 /* filesystem written synchronously */
49
- MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */
50
- MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */
51
- MNT_UNION = 0x00000020 /* union with underlying filesystem */
52
- MNT_ASYNC = 0x00000040 /* filesystem written asynchronously */
53
- MNT_SUIDDIR = 0x00100000 /* special handling of SUID on dirs */
54
- MNT_SOFTDEP = 0x00200000 /* soft updates being done */
55
- MNT_NOSYMFOLLOW = 0x00400000 /* do not follow symlinks */
56
- MNT_GJOURNAL = 0x02000000 /* GEOM journal support enabled */
57
- MNT_MULTILABEL = 0x04000000 /* MAC support for individual objects */
58
- MNT_ACLS = 0x08000000 /* ACL support enabled */
59
- MNT_NOATIME = 0x10000000 /* disable update of file access time */
60
- MNT_NOCLUSTERR = 0x40000000 /* disable cluster read */
61
- MNT_NOCLUSTERW = 0x80000000 /* disable cluster write */
62
- MNT_NFS4ACLS = 0x00000010
63
-
64
- MNT_WAIT = 1 /* synchronously wait for I/O to complete */
65
- MNT_NOWAIT = 2 /* start all I/O, but do not wait for it */
66
- MNT_LAZY = 3 /* push data not written by filesystem syncer */
67
- MNT_SUSPEND = 4 /* Suspend file system after sync */
68
-
69
-)
70
-
71
-// Basic types
72
-
73
-type (
74
- _C_short C.short
75
- _C_int C.int
76
- _C_long C.long
77
- _C_long_long C.longlong
78
- _C_long_double C.longlong
79
-)
80
-
81
-type Statfs C.struct_statfs
82
-type Fsid C.struct_fsid
83
-
84
-type Devstat C.struct_devstat
85
-type Bintime C.struct_bintime
Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem.go
deleted
-38
@@ -1,38 +0,0 @@
1
-package mem
2
-
3
-import (
4
- "encoding/json"
5
-)
6
-
7
-type VirtualMemoryStat struct {
8
- Total uint64 `json:"total"`
9
- Available uint64 `json:"available"`
10
- Used uint64 `json:"used"`
11
- UsedPercent float64 `json:"used_percent"`
12
- Free uint64 `json:"free"`
13
- Active uint64 `json:"active"`
14
- Inactive uint64 `json:"inactive"`
15
- Buffers uint64 `json:"buffers"`
16
- Cached uint64 `json:"cached"`
17
- Wired uint64 `json:"wired"`
18
- Shared uint64 `json:"shared"`
19
-}
20
-
21
-type SwapMemoryStat struct {
22
- Total uint64 `json:"total"`
23
- Used uint64 `json:"used"`
24
- Free uint64 `json:"free"`
25
- UsedPercent float64 `json:"used_percent"`
26
- Sin uint64 `json:"sin"`
27
- Sout uint64 `json:"sout"`
28
-}
29
-
30
-func (m VirtualMemoryStat) String() string {
31
- s, _ := json.Marshal(m)
32
- return string(s)
33
-}
34
-
35
-func (m SwapMemoryStat) String() string {
36
- s, _ := json.Marshal(m)
37
- return string(s)
38
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin.go
deleted
-153
@@ -1,153 +0,0 @@
1
-// +build darwin
2
-
3
-package mem
4
-
5
-import (
6
- "os/exec"
7
- "strconv"
8
- "strings"
9
-
10
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
11
-)
12
-
13
-func getPageSize() (uint64, error) {
14
- out, err := exec.Command("pagesize").Output()
15
- if err != nil {
16
- return 0, err
17
- }
18
- o := strings.TrimSpace(string(out))
19
- p, err := strconv.ParseUint(o, 10, 64)
20
- if err != nil {
21
- return 0, err
22
- }
23
- return p, nil
24
-}
25
-
26
-// Runs vm_stat and returns Free and inactive pages
27
-func getVmStat(pagesize uint64, vms *VirtualMemoryStat) error {
28
- out, err := exec.Command("vm_stat").Output()
29
- if err != nil {
30
- return err
31
- }
32
- return parseVmStat(string(out), pagesize, vms)
33
-}
34
-
35
-func parseVmStat(out string, pagesize uint64, vms *VirtualMemoryStat) error {
36
- var err error
37
-
38
- lines := strings.Split(out, "\n")
39
- for _, line := range lines {
40
- fields := strings.Split(line, ":")
41
- if len(fields) < 2 {
42
- continue
43
- }
44
- key := strings.TrimSpace(fields[0])
45
- value := strings.Trim(fields[1], " .")
46
- switch key {
47
- case "Pages free":
48
- free, e := strconv.ParseUint(value, 10, 64)
49
- if e != nil {
50
- err = e
51
- }
52
- vms.Free = free * pagesize
53
- case "Pages inactive":
54
- inactive, e := strconv.ParseUint(value, 10, 64)
55
- if e != nil {
56
- err = e
57
- }
58
- vms.Cached += inactive * pagesize
59
- vms.Inactive = inactive * pagesize
60
- case "Pages active":
61
- active, e := strconv.ParseUint(value, 10, 64)
62
- if e != nil {
63
- err = e
64
- }
65
- vms.Active = active * pagesize
66
- case "Pages wired down":
67
- wired, e := strconv.ParseUint(value, 10, 64)
68
- if e != nil {
69
- err = e
70
- }
71
- vms.Wired = wired * pagesize
72
- case "Pages purgeable":
73
- purgeable, e := strconv.ParseUint(value, 10, 64)
74
- if e != nil {
75
- err = e
76
- }
77
- vms.Cached += purgeable * pagesize
78
- }
79
- }
80
- return err
81
-}
82
-
83
-// VirtualMemory returns VirtualmemoryStat.
84
-func VirtualMemory() (*VirtualMemoryStat, error) {
85
- ret := &VirtualMemoryStat{}
86
-
87
- p, err := getPageSize()
88
- if err != nil {
89
- return nil, err
90
- }
91
- t, err := common.DoSysctrl("hw.memsize")
92
- if err != nil {
93
- return nil, err
94
- }
95
- total, err := strconv.ParseUint(t[0], 10, 64)
96
- if err != nil {
97
- return nil, err
98
- }
99
- err = getVmStat(p, ret)
100
- if err != nil {
101
- return nil, err
102
- }
103
-
104
- ret.Available = ret.Free + ret.Cached
105
- ret.Total = total
106
-
107
- ret.Used = ret.Total - ret.Free
108
- ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0
109
-
110
- return ret, nil
111
-}
112
-
113
-// SwapMemory returns swapinfo.
114
-func SwapMemory() (*SwapMemoryStat, error) {
115
- var ret *SwapMemoryStat
116
-
117
- swapUsage, err := common.DoSysctrl("vm.swapusage")
118
- if err != nil {
119
- return ret, err
120
- }
121
-
122
- total := strings.Replace(swapUsage[2], "M", "", 1)
123
- used := strings.Replace(swapUsage[5], "M", "", 1)
124
- free := strings.Replace(swapUsage[8], "M", "", 1)
125
-
126
- total_v, err := strconv.ParseFloat(total, 64)
127
- if err != nil {
128
- return nil, err
129
- }
130
- used_v, err := strconv.ParseFloat(used, 64)
131
- if err != nil {
132
- return nil, err
133
- }
134
- free_v, err := strconv.ParseFloat(free, 64)
135
- if err != nil {
136
- return nil, err
137
- }
138
-
139
- u := float64(0)
140
- if total_v != 0 {
141
- u = ((total_v - free_v) / total_v) * 100.0
142
- }
143
-
144
- // vm.swapusage shows "M", multiply 1000
145
- ret = &SwapMemoryStat{
146
- Total: uint64(total_v * 1000),
147
- Used: uint64(used_v * 1000),
148
- Free: uint64(free_v * 1000),
149
- UsedPercent: u,
150
- }
151
-
152
- return ret, nil
153
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin_test.go
deleted
-67
@@ -1,67 +0,0 @@
1
-// +build darwin
2
-
3
-package mem
4
-
5
-import (
6
- "testing"
7
-)
8
-
9
-var vm_stat_out = `
10
-Mach Virtual Memory Statistics: (page size of 4096 bytes)
11
-Pages free: 105885.
12
-Pages active: 725641.
13
-Pages inactive: 449242.
14
-Pages speculative: 6155.
15
-Pages throttled: 0.
16
-Pages wired down: 560835.
17
-Pages purgeable: 128967.
18
-"Translation faults": 622528839.
19
-Pages copy-on-write: 17697839.
20
-Pages zero filled: 311034413.
21
-Pages reactivated: 4705104.
22
-Pages purged: 5605610.
23
-File-backed pages: 349192.
24
-Anonymous pages: 831846.
25
-Pages stored in compressor: 876507.
26
-Pages occupied by compressor: 249167.
27
-Decompressions: 4555025.
28
-Compressions: 7524729.
29
-Pageins: 40532443.
30
-Pageouts: 126496.
31
-Swapins: 2988073.
32
-Swapouts: 3283599.
33
-`
34
-
35
-func TestParseVmStat(t *testing.T) {
36
- ret := &VirtualMemoryStat{}
37
- err := parseVmStat(vm_stat_out, 4096, ret)
38
-
39
- if err != nil {
40
- t.Errorf("Expected no error, got %s\n", err.Error())
41
- }
42
-
43
- if ret.Free != uint64(105885*4096) {
44
- t.Errorf("Free pages, actual: %d, expected: %d", ret.Free,
45
- 105885*4096)
46
- }
47
-
48
- if ret.Inactive != uint64(449242*4096) {
49
- t.Errorf("Inactive pages, actual: %d, expected: %d", ret.Inactive,
50
- 449242*4096)
51
- }
52
-
53
- if ret.Active != uint64(725641*4096) {
54
- t.Errorf("Active pages, actual: %d, expected: %d", ret.Active,
55
- 725641*4096)
56
- }
57
-
58
- if ret.Wired != uint64(560835*4096) {
59
- t.Errorf("Wired pages, actual: %d, expected: %d", ret.Wired,
60
- 560835*4096)
61
- }
62
-
63
- if ret.Cached != uint64(128967*4096+449242.*4096) {
64
- t.Errorf("Cached pages, actual: %d, expected: %d", ret.Cached,
65
- 128967*4096+449242.*4096)
66
- }
67
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_freebsd.go
deleted
-129
@@ -1,129 +0,0 @@
1
-// +build freebsd
2
-
3
-package mem
4
-
5
-import (
6
- "os/exec"
7
- "strconv"
8
- "strings"
9
-
10
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
11
-)
12
-
13
-func VirtualMemory() (*VirtualMemoryStat, error) {
14
- pageSize, err := common.DoSysctrl("vm.stats.vm.v_page_size")
15
- if err != nil {
16
- return nil, err
17
- }
18
- p, err := strconv.ParseUint(pageSize[0], 10, 64)
19
- if err != nil {
20
- return nil, err
21
- }
22
-
23
- pageCount, err := common.DoSysctrl("vm.stats.vm.v_page_count")
24
- if err != nil {
25
- return nil, err
26
- }
27
- free, err := common.DoSysctrl("vm.stats.vm.v_free_count")
28
- if err != nil {
29
- return nil, err
30
- }
31
- active, err := common.DoSysctrl("vm.stats.vm.v_active_count")
32
- if err != nil {
33
- return nil, err
34
- }
35
- inactive, err := common.DoSysctrl("vm.stats.vm.v_inactive_count")
36
- if err != nil {
37
- return nil, err
38
- }
39
- cache, err := common.DoSysctrl("vm.stats.vm.v_cache_count")
40
- if err != nil {
41
- return nil, err
42
- }
43
- buffer, err := common.DoSysctrl("vfs.bufspace")
44
- if err != nil {
45
- return nil, err
46
- }
47
- wired, err := common.DoSysctrl("vm.stats.vm.v_wire_count")
48
- if err != nil {
49
- return nil, err
50
- }
51
-
52
- parsed := make([]uint64, 0, 7)
53
- vv := []string{
54
- pageCount[0],
55
- free[0],
56
- active[0],
57
- inactive[0],
58
- cache[0],
59
- buffer[0],
60
- wired[0],
61
- }
62
- for _, target := range vv {
63
- t, err := strconv.ParseUint(target, 10, 64)
64
- if err != nil {
65
- return nil, err
66
- }
67
- parsed = append(parsed, t)
68
- }
69
-
70
- ret := &VirtualMemoryStat{
71
- Total: parsed[0] * p,
72
- Free: parsed[1] * p,
73
- Active: parsed[2] * p,
74
- Inactive: parsed[3] * p,
75
- Cached: parsed[4] * p,
76
- Buffers: parsed[5],
77
- Wired: parsed[6] * p,
78
- }
79
-
80
- ret.Available = ret.Inactive + ret.Cached + ret.Free
81
- ret.Used = ret.Active + ret.Wired + ret.Cached
82
- ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0
83
-
84
- return ret, nil
85
-}
86
-
87
-// Return swapinfo
88
-// FreeBSD can have multiple swap devices. but use only first device
89
-func SwapMemory() (*SwapMemoryStat, error) {
90
- out, err := exec.Command("swapinfo").Output()
91
- if err != nil {
92
- return nil, err
93
- }
94
- var ret *SwapMemoryStat
95
- for _, line := range strings.Split(string(out), "\n") {
96
- values := strings.Fields(line)
97
- // skip title line
98
- if len(values) == 0 || values[0] == "Device" {
99
- continue
100
- }
101
-
102
- u := strings.Replace(values[4], "%", "", 1)
103
- total_v, err := strconv.ParseUint(values[1], 10, 64)
104
- if err != nil {
105
- return nil, err
106
- }
107
- used_v, err := strconv.ParseUint(values[2], 10, 64)
108
- if err != nil {
109
- return nil, err
110
- }
111
- free_v, err := strconv.ParseUint(values[3], 10, 64)
112
- if err != nil {
113
- return nil, err
114
- }
115
- up_v, err := strconv.ParseFloat(u, 64)
116
- if err != nil {
117
- return nil, err
118
- }
119
-
120
- ret = &SwapMemoryStat{
121
- Total: total_v,
122
- Used: used_v,
123
- Free: free_v,
124
- UsedPercent: up_v,
125
- }
126
- }
127
-
128
- return ret, nil
129
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go
deleted
-99
@@ -1,99 +0,0 @@
1
-// +build linux
2
-
3
-package mem
4
-
5
-import (
6
- "strconv"
7
- "strings"
8
- "syscall"
9
-
10
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
11
-)
12
-
13
-func VirtualMemory() (*VirtualMemoryStat, error) {
14
- filename := "/proc/meminfo"
15
- lines, _ := common.ReadLines(filename)
16
- // flag if MemAvailable is in /proc/meminfo (kernel 3.14+)
17
- memavail := false
18
-
19
- ret := &VirtualMemoryStat{}
20
- for _, line := range lines {
21
- fields := strings.Split(line, ":")
22
- if len(fields) != 2 {
23
- continue
24
- }
25
- key := strings.TrimSpace(fields[0])
26
- value := strings.TrimSpace(fields[1])
27
- value = strings.Replace(value, " kB", "", -1)
28
-
29
- t, err := strconv.ParseUint(value, 10, 64)
30
- if err != nil {
31
- return ret, err
32
- }
33
- switch key {
34
- case "MemTotal":
35
- ret.Total = t * 1024
36
- case "MemFree":
37
- ret.Free = t * 1024
38
- case "MemAvailable":
39
- memavail = true
40
- ret.Available = t * 1024
41
- case "Buffers":
42
- ret.Buffers = t * 1024
43
- case "Cached":
44
- ret.Cached = t * 1024
45
- case "Active":
46
- ret.Active = t * 1024
47
- case "Inactive":
48
- ret.Inactive = t * 1024
49
- }
50
- }
51
- if !memavail {
52
- ret.Available = ret.Free + ret.Buffers + ret.Cached
53
- }
54
- ret.Used = ret.Total - ret.Free
55
- ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0
56
-
57
- return ret, nil
58
-}
59
-
60
-func SwapMemory() (*SwapMemoryStat, error) {
61
- sysinfo := &syscall.Sysinfo_t{}
62
-
63
- if err := syscall.Sysinfo(sysinfo); err != nil {
64
- return nil, err
65
- }
66
- ret := &SwapMemoryStat{
67
- Total: uint64(sysinfo.Totalswap),
68
- Free: uint64(sysinfo.Freeswap),
69
- }
70
- ret.Used = ret.Total - ret.Free
71
- //check Infinity
72
- if ret.Total != 0 {
73
- ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0
74
- } else {
75
- ret.UsedPercent = 0
76
- }
77
- lines, _ := common.ReadLines("/proc/vmstat")
78
- for _, l := range lines {
79
- fields := strings.Fields(l)
80
- if len(fields) < 2 {
81
- continue
82
- }
83
- switch fields[0] {
84
- case "pswpin":
85
- value, err := strconv.ParseUint(fields[1], 10, 64)
86
- if err != nil {
87
- continue
88
- }
89
- ret.Sin = value * 4 * 1024
90
- case "pswpout":
91
- value, err := strconv.ParseUint(fields[1], 10, 64)
92
- if err != nil {
93
- continue
94
- }
95
- ret.Sout = value * 4 * 1024
96
- }
97
- }
98
- return ret, nil
99
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_test.go
deleted
-55
@@ -1,55 +0,0 @@
1
-package mem
2
-
3
-import (
4
- "fmt"
5
- "testing"
6
-)
7
-
8
-func TestVirtual_memory(t *testing.T) {
9
- v, err := VirtualMemory()
10
- if err != nil {
11
- t.Errorf("error %v", err)
12
- }
13
- empty := &VirtualMemoryStat{}
14
- if v == empty {
15
- t.Errorf("error %v", v)
16
- }
17
-}
18
-
19
-func TestSwap_memory(t *testing.T) {
20
- v, err := SwapMemory()
21
- if err != nil {
22
- t.Errorf("error %v", err)
23
- }
24
- empty := &SwapMemoryStat{}
25
- if v == empty {
26
- t.Errorf("error %v", v)
27
- }
28
-}
29
-
30
-func TestVirtualMemoryStat_String(t *testing.T) {
31
- v := VirtualMemoryStat{
32
- Total: 10,
33
- Available: 20,
34
- Used: 30,
35
- UsedPercent: 30.1,
36
- Free: 40,
37
- }
38
- e := `{"total":10,"available":20,"used":30,"used_percent":30.1,"free":40,"active":0,"inactive":0,"buffers":0,"cached":0,"wired":0,"shared":0}`
39
- if e != fmt.Sprintf("%v", v) {
40
- t.Errorf("VirtualMemoryStat string is invalid: %v", v)
41
- }
42
-}
43
-
44
-func TestSwapMemoryStat_String(t *testing.T) {
45
- v := SwapMemoryStat{
46
- Total: 10,
47
- Used: 30,
48
- Free: 40,
49
- UsedPercent: 30.1,
50
- }
51
- e := `{"total":10,"used":30,"free":40,"used_percent":30.1,"sin":0,"sout":0}`
52
- if e != fmt.Sprintf("%v", v) {
53
- t.Errorf("SwapMemoryStat string is invalid: %v", v)
54
- }
55
-}
Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_windows.go
deleted
-50
@@ -1,50 +0,0 @@
1
-// +build windows
2
-
3
-package mem
4
-
5
-import (
6
- "syscall"
7
- "unsafe"
8
-
9
- common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
10
-)
11
-
12
-var (
13
- procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
14
-)
15
-
16
-type MEMORYSTATUSEX struct {
17
- cbSize uint32
18
- dwMemoryLoad uint32
19
- ullTotalPhys uint64 // in bytes
20
- ullAvailPhys uint64
21
- ullTotalPageFile uint64
22
- ullAvailPageFile uint64
23
- ullTotalVirtual uint64
24
- ullAvailVirtual uint64
25
- ullAvailExtendedVirtual uint64
26
-}
27
-
28
-func VirtualMemory() (*VirtualMemoryStat, error) {
29
- var memInfo MEMORYSTATUSEX
30
- memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
31
- mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo)))
32
- if mem == 0 {
33
- return nil, syscall.GetLastError()
34
- }
35
-
36
- ret := &VirtualMemoryStat{
37
- Total: memInfo.ullTotalPhys,
38
- Available: memInfo.ullAvailPhys,
39
- UsedPercent: float64(memInfo.dwMemoryLoad),
40
- }
41
-
42
- ret.Used = ret.Total - ret.Available
43
- return ret, nil
44
-}
45
-
46
-func SwapMemory() (*SwapMemoryStat, error) {
47
- ret := &SwapMemoryStat{}
48
-
49
- return ret, nil
50
-}
Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info.go
new
+38
@@ -0,0 +1,38 @@
1
+package sysinfo
2
+
3
+import (
4
+ "errors"
5
+)
6
+
7
+var ErrPlatformNotSupported = errors.New("this operation is not supported on your platform")
8
+
9
+type DiskStats struct {
10
+ Free uint64
11
+ Total uint64
12
+ FsType string
13
+}
14
+
15
+var diskUsageImpl func(string) (*DiskStats, error)
16
+
17
+func DiskUsage(path string) (*DiskStats, error) {
18
+ if diskUsageImpl == nil {
19
+ return nil, ErrPlatformNotSupported
20
+ }
21
+
22
+ return diskUsageImpl(path)
23
+}
24
+
25
+type MemStats struct {
26
+ Swap uint64
27
+ Used uint64
28
+}
29
+
30
+var memInfoImpl func() (*MemStats, error)
31
+
32
+func MemoryInfo() (*MemStats, error) {
33
+ if memInfoImpl == nil {
34
+ return nil, ErrPlatformNotSupported
35
+ }
36
+
37
+ return memInfoImpl()
38
+}
Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_darwin.go
new
+32
@@ -0,0 +1,32 @@
1
+package sysinfo
2
+
3
+import (
4
+ "fmt"
5
+ "syscall"
6
+)
7
+
8
+func init() {
9
+ diskUsageImpl = darwinDiskUsage
10
+ memInfoImpl = darwinMemInfo
11
+}
12
+
13
+func darwinDiskUsage(path string) (*DiskStats, error) {
14
+ var stfst syscall.Statfs_t
15
+ err := syscall.Statfs(path, &stfst)
16
+ if err != nil {
17
+ return nil, err
18
+ }
19
+
20
+ free := stfst.Bfree * uint64(stfst.Bsize)
21
+ total := stfst.Bavail * uint64(stfst.Bsize)
22
+ return &DiskStats{
23
+ Free: free,
24
+ Total: total,
25
+ FsType: fmt.Sprint(stfst.Type),
26
+ }, nil
27
+}
28
+
29
+func darwinMemInfo() (*MemStats, error) {
30
+ // TODO: use vm_stat on osx to gather memory information
31
+ return new(MemStats), nil
32
+}
Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_linux.go
new
+70
@@ -0,0 +1,70 @@
1
+package sysinfo
2
+
3
+import (
4
+ "bytes"
5
+ "fmt"
6
+ "io/ioutil"
7
+ "strings"
8
+ "syscall"
9
+
10
+ humanize "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/go-humanize"
11
+)
12
+
13
+func init() {
14
+ diskUsageImpl = linuxDiskUsage
15
+ memInfoImpl = linuxMemInfo
16
+}
17
+
18
+func linuxDiskUsage(path string) (*DiskStats, error) {
19
+ var stfst syscall.Statfs_t
20
+ err := syscall.Statfs(path, &stfst)
21
+ if err != nil {
22
+ return nil, err
23
+ }
24
+
25
+ free := stfst.Bfree * uint64(stfst.Bsize)
26
+ total := stfst.Bavail * uint64(stfst.Bsize)
27
+ return &DiskStats{
28
+ Free: free,
29
+ Total: total,
30
+ FsType: fmt.Sprint(stfst.Type),
31
+ }, nil
32
+}
33
+
34
+func linuxMemInfo() (*MemStats, error) {
35
+ info, err := ioutil.ReadFile("/proc/self/status")
36
+ if err != nil {
37
+ return nil, err
38
+ }
39
+
40
+ var stats MemStats
41
+ for _, e := range bytes.Split(info, []byte("\n")) {
42
+ if !bytes.HasPrefix(e, []byte("Vm")) {
43
+ continue
44
+ }
45
+
46
+ parts := bytes.Split(e, []byte(":"))
47
+ if len(parts) != 2 {
48
+ return nil, fmt.Errorf("unexpected line in proc stats: %q", string(e))
49
+ }
50
+
51
+ val := strings.Trim(string(parts[1]), " \n\t")
52
+ switch string(parts[0]) {
53
+ case "VmSize":
54
+ vmsize, err := humanize.ParseBytes(val)
55
+ if err != nil {
56
+ return nil, err
57
+ }
58
+
59
+ stats.Used = vmsize
60
+ case "VmSwap":
61
+ swapsize, err := humanize.ParseBytes(val)
62
+ if err != nil {
63
+ return nil, err
64
+ }
65
+
66
+ stats.Swap = swapsize
67
+ }
68
+ }
69
+ return &stats, nil
70
+}
cmd/ipfs/goreq.go
deleted
-3
@@ -1,3 +0,0 @@
1
-// +build !go1.5
2
-
3
-`IPFS needs to be built with go version 1.5 or greater`
core/commands/sysdiag.go
+6
-12
@@ -9,8 +9,7 @@ import (
9
config "github.com/ipfs/go-ipfs/repo/config"
10
11
manet "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
12
- psud "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/disk"
13
- psum "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/mem"
12
+ sysi "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo"
13
)
14
15
var sysDiagCmd = &cmds.Command{
@@ -91,14 +90,13 @@ func ipfsPath() string {
90
91
func diskSpaceInfo(out map[string]interface{}) error {
92
di := make(map[string]interface{})
94
- dinfo, err := psud.DiskUsage(ipfsPath())
93
+ dinfo, err := sysi.DiskUsage(ipfsPath())
94
if err != nil {
95
return err
96
}
97
99
- di["fstype"] = dinfo.Fstype
98
+ di["fstype"] = dinfo.FsType
99
di["total_space"] = dinfo.Total
101
- di["used_space"] = dinfo.Used
100
di["free_space"] = dinfo.Free
101
102
out["diskinfo"] = di
@@ -107,18 +105,14 @@ func diskSpaceInfo(out map[string]interface{}) error {
105
106
func memInfo(out map[string]interface{}) error {
107
m := make(map[string]interface{})
110
- swap, err := psum.SwapMemory()
111
- if err != nil {
112
- return err
113
- }
108
115
- virt, err := psum.VirtualMemory()
109
+ meminf, err := sysi.MemoryInfo()
110
if err != nil {
111
return err
112
}
113
120
- m["swap"] = swap
121
- m["virt"] = virt
114
+ m["swap"] = meminf.Swap
115
+ m["virt"] = meminf.Used
116
out["memory"] = m
117
return nil
118
}
util/sadhack/godep.go
-4
@@ -7,7 +7,3 @@ import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/go-hum
7
// imported by chegga/pb on windows, this is here so running godeps on non-windows doesnt
8
// drop it from our vendoring
9
import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/olekukonko/ts"
10
-
11
-// these two are for diagnostics on windows systems
12
-import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/StackExchange/wmi"
13
-import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"