Merge lp:~mandel/ubuntu-download-manager/remove-username-password-update into lp:ubuntu-download-manager
- remove-username-password-update
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~mandel/ubuntu-download-manager/remove-username-password-update |
Merge into: | lp:ubuntu-download-manager |
Prerequisite: | lp:~mandel/ubuntu-download-manager/upload-go-bindings |
Diff against target: |
1835 lines (+11/-1702) 13 files modified
bindings/golang/common.go (+0/-78) bindings/golang/common_test.go (+0/-83) bindings/golang/downloader.go (+0/-600) bindings/golang/downloader_test.go (+0/-306) bindings/golang/uploader.go (+0/-396) bindings/golang/uploader_test.go (+0/-215) docs/com.canonical.applications.upload_manager.xml (+0/-2) src/uploads/priv/ubuntu/uploads/factory.cpp (+2/-4) src/uploads/priv/ubuntu/uploads/factory.h (+1/-3) src/uploads/priv/ubuntu/uploads/manager.cpp (+4/-7) src/uploads/priv/ubuntu/uploads/manager.h (+1/-3) src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp (+2/-2) src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h (+1/-3) |
To merge this branch: | bzr merge lp:~mandel/ubuntu-download-manager/remove-username-password-update |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Ubuntu One hackers | Pending | ||
Review via email: mp+217258@code.launchpad.net |
This proposal has been superseded by a proposal from 2014-05-21.
Commit message
Remove the username and password from mms uploads.
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
- 262. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:262
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 263. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update. - 264. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:264
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 265. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:265
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 266. By Manuel de la Peña
-
Merged upload-go-bindings into remove-
username- password- update.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:266
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 267. By Manuel de la Peña
-
Fix merge issues due to the removal of go.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:267
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Unmerged revisions
Preview Diff
1 | === removed directory 'bindings' |
2 | === removed directory 'bindings/golang' |
3 | === removed file 'bindings/golang/common.go' |
4 | --- bindings/golang/common.go 2014-05-13 08:50:46 +0000 |
5 | +++ bindings/golang/common.go 1970-01-01 00:00:00 +0000 |
6 | @@ -1,78 +0,0 @@ |
7 | -/* |
8 | - * Copyright 2014 Canonical Ltd. |
9 | - * |
10 | - * Authors: |
11 | - * Manuel de la Pena: manuel.delapena@canonical.com |
12 | - * |
13 | - * This file is part of ubuntu-download-manager. |
14 | - * |
15 | - * ubuntu-download-manager is free software; you can redistribute it and/or modify |
16 | - * it under the terms of the GNU General Public License as published by |
17 | - * the Free Software Foundation; version 3. |
18 | - * |
19 | - * ubuntu-download-manager is distributed in the hope that it will be useful, |
20 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | - * GNU General Public License for more details. |
23 | - * |
24 | - * You should have received a copy of the GNU General Public License |
25 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 | - */ |
27 | - |
28 | -// Package udm provides a go interface to work with the ubuntu download manager |
29 | -package udm |
30 | - |
31 | -import ( |
32 | - "launchpad.net/go-dbus/v1" |
33 | -) |
34 | - |
35 | -// Progress provides how much progress has been performed in a download that was |
36 | -// already started. |
37 | -type Progress struct { |
38 | - Received uint64 |
39 | - Total uint64 |
40 | -} |
41 | - |
42 | -// internal interface used to simplify testing |
43 | -type watch interface { |
44 | - Cancel() error |
45 | - Chanel() chan *dbus.Message |
46 | -} |
47 | - |
48 | -// small wrapper used to simplify testing by using the watch interface |
49 | -type watchWrapper struct { |
50 | - watch *dbus.SignalWatch |
51 | -} |
52 | - |
53 | -func newWatchWrapper(sw *dbus.SignalWatch) *watchWrapper { |
54 | - w := watchWrapper{} |
55 | - return &w |
56 | -} |
57 | - |
58 | -func (w *watchWrapper) Cancel() error { |
59 | - return w.watch.Cancel() |
60 | -} |
61 | - |
62 | -func (w *watchWrapper) Chanel() chan *dbus.Message { |
63 | - return w.watch.C |
64 | -} |
65 | - |
66 | -// interface added to simplify testing |
67 | -type proxy interface { |
68 | - Call(iface, method string, args ...interface{}) (*dbus.Message, error) |
69 | -} |
70 | - |
71 | -var readArgs = func(msg *dbus.Message, args ...interface{}) error { |
72 | - return msg.Args(args) |
73 | -} |
74 | - |
75 | -func connectToSignal(conn *dbus.Connection, path dbus.ObjectPath, signal string) (watch, error) { |
76 | - sw, err := conn.WatchSignal(&dbus.MatchRule{ |
77 | - Type: dbus.TypeSignal, |
78 | - Sender: DOWNLOAD_SERVICE, |
79 | - Interface: DOWNLOAD_INTERFACE, |
80 | - Member: signal, |
81 | - Path: path}) |
82 | - w := newWatchWrapper(sw) |
83 | - return w, err |
84 | -} |
85 | |
86 | === removed file 'bindings/golang/common_test.go' |
87 | --- bindings/golang/common_test.go 2014-05-13 08:50:46 +0000 |
88 | +++ bindings/golang/common_test.go 1970-01-01 00:00:00 +0000 |
89 | @@ -1,83 +0,0 @@ |
90 | -/* |
91 | - * Copyright 2014 Canonical Ltd. |
92 | - * |
93 | - * Authors: |
94 | - * Manuel de la Pena: manuel.delapena@canonical.com |
95 | - * |
96 | - * This file is part of ubuntu-download-manager. |
97 | - * |
98 | - * ubuntu-download-manager is free software; you can redistribute it and/or modify |
99 | - * it under the terms of the GNU General Public License as published by |
100 | - * the Free Software Foundation; version 3. |
101 | - * |
102 | - * ubuntu-download-manager is distributed in the hope that it will be useful, |
103 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
104 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
105 | - * GNU General Public License for more details. |
106 | - * |
107 | - * You should have received a copy of the GNU General Public License |
108 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
109 | - */ |
110 | - |
111 | -package udm |
112 | - |
113 | -import ( |
114 | - . "gopkg.in/check.v1" |
115 | - "launchpad.net/go-dbus/v1" |
116 | - "testing" |
117 | -) |
118 | - |
119 | -func Test(t *testing.T) { TestingT(t) } |
120 | - |
121 | -type fakeProxy struct { |
122 | - Interface string |
123 | - MethodName string |
124 | - Args []interface{} |
125 | - Err error |
126 | - Result *dbus.Message |
127 | -} |
128 | - |
129 | -func (f *fakeProxy) Call(iface, method string, args ...interface{}) (*dbus.Message, error) { |
130 | - // store the called method and return Result |
131 | - f.Interface = iface |
132 | - f.MethodName = method |
133 | - f.Args = args |
134 | - if f.Err == nil { |
135 | - return f.Result, nil |
136 | - } |
137 | - return nil, f.Err |
138 | -} |
139 | - |
140 | -type FakeWatch struct { |
141 | - Canceled bool |
142 | - Ch chan *dbus.Message |
143 | -} |
144 | - |
145 | -func newFakeWatch() *FakeWatch { |
146 | - ch := make(chan *dbus.Message) |
147 | - fw := FakeWatch{false, ch} |
148 | - return &fw |
149 | -} |
150 | - |
151 | -func (w *FakeWatch) Cancel() error { |
152 | - w.Canceled = true |
153 | - return nil |
154 | -} |
155 | - |
156 | -func (w *FakeWatch) Chanel() chan *dbus.Message { |
157 | - return w.Ch |
158 | -} |
159 | - |
160 | -// returns a new error that can be used in the tests |
161 | -func newDBusError() *dbus.Message { |
162 | - msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method") |
163 | - msg.Type = dbus.TypeError |
164 | - msg.ErrorName = "com.testing.udm" |
165 | - return msg |
166 | -} |
167 | - |
168 | -func newDBusReturn() *dbus.Message { |
169 | - msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method") |
170 | - msg.Type = dbus.TypeMethodReturn |
171 | - return msg |
172 | -} |
173 | |
174 | === removed file 'bindings/golang/downloader.go' |
175 | --- bindings/golang/downloader.go 2014-05-13 08:50:46 +0000 |
176 | +++ bindings/golang/downloader.go 1970-01-01 00:00:00 +0000 |
177 | @@ -1,600 +0,0 @@ |
178 | -/* |
179 | - * Copyright 2014 Canonical Ltd. |
180 | - * |
181 | - * Authors: |
182 | - * Manuel de la Pena: manuel.delapena@canonical.com |
183 | - * |
184 | - * This file is part of ubuntu-download-manager. |
185 | - * |
186 | - * ubuntu-download-manager is free software; you can redistribute it and/or modify |
187 | - * it under the terms of the GNU General Public License as published by |
188 | - * the Free Software Foundation; version 3. |
189 | - * |
190 | - * ubuntu-download-manager is distributed in the hope that it will be useful, |
191 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
192 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
193 | - * GNU General Public License for more details. |
194 | - * |
195 | - * You should have received a copy of the GNU General Public License |
196 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
197 | - */ |
198 | - |
199 | -// Package udm provides a go interface to work with the ubuntu download manager |
200 | -package udm |
201 | - |
202 | -import ( |
203 | - "errors" |
204 | - "fmt" |
205 | - "launchpad.net/go-dbus/v1" |
206 | - "runtime" |
207 | -) |
208 | - |
209 | -const ( |
210 | - DOWNLOAD_SERVICE = "com.canonical.applications.Downloader" |
211 | - DOWNLOAD_INTERFACE = "com.canonical.applications.Download" |
212 | - DOWNLOAD_MANAGER_INTERFACE = "com.canonical.applications.DownloadManager" |
213 | -) |
214 | - |
215 | -type hashType string |
216 | - |
217 | -const ( |
218 | - MD5 hashType = "md5" |
219 | - SHA1 hashType = "sha1" |
220 | - SHA224 hashType = "sha224" |
221 | - SHA256 hashType = "sha256" |
222 | - SHA384 hashType = "sha384" |
223 | - SHA512 hashType = "sha512" |
224 | -) |
225 | - |
226 | -const ( |
227 | - LOCAL_PATH = "local-path" |
228 | - OBJECT_PATH = "objectpath" |
229 | - POST_DOWNLOAD_COMMAND = "post-download-command" |
230 | -) |
231 | - |
232 | -// Download is the common interface of a download. It provides all the required |
233 | -// methods to interact with a download created by udm. |
234 | -type Download interface { |
235 | - TotalSize() (uint64, error) |
236 | - Progress() (uint64, error) |
237 | - Metadata() (map[string]string, error) |
238 | - SetThrottle(uint64) error |
239 | - Throttle() (uint64, error) |
240 | - AllowMobileDownload(bool) error |
241 | - SetDestinationDir(string) error |
242 | - IsMobileDownload() (bool, error) |
243 | - Start() error |
244 | - Pause() error |
245 | - Resume() error |
246 | - Cancel() error |
247 | - Started() chan bool |
248 | - Paused() chan bool |
249 | - DownloadProgress() chan Progress |
250 | - Resumed() chan bool |
251 | - Canceled() chan bool |
252 | - Finished() chan string |
253 | - Error() chan error |
254 | -} |
255 | - |
256 | -// FileDownload represents a single file being downloaded by udm. |
257 | -type FileDownload struct { |
258 | - conn *dbus.Connection |
259 | - proxy proxy |
260 | - path dbus.ObjectPath |
261 | - started chan bool |
262 | - started_w watch |
263 | - paused chan bool |
264 | - paused_w watch |
265 | - resumed chan bool |
266 | - resumed_w watch |
267 | - canceled chan bool |
268 | - canceled_w watch |
269 | - finished chan string |
270 | - finished_w watch |
271 | - errors chan error |
272 | - error_w watch |
273 | - progress chan Progress |
274 | - progress_w watch |
275 | -} |
276 | - |
277 | -func (down *FileDownload) free() { |
278 | - // cancel all watches so that goroutines are done and close the |
279 | - // channels |
280 | - down.started_w.Cancel() |
281 | - down.paused_w.Cancel() |
282 | - down.resumed_w.Cancel() |
283 | - down.canceled_w.Cancel() |
284 | - down.finished_w.Cancel() |
285 | - down.error_w.Cancel() |
286 | - down.progress_w.Cancel() |
287 | -} |
288 | - |
289 | -func cleanDownloadData(down *FileDownload) { |
290 | - down.free() |
291 | -} |
292 | - |
293 | -func newFileDownload(conn *dbus.Connection, path dbus.ObjectPath) (*FileDownload, error) { |
294 | - proxy := conn.Object(DOWNLOAD_SERVICE, path) |
295 | - started_ch := make(chan bool) |
296 | - started_w, err := connectToSignal(conn, path, "started") |
297 | - if err != nil { |
298 | - return nil, err |
299 | - } |
300 | - |
301 | - paused_ch := make(chan bool) |
302 | - paused_w, err := connectToSignal(conn, path, "paused") |
303 | - if err != nil { |
304 | - return nil, err |
305 | - } |
306 | - |
307 | - resumed_ch := make(chan bool) |
308 | - resumed_w, err := connectToSignal(conn, path, "resumed") |
309 | - if err != nil { |
310 | - return nil, err |
311 | - } |
312 | - |
313 | - canceled_ch := make(chan bool) |
314 | - canceled_w, err := connectToSignal(conn, path, "canceled") |
315 | - if err != nil { |
316 | - return nil, err |
317 | - } |
318 | - |
319 | - finished_ch := make(chan string) |
320 | - finished_w, err := connectToSignal(conn, path, "finished") |
321 | - if err != nil { |
322 | - return nil, err |
323 | - } |
324 | - |
325 | - errors_ch := make(chan error) |
326 | - errors_w, err := connectToSignal(conn, path, "error") |
327 | - if err != nil { |
328 | - return nil, err |
329 | - } |
330 | - |
331 | - progress_ch := make(chan Progress) |
332 | - progress_w, err := connectToSignal(conn, path, "progress") |
333 | - if err != nil { |
334 | - return nil, err |
335 | - } |
336 | - |
337 | - d := FileDownload{conn, proxy, path, started_ch, started_w, paused_ch, paused_w, resumed_ch, resumed_w, canceled_ch, canceled_w, finished_ch, finished_w, errors_ch, errors_w, progress_ch, progress_w} |
338 | - |
339 | - // connect to the diff signals so that we have nice channels that do |
340 | - // not expose dbus watchers |
341 | - d.connectToStarted() |
342 | - d.connectToPaused() |
343 | - d.connectToResumed() |
344 | - d.connectToCanceled() |
345 | - d.connectToFinished() |
346 | - d.connectToError() |
347 | - d.connectToProgress() |
348 | - runtime.SetFinalizer(&d, cleanDownloadData) |
349 | - return &d, nil |
350 | -} |
351 | - |
352 | -// TotalSize returns the total size of the file being downloaded. |
353 | -func (down *FileDownload) TotalSize() (size uint64, err error) { |
354 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "totalSize") |
355 | - if err != nil { |
356 | - return 0, err |
357 | - } |
358 | - |
359 | - if reply.Type == dbus.TypeError { |
360 | - return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) |
361 | - } |
362 | - |
363 | - if err = readArgs(reply, &size); err != nil { |
364 | - return 0, err |
365 | - } |
366 | - return size, nil |
367 | -} |
368 | - |
369 | -// Process returns the process so far in downloading the file. |
370 | -func (down *FileDownload) Progress() (progress uint64, err error) { |
371 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "progress") |
372 | - if err != nil { |
373 | - return 0, err |
374 | - } |
375 | - |
376 | - if reply.Type == dbus.TypeError { |
377 | - return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) |
378 | - } |
379 | - |
380 | - if err = readArgs(reply, &progress); err != nil { |
381 | - return 0, err |
382 | - } |
383 | - return progress, nil |
384 | -} |
385 | - |
386 | -// Metadata returns the metadata that was provided at creating time to the download. |
387 | -func (down *FileDownload) Metadata() (metadata map[string]string, err error) { |
388 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "metadata") |
389 | - if err != nil { |
390 | - return nil, err |
391 | - } |
392 | - |
393 | - if reply.Type == dbus.TypeError { |
394 | - return nil, fmt.Errorf("DBus Error: %", reply.ErrorName) |
395 | - } |
396 | - |
397 | - if err = readArgs(reply, &metadata); err != nil { |
398 | - return nil, err |
399 | - } |
400 | - return metadata, nil |
401 | -} |
402 | - |
403 | -// SetThrottle sets the network throttle to be used in the download. |
404 | -func (down *FileDownload) SetThrottle(throttle uint64) (err error) { |
405 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setThrottle", throttle) |
406 | - if err != nil { |
407 | - return err |
408 | - } |
409 | - |
410 | - if reply.Type == dbus.TypeError { |
411 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
412 | - } |
413 | - |
414 | - return nil |
415 | -} |
416 | - |
417 | -// Throttle returns the network throttle that is currently used in the download. |
418 | -func (down *FileDownload) Throttle() (throttle uint64, err error) { |
419 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "throttle") |
420 | - if err != nil { |
421 | - return 0, err |
422 | - } |
423 | - |
424 | - if reply.Type == dbus.TypeError { |
425 | - return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) |
426 | - } |
427 | - |
428 | - if err = readArgs(reply, &throttle); err != nil { |
429 | - return 0, err |
430 | - } |
431 | - return throttle, nil |
432 | -} |
433 | - |
434 | -// AllowMobileDownload returns if the download is allow to use the mobile connect |
435 | -// connection. |
436 | -func (down *FileDownload) AllowMobileDownload(allowed bool) (err error) { |
437 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "allowGSMDownload", allowed) |
438 | - if err != nil { |
439 | - return err |
440 | - } |
441 | - |
442 | - if reply.Type == dbus.TypeError { |
443 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
444 | - } |
445 | - |
446 | - return nil |
447 | -} |
448 | - |
449 | -// SetDestinationDir permits unconfined applications to set the destination |
450 | -// directory of the download. This method must be called BEFORE the download |
451 | -// is started else an error will be returned. |
452 | -func (down *FileDownload) SetDestinationDir(path string) (err error) { |
453 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setDestinationDir", path) |
454 | - if err != nil { |
455 | - return err |
456 | - } |
457 | - |
458 | - if reply.Type == dbus.TypeError { |
459 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
460 | - } |
461 | - |
462 | - return nil |
463 | -} |
464 | - |
465 | -// IsMobileDownload returns if the download will be performed over the mobile data. |
466 | -func (down *FileDownload) IsMobileDownload() (allowed bool, err error) { |
467 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "isGSMDownloadAllowed", allowed) |
468 | - if err != nil { |
469 | - return false, err |
470 | - } |
471 | - |
472 | - if reply.Type == dbus.TypeError { |
473 | - return false, fmt.Errorf("DBus Error: %", reply.ErrorName) |
474 | - } |
475 | - |
476 | - if err = readArgs(reply, &allowed); err != nil { |
477 | - return false, err |
478 | - } |
479 | - return allowed, nil |
480 | -} |
481 | - |
482 | -// Start tells udm that the download is ready to be peformed and that the client is |
483 | -// ready to recieve signals. The following is a common pattern to be used when |
484 | -// creating downloads in udm. |
485 | -// |
486 | -// man, err := udm.NewDownloadManager() |
487 | -// if err != nil { |
488 | -// } |
489 | -// |
490 | -// // variables used to create the download |
491 | -// |
492 | -// url := "http://www.python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz" |
493 | -// hash := "8af44d33ea3a1528fc56b3a362924500" |
494 | -// hashAlgo := MD5 |
495 | -// var metadata map[string]interface{} |
496 | -// var headers map[string]string |
497 | -// |
498 | -// // create the download BUT do not start downloading just yet |
499 | -// down, err := man.CreateDownload(url, hash, hashAlgo, metadata, headers) |
500 | -// |
501 | -// // connect routines to the download channels so that we can get the |
502 | -// // information of the download the channel will not get any data until the |
503 | -// // Start is called. |
504 | -// |
505 | -// started_signal := down.Started() |
506 | -// go func() { |
507 | -// <-started_signal |
508 | -// fmt.Println("Download started") |
509 | -// }() |
510 | -// progress_signal := down.DownloadProgress() |
511 | -// go func() { |
512 | -// for progress := range p { |
513 | -// fmt.Printf("Recieved %d out of %d\n", progress.Received, progress.Total) |
514 | -// } |
515 | -// }() |
516 | -// |
517 | -// finished_signal := down.Finished() |
518 | -// |
519 | -// // start download |
520 | -// down.Start() |
521 | -// |
522 | -// // block until we are finished downloading |
523 | -// <- finished_signal |
524 | -func (down *FileDownload) Start() (err error) { |
525 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "start") |
526 | - if err != nil { |
527 | - return err |
528 | - } |
529 | - |
530 | - if reply.Type == dbus.TypeError { |
531 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
532 | - } |
533 | - |
534 | - return nil |
535 | -} |
536 | - |
537 | -// Pause pauses a download that was started and if not nothing is done. |
538 | -func (down *FileDownload) Pause() (err error) { |
539 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "pause") |
540 | - if err != nil { |
541 | - return err |
542 | - } |
543 | - |
544 | - if reply.Type == dbus.TypeError { |
545 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
546 | - } |
547 | - |
548 | - return nil |
549 | -} |
550 | - |
551 | -// Resumes a download that was paused or does nothing otherwise. |
552 | -func (down *FileDownload) Resume() (err error) { |
553 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "resume") |
554 | - if err != nil { |
555 | - return err |
556 | - } |
557 | - |
558 | - if reply.Type == dbus.TypeError { |
559 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
560 | - } |
561 | - |
562 | - return nil |
563 | -} |
564 | - |
565 | -// Cancel cancels a download that was in process and deletes any local files |
566 | -// that were created. |
567 | -func (down *FileDownload) Cancel() (err error) { |
568 | - reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "cancel") |
569 | - if err != nil { |
570 | - return err |
571 | - } |
572 | - |
573 | - if reply.Type == dbus.TypeError { |
574 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
575 | - } |
576 | - |
577 | - return nil |
578 | -} |
579 | - |
580 | -func (down *FileDownload) connectToStarted() { |
581 | - go func() { |
582 | - for msg := range down.started_w.Chanel() { |
583 | - var started bool |
584 | - readArgs(msg, &started) |
585 | - down.started <- started |
586 | - } |
587 | - close(down.started) |
588 | - }() |
589 | -} |
590 | - |
591 | -// Started returns a channel that will be used to communicate the started signals. |
592 | -func (down *FileDownload) Started() chan bool { |
593 | - return down.started |
594 | -} |
595 | - |
596 | -func (down *FileDownload) connectToPaused() { |
597 | - go func() { |
598 | - for msg := range down.paused_w.Chanel() { |
599 | - var paused bool |
600 | - readArgs(msg, &paused) |
601 | - down.paused <- paused |
602 | - } |
603 | - close(down.paused) |
604 | - }() |
605 | -} |
606 | - |
607 | -// Paused returns a channel that will be used to communicate the paused signals. |
608 | -func (down *FileDownload) Paused() chan bool { |
609 | - return down.paused |
610 | -} |
611 | - |
612 | -func (down *FileDownload) connectToProgress() { |
613 | - go func() { |
614 | - for msg := range down.progress_w.Chanel() { |
615 | - var received uint64 |
616 | - var total uint64 |
617 | - readArgs(msg, &received, &total) |
618 | - down.progress <- Progress{received, total} |
619 | - } |
620 | - close(down.progress) |
621 | - }() |
622 | -} |
623 | - |
624 | -// DownloadProgress returns a channel that will be used to communicate the progress |
625 | -// signals. |
626 | -func (down *FileDownload) DownloadProgress() chan Progress { |
627 | - return down.progress |
628 | -} |
629 | - |
630 | -func (down *FileDownload) connectToResumed() { |
631 | - go func() { |
632 | - for msg := range down.resumed_w.Chanel() { |
633 | - var resumed bool |
634 | - readArgs(msg, &resumed) |
635 | - down.resumed <- resumed |
636 | - } |
637 | - close(down.resumed) |
638 | - }() |
639 | -} |
640 | - |
641 | -// Resumed returns a channel that will be used to communicate the paused signals. |
642 | -func (down *FileDownload) Resumed() chan bool { |
643 | - return down.resumed |
644 | -} |
645 | - |
646 | -func (down *FileDownload) connectToCanceled() { |
647 | - go func() { |
648 | - for msg := range down.canceled_w.Chanel() { |
649 | - var canceled bool |
650 | - readArgs(msg, &canceled) |
651 | - down.canceled <- canceled |
652 | - } |
653 | - close(down.canceled) |
654 | - }() |
655 | -} |
656 | - |
657 | -// Canceled returns a channel that will be used to communicate the canceled signals. |
658 | -func (down *FileDownload) Canceled() chan bool { |
659 | - return down.canceled |
660 | -} |
661 | - |
662 | -func (down *FileDownload) connectToFinished() { |
663 | - go func() { |
664 | - for msg := range down.finished_w.Chanel() { |
665 | - var path string |
666 | - readArgs(msg, &path) |
667 | - down.finished <- path |
668 | - } |
669 | - close(down.finished) |
670 | - }() |
671 | -} |
672 | - |
673 | -// Finished returns a channel that will ne used to communicate the finished signals. |
674 | -func (down *FileDownload) Finished() chan string { |
675 | - return down.finished |
676 | -} |
677 | - |
678 | -func (down *FileDownload) connectToError() { |
679 | - go func() { |
680 | - for msg := range down.error_w.Chanel() { |
681 | - var reason string |
682 | - readArgs(msg, &reason) |
683 | - down.errors <- errors.New(reason) |
684 | - } |
685 | - close(down.errors) |
686 | - }() |
687 | -} |
688 | - |
689 | -// Error returns the channel that will be used to communicate the error signals. |
690 | -func (down *FileDownload) Error() chan error { |
691 | - return down.errors |
692 | -} |
693 | - |
694 | -type DownloadManager struct { |
695 | - conn *dbus.Connection |
696 | - proxy *dbus.ObjectProxy |
697 | -} |
698 | - |
699 | -// NewDownloadManager creates a new manager that can be used to create download in the |
700 | -// udm daemon. |
701 | -func NewDownloadManager() (*DownloadManager, error) { |
702 | - conn, err := dbus.Connect(dbus.SessionBus) |
703 | - if err != nil { |
704 | - return nil, err |
705 | - } |
706 | - |
707 | - if err != nil { |
708 | - return nil, err |
709 | - } |
710 | - |
711 | - proxy := conn.Object(DOWNLOAD_SERVICE, "/") |
712 | - d := DownloadManager{conn, proxy} |
713 | - return &d, nil |
714 | -} |
715 | - |
716 | -// CreateDownload creates a new download in the udm daemon that can be used to get |
717 | -// a remote resource. Udm allows to pass a hash signature and method that will be |
718 | -// check once the download has been complited. |
719 | -// |
720 | -// The download hash can be one of the the following constants: |
721 | -// |
722 | -// MD5 |
723 | -// SHA1 |
724 | -// SHA224 |
725 | -// SHA256 |
726 | -// SHA384 |
727 | -// SHA512 |
728 | -// |
729 | -// The metadata attribute can be used to pass extra information to the udm daemon |
730 | -// that will just be considered if the caller is not a apparmor confined application. |
731 | -// |
732 | -// LOCAL_PATH => allows to provide the local path for the download. |
733 | -// OBJECT_PATH => allows to provide the object path to be used in the dbus daemon. |
734 | -// POST_DOWNLOAD_COMMAND => allows to provide a command that will be executed on the |
735 | -// download |
736 | -// |
737 | -// The headers attribute allows to provide extra headers to be used in the request used |
738 | -// to perform the download. |
739 | -func (man *DownloadManager) CreateDownload(url string, hash string, algo hashType, metadata map[string]interface{}, headers map[string]string) (down Download, err error) { |
740 | - var t map[string]*dbus.Variant |
741 | - for key, value := range metadata { |
742 | - t[key] = &dbus.Variant{Value: value} |
743 | - } |
744 | - s := struct { |
745 | - U string |
746 | - H string |
747 | - A string |
748 | - M map[string]*dbus.Variant |
749 | - HD map[string]string |
750 | - }{url, hash, string(algo), t, headers} |
751 | - var path dbus.ObjectPath |
752 | - reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createDownload", s) |
753 | - if err != nil || reply.Type == dbus.TypeError { |
754 | - return nil, err |
755 | - } |
756 | - if err = readArgs(reply, &path); err != nil { |
757 | - return nil, err |
758 | - } |
759 | - down, err = newFileDownload(man.conn, path) |
760 | - return down, err |
761 | -} |
762 | - |
763 | -// CreateMmsDownload creates an mms download that will be performed right away. An |
764 | -// mms download only uses mobile that and an apn proxy to download a multime media |
765 | -// message. |
766 | -func (man *DownloadManager) CreateMmsDownload(url string, hostname string, port int32) (down Download, err error) { |
767 | - var path dbus.ObjectPath |
768 | - reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createMmsDownload", url, hostname, port) |
769 | - if err != nil || reply.Type == dbus.TypeError { |
770 | - return nil, err |
771 | - } |
772 | - if err = readArgs(reply, &path); err != nil { |
773 | - return nil, err |
774 | - } |
775 | - down, err = newFileDownload(man.conn, path) |
776 | - return down, err |
777 | -} |
778 | |
779 | === removed file 'bindings/golang/downloader_test.go' |
780 | --- bindings/golang/downloader_test.go 2014-05-13 08:50:46 +0000 |
781 | +++ bindings/golang/downloader_test.go 1970-01-01 00:00:00 +0000 |
782 | @@ -1,306 +0,0 @@ |
783 | -/* |
784 | - * Copyright 2014 Canonical Ltd. |
785 | - * |
786 | - * Authors: |
787 | - * Manuel de la Pena: manuel.delapena@canonical.com |
788 | - * |
789 | - * This file is part of ubuntu-download-manager. |
790 | - * |
791 | - * ubuntu-download-manager is free software; you can redistribute it and/or modify |
792 | - * it under the terms of the GNU General Public License as published by |
793 | - * the Free Software Foundation; version 3. |
794 | - * |
795 | - * ubuntu-download-manager is distributed in the hope that it will be useful, |
796 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
797 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
798 | - * GNU General Public License for more details. |
799 | - * |
800 | - * You should have received a copy of the GNU General Public License |
801 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
802 | - */ |
803 | - |
804 | -package udm |
805 | - |
806 | -import ( |
807 | - "errors" |
808 | - . "gopkg.in/check.v1" |
809 | - "launchpad.net/go-dbus/v1" |
810 | - "reflect" |
811 | -) |
812 | - |
813 | -type DownloadSuite struct { |
814 | - proxy *fakeProxy |
815 | - download *FileDownload |
816 | - msg_args []interface{} |
817 | - msg_args_err error |
818 | - started_ch chan bool |
819 | - started_w watch |
820 | - paused_ch chan bool |
821 | - paused_w watch |
822 | - resumed_ch chan bool |
823 | - resumed_w watch |
824 | - canceled_ch chan bool |
825 | - canceled_w watch |
826 | - finished_ch chan string |
827 | - finished_w watch |
828 | - errors_ch chan error |
829 | - errors_w watch |
830 | - progress_ch chan Progress |
831 | - progress_w watch |
832 | -} |
833 | - |
834 | -var _ = Suite(&DownloadSuite{}) |
835 | - |
836 | -func (s *DownloadSuite) SetUpTest(c *C) { |
837 | - s.proxy = &fakeProxy{} |
838 | - s.started_ch = make(chan bool) |
839 | - s.started_w = newFakeWatch() |
840 | - s.paused_ch = make(chan bool) |
841 | - s.paused_w = newFakeWatch() |
842 | - s.resumed_ch = make(chan bool) |
843 | - s.resumed_w = newFakeWatch() |
844 | - s.canceled_ch = make(chan bool) |
845 | - s.canceled_w = newFakeWatch() |
846 | - s.finished_ch = make(chan string) |
847 | - s.finished_w = newFakeWatch() |
848 | - s.errors_ch = make(chan error) |
849 | - s.errors_w = newFakeWatch() |
850 | - s.progress_ch = make(chan Progress) |
851 | - s.progress_w = newFakeWatch() |
852 | - s.download = &FileDownload{nil, s.proxy, "", s.started_ch, s.started_w, s.paused_ch, s.paused_w, s.resumed_ch, s.resumed_w, s.canceled_ch, s.canceled_w, s.finished_ch, s.finished_w, s.errors_ch, s.errors_w, s.progress_ch, s.progress_w} |
853 | - |
854 | - readArgs = func(msg *dbus.Message, args ...interface{}) error { |
855 | - for i, arg := range args { |
856 | - v := reflect.ValueOf(arg) |
857 | - e := v.Elem() |
858 | - switch s.msg_args[i].(type) { |
859 | - default: |
860 | - return errors.New("unexpected type") |
861 | - case bool: |
862 | - e.SetBool(s.msg_args[i].(bool)) |
863 | - case uint64: |
864 | - e.SetUint(s.msg_args[i].(uint64)) |
865 | - } |
866 | - } |
867 | - return s.msg_args_err |
868 | - } |
869 | -} |
870 | - |
871 | -func (s *DownloadSuite) TestTotalSizeError(c *C) { |
872 | - s.proxy.Result = newDBusError() |
873 | - size, err := s.download.TotalSize() |
874 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
875 | - c.Assert(s.proxy.MethodName, Equals, "totalSize") |
876 | - c.Assert(size, Equals, uint64(0)) |
877 | - c.Assert(err, NotNil) |
878 | -} |
879 | - |
880 | -func (s *DownloadSuite) TestTotalSize(c *C) { |
881 | - expected_size := uint64(98) |
882 | - s.proxy.Result = newDBusReturn() |
883 | - s.msg_args = make([]interface{}, 1) |
884 | - s.msg_args[0] = expected_size |
885 | - s.msg_args_err = nil |
886 | - size, err := s.download.TotalSize() |
887 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
888 | - c.Assert(s.proxy.MethodName, Equals, "totalSize") |
889 | - c.Assert(err, IsNil) |
890 | - c.Assert(size, Equals, expected_size) |
891 | -} |
892 | - |
893 | -func (s *DownloadSuite) TestProgressError(c *C) { |
894 | - s.proxy.Result = newDBusError() |
895 | - progress, err := s.download.Progress() |
896 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
897 | - c.Assert(s.proxy.MethodName, Equals, "progress") |
898 | - c.Assert(progress, Equals, uint64(0)) |
899 | - c.Assert(err, NotNil) |
900 | -} |
901 | - |
902 | -func (s *DownloadSuite) TestProgress(c *C) { |
903 | - expected_progress := uint64(98) |
904 | - s.proxy.Result = newDBusReturn() |
905 | - s.msg_args = make([]interface{}, 1) |
906 | - s.msg_args[0] = expected_progress |
907 | - s.msg_args_err = nil |
908 | - progress, err := s.download.Progress() |
909 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
910 | - c.Assert(s.proxy.MethodName, Equals, "progress") |
911 | - c.Assert(err, IsNil) |
912 | - c.Assert(progress, Equals, expected_progress) |
913 | -} |
914 | - |
915 | -func (s *DownloadSuite) TestMetadataError(c *C) { |
916 | - s.proxy.Result = newDBusError() |
917 | - metadata, err := s.download.Metadata() |
918 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
919 | - c.Assert(s.proxy.MethodName, Equals, "metadata") |
920 | - c.Assert(metadata, IsNil) |
921 | - c.Assert(err, NotNil) |
922 | -} |
923 | - |
924 | -func (s *DownloadSuite) TestSetThrotthleError(c *C) { |
925 | - throttle := uint64(9) |
926 | - s.proxy.Result = newDBusError() |
927 | - err := s.download.SetThrottle(throttle) |
928 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
929 | - c.Assert(s.proxy.MethodName, Equals, "setThrottle") |
930 | - c.Assert(err, NotNil) |
931 | - c.Assert(s.proxy.Args[0], Equals, throttle) |
932 | -} |
933 | - |
934 | -func (s *DownloadSuite) TestSetThrottle(c *C) { |
935 | - s.proxy.Result = newDBusReturn() |
936 | - err := s.download.SetThrottle(uint64(9)) |
937 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
938 | - c.Assert(s.proxy.MethodName, Equals, "setThrottle") |
939 | - c.Assert(err, IsNil) |
940 | -} |
941 | - |
942 | -func (s *DownloadSuite) TestThrottleError(c *C) { |
943 | - s.proxy.Result = newDBusError() |
944 | - size, err := s.download.Throttle() |
945 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
946 | - c.Assert(s.proxy.MethodName, Equals, "throttle") |
947 | - c.Assert(size, Equals, uint64(0)) |
948 | - c.Assert(err, NotNil) |
949 | -} |
950 | - |
951 | -func (s *DownloadSuite) TestThrottle(c *C) { |
952 | - expected_throttle := uint64(98) |
953 | - s.proxy.Result = newDBusReturn() |
954 | - s.msg_args = make([]interface{}, 1) |
955 | - s.msg_args[0] = expected_throttle |
956 | - s.msg_args_err = nil |
957 | - throttle, err := s.download.Throttle() |
958 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
959 | - c.Assert(s.proxy.MethodName, Equals, "throttle") |
960 | - c.Assert(err, IsNil) |
961 | - c.Assert(throttle, Equals, expected_throttle) |
962 | -} |
963 | - |
964 | -func (s *DownloadSuite) TestAllowMobileDownloadError(c *C) { |
965 | - s.proxy.Result = newDBusError() |
966 | - err := s.download.AllowMobileDownload(true) |
967 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
968 | - c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload") |
969 | - c.Assert(err, NotNil) |
970 | -} |
971 | - |
972 | -func (s *DownloadSuite) TestAllowMobileDownload(c *C) { |
973 | - expected_allowed := true |
974 | - s.proxy.Result = newDBusReturn() |
975 | - err := s.download.AllowMobileDownload(expected_allowed) |
976 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
977 | - c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload") |
978 | - c.Assert(err, IsNil) |
979 | - c.Assert(s.proxy.Args[0], Equals, expected_allowed) |
980 | -} |
981 | - |
982 | -func (s *DownloadSuite) TestSetDestinationDirError(c *C) { |
983 | - s.proxy.Result = newDBusError() |
984 | - err := s.download.SetDestinationDir("/new/path") |
985 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
986 | - c.Assert(s.proxy.MethodName, Equals, "setDestinationDir") |
987 | - c.Assert(err, NotNil) |
988 | -} |
989 | - |
990 | -func (s *DownloadSuite) TestSetDestinationDir(c *C) { |
991 | - expected_dir := "/path/to/use" |
992 | - s.proxy.Result = newDBusReturn() |
993 | - err := s.download.SetDestinationDir(expected_dir) |
994 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
995 | - c.Assert(s.proxy.MethodName, Equals, "setDestinationDir") |
996 | - c.Assert(err, IsNil) |
997 | - c.Assert(s.proxy.Args[0], Equals, expected_dir) |
998 | -} |
999 | - |
1000 | -func (s *DownloadSuite) TestIsMobileDownloadError(c *C) { |
1001 | - s.proxy.Result = newDBusError() |
1002 | - allowed, err := s.download.IsMobileDownload() |
1003 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1004 | - c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed") |
1005 | - c.Assert(allowed, Equals, false) |
1006 | - c.Assert(err, NotNil) |
1007 | -} |
1008 | - |
1009 | -func (s *DownloadSuite) TestIsMobileDownload(c *C) { |
1010 | - expected_allowed := true |
1011 | - s.proxy.Result = newDBusReturn() |
1012 | - s.msg_args = make([]interface{}, 1) |
1013 | - s.msg_args[0] = expected_allowed |
1014 | - s.msg_args_err = nil |
1015 | - allowed, err := s.download.IsMobileDownload() |
1016 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1017 | - c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed") |
1018 | - c.Assert(err, IsNil) |
1019 | - c.Assert(allowed, Equals, expected_allowed) |
1020 | -} |
1021 | - |
1022 | -func (s *DownloadSuite) TestStartDBusError(c *C) { |
1023 | - s.proxy.Result = newDBusError() |
1024 | - err := s.download.Start() |
1025 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1026 | - c.Assert(s.proxy.MethodName, Equals, "start") |
1027 | - c.Assert(err, NotNil) |
1028 | -} |
1029 | - |
1030 | -func (s *DownloadSuite) TestStartError(c *C) { |
1031 | - s.proxy.Result = newDBusReturn() |
1032 | - s.proxy.Err = errors.New("Fake error") |
1033 | - err := s.download.Start() |
1034 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1035 | - c.Assert(s.proxy.MethodName, Equals, "start") |
1036 | - c.Assert(err, NotNil) |
1037 | -} |
1038 | - |
1039 | -func (s *DownloadSuite) TestPauseDBusError(c *C) { |
1040 | - s.proxy.Result = newDBusError() |
1041 | - err := s.download.Pause() |
1042 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1043 | - c.Assert(s.proxy.MethodName, Equals, "pause") |
1044 | - c.Assert(err, NotNil) |
1045 | -} |
1046 | - |
1047 | -func (s *DownloadSuite) TestPauseError(c *C) { |
1048 | - s.proxy.Result = newDBusReturn() |
1049 | - s.proxy.Err = errors.New("Fake error") |
1050 | - err := s.download.Pause() |
1051 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1052 | - c.Assert(s.proxy.MethodName, Equals, "pause") |
1053 | - c.Assert(err, NotNil) |
1054 | -} |
1055 | - |
1056 | -func (s *DownloadSuite) TestResumeDBusError(c *C) { |
1057 | - s.proxy.Result = newDBusError() |
1058 | - err := s.download.Resume() |
1059 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1060 | - c.Assert(s.proxy.MethodName, Equals, "resume") |
1061 | - c.Assert(err, NotNil) |
1062 | -} |
1063 | - |
1064 | -func (s *DownloadSuite) TestResumeError(c *C) { |
1065 | - s.proxy.Result = newDBusReturn() |
1066 | - s.proxy.Err = errors.New("Fake error") |
1067 | - err := s.download.Resume() |
1068 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1069 | - c.Assert(s.proxy.MethodName, Equals, "resume") |
1070 | - c.Assert(err, NotNil) |
1071 | -} |
1072 | - |
1073 | -func (s *DownloadSuite) TestCancelDBusError(c *C) { |
1074 | - s.proxy.Result = newDBusError() |
1075 | - err := s.download.Cancel() |
1076 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1077 | - c.Assert(s.proxy.MethodName, Equals, "cancel") |
1078 | - c.Assert(err, NotNil) |
1079 | -} |
1080 | - |
1081 | -func (s *DownloadSuite) TestCancelError(c *C) { |
1082 | - s.proxy.Result = newDBusReturn() |
1083 | - s.proxy.Err = errors.New("Fake error") |
1084 | - err := s.download.Cancel() |
1085 | - c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE) |
1086 | - c.Assert(s.proxy.MethodName, Equals, "cancel") |
1087 | - c.Assert(err, NotNil) |
1088 | -} |
1089 | |
1090 | === removed file 'bindings/golang/uploader.go' |
1091 | --- bindings/golang/uploader.go 2014-05-13 08:50:46 +0000 |
1092 | +++ bindings/golang/uploader.go 1970-01-01 00:00:00 +0000 |
1093 | @@ -1,396 +0,0 @@ |
1094 | -/* |
1095 | - * Copyright 2014 Canonical Ltd. |
1096 | - * |
1097 | - * Authors: |
1098 | - * Manuel de la Pena: manuel.delapena@canonical.com |
1099 | - * |
1100 | - * This file is part of ubuntu-download-manager. |
1101 | - * |
1102 | - * ubuntu-download-manager is free software; you can redistribute it and/or modify |
1103 | - * it under the terms of the GNU General Public License as published by |
1104 | - * the Free Software Foundation; version 3. |
1105 | - * |
1106 | - * ubuntu-download-manager is distributed in the hope that it will be useful, |
1107 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1108 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1109 | - * GNU General Public License for more details. |
1110 | - * |
1111 | - * You should have received a copy of the GNU General Public License |
1112 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1113 | - */ |
1114 | - |
1115 | -// Package udm provides a go interface to work with the ubuntu download manager |
1116 | -package udm |
1117 | - |
1118 | -import ( |
1119 | - "errors" |
1120 | - "fmt" |
1121 | - "launchpad.net/go-dbus/v1" |
1122 | - "runtime" |
1123 | -) |
1124 | - |
1125 | -const ( |
1126 | - UPLOAD_SERVICE = "com.canonical.applications.Uploader" |
1127 | - UPLOAD_INTERFACE = "com.canonical.applications.Upload" |
1128 | - UPLOAD_MANAGER_INTERFACE = "com.canonical.applications.UploadManager" |
1129 | -) |
1130 | - |
1131 | -// Upload is the common interface of an upload. It provides all the required |
1132 | -// methods to interact with an upload created by udm. |
1133 | -type Upload interface { |
1134 | - Progress() (uint64, error) |
1135 | - Metadata() (map[string]string, error) |
1136 | - SetThrottle(uint64) error |
1137 | - Throttle() (uint64, error) |
1138 | - AllowMobileUpload(bool) error |
1139 | - IsMobileUpload() (bool, error) |
1140 | - Start() error |
1141 | - Cancel() error |
1142 | - Started() chan bool |
1143 | - UploadProgress() chan Progress |
1144 | - Canceled() chan bool |
1145 | - Finished() chan string |
1146 | - Error() chan error |
1147 | -} |
1148 | - |
1149 | -// FileUpload represents a single file being uploaded by udm. |
1150 | -type FileUpload struct { |
1151 | - conn *dbus.Connection |
1152 | - proxy proxy |
1153 | - path dbus.ObjectPath |
1154 | - started chan bool |
1155 | - started_w watch |
1156 | - canceled chan bool |
1157 | - canceled_w watch |
1158 | - finished chan string |
1159 | - finished_w watch |
1160 | - errors chan error |
1161 | - error_w watch |
1162 | - progress chan Progress |
1163 | - progress_w watch |
1164 | -} |
1165 | - |
1166 | -func (upload *FileUpload) free() { |
1167 | - // cancel all watches so that goroutines are done and close the |
1168 | - // channels |
1169 | - upload.started_w.Cancel() |
1170 | - upload.canceled_w.Cancel() |
1171 | - upload.finished_w.Cancel() |
1172 | - upload.error_w.Cancel() |
1173 | - upload.progress_w.Cancel() |
1174 | -} |
1175 | - |
1176 | -func cleanUploadData(upload *FileUpload) { |
1177 | - upload.free() |
1178 | -} |
1179 | - |
1180 | -func newFileUpload(conn *dbus.Connection, path dbus.ObjectPath) (*FileUpload, error) { |
1181 | - proxy := conn.Object(DOWNLOAD_SERVICE, path) |
1182 | - started_ch := make(chan bool) |
1183 | - started_w, err := connectToSignal(conn, path, "started") |
1184 | - if err != nil { |
1185 | - return nil, err |
1186 | - } |
1187 | - |
1188 | - canceled_ch := make(chan bool) |
1189 | - canceled_w, err := connectToSignal(conn, path, "canceled") |
1190 | - if err != nil { |
1191 | - return nil, err |
1192 | - } |
1193 | - |
1194 | - finished_ch := make(chan string) |
1195 | - finished_w, err := connectToSignal(conn, path, "finished") |
1196 | - if err != nil { |
1197 | - return nil, err |
1198 | - } |
1199 | - |
1200 | - errors_ch := make(chan error) |
1201 | - errors_w, err := connectToSignal(conn, path, "error") |
1202 | - if err != nil { |
1203 | - return nil, err |
1204 | - } |
1205 | - |
1206 | - progress_ch := make(chan Progress) |
1207 | - progress_w, err := connectToSignal(conn, path, "progress") |
1208 | - if err != nil { |
1209 | - return nil, err |
1210 | - } |
1211 | - |
1212 | - u := FileUpload{conn, proxy, path, started_ch, started_w, canceled_ch, canceled_w, finished_ch, finished_w, errors_ch, errors_w, progress_ch, progress_w} |
1213 | - |
1214 | - // connect to the diff signals so that we have nice channels that do |
1215 | - // not expose dbus watchers |
1216 | - u.connectToStarted() |
1217 | - u.connectToCanceled() |
1218 | - u.connectToFinished() |
1219 | - u.connectToError() |
1220 | - u.connectToProgress() |
1221 | - runtime.SetFinalizer(&u, cleanDownloadData) |
1222 | - return &u, nil |
1223 | -} |
1224 | - |
1225 | -// Process returns the process so far in uploading the file. |
1226 | -func (upload *FileUpload) Progress() (progress uint64, err error) { |
1227 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "progress") |
1228 | - if err != nil { |
1229 | - return 0, err |
1230 | - } |
1231 | - |
1232 | - if reply.Type == dbus.TypeError { |
1233 | - return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) |
1234 | - } |
1235 | - |
1236 | - if err = readArgs(reply, &progress); err != nil { |
1237 | - return 0, err |
1238 | - } |
1239 | - return progress, nil |
1240 | -} |
1241 | - |
1242 | -// Metadata returns the metadata that was provided at creating time to the upload. |
1243 | -func (upload *FileUpload) Metadata() (metadata map[string]string, err error) { |
1244 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "metadata") |
1245 | - if err != nil { |
1246 | - return nil, err |
1247 | - } |
1248 | - |
1249 | - if reply.Type == dbus.TypeError { |
1250 | - return nil, fmt.Errorf("DBus Error: %", reply.ErrorName) |
1251 | - } |
1252 | - |
1253 | - if err = readArgs(reply, &metadata); err != nil { |
1254 | - return nil, err |
1255 | - } |
1256 | - return metadata, nil |
1257 | -} |
1258 | - |
1259 | -// SetThrottle sets the network throttle to be used in the upload. |
1260 | -func (upload *FileUpload) SetThrottle(throttle uint64) (err error) { |
1261 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "setThrottle", throttle) |
1262 | - if err != nil { |
1263 | - return err |
1264 | - } |
1265 | - |
1266 | - if reply.Type == dbus.TypeError { |
1267 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
1268 | - } |
1269 | - |
1270 | - return nil |
1271 | -} |
1272 | - |
1273 | -// Throttle returns the network throttle that is currently used in the upload. |
1274 | -func (upload *FileUpload) Throttle() (throttle uint64, err error) { |
1275 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "throttle") |
1276 | - if err != nil { |
1277 | - return 0, err |
1278 | - } |
1279 | - |
1280 | - if reply.Type == dbus.TypeError { |
1281 | - return 0, fmt.Errorf("DBus Error: %", reply.ErrorName) |
1282 | - } |
1283 | - |
1284 | - if err = readArgs(reply, &throttle); err != nil { |
1285 | - return 0, err |
1286 | - } |
1287 | - return throttle, nil |
1288 | -} |
1289 | - |
1290 | -// AllowMobileUpload returns if the download is allow to use the mobile connect |
1291 | -// connection. |
1292 | -func (upload *FileUpload) AllowMobileUpload(allowed bool) (err error) { |
1293 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "allowMobileUpload", allowed) |
1294 | - if err != nil { |
1295 | - return err |
1296 | - } |
1297 | - |
1298 | - if reply.Type == dbus.TypeError { |
1299 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
1300 | - } |
1301 | - |
1302 | - return nil |
1303 | -} |
1304 | - |
1305 | -// IsMobileUpload returns if the download will be performed over the mobile data. |
1306 | -func (upload *FileUpload) IsMobileUpload() (allowed bool, err error) { |
1307 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "isMobileUploadAllowed", allowed) |
1308 | - if err != nil { |
1309 | - return false, err |
1310 | - } |
1311 | - |
1312 | - if reply.Type == dbus.TypeError { |
1313 | - return false, fmt.Errorf("DBus Error: %", reply.ErrorName) |
1314 | - } |
1315 | - |
1316 | - if err = readArgs(reply, &allowed); err != nil { |
1317 | - return false, err |
1318 | - } |
1319 | - return allowed, nil |
1320 | -} |
1321 | - |
1322 | -func (upload *FileUpload) Start() (err error) { |
1323 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "start") |
1324 | - if err != nil { |
1325 | - return err |
1326 | - } |
1327 | - |
1328 | - if reply.Type == dbus.TypeError { |
1329 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
1330 | - } |
1331 | - |
1332 | - return nil |
1333 | -} |
1334 | - |
1335 | -// Cancel cancels an upload that was in process and deletes any local files |
1336 | -// that were created. |
1337 | -func (upload *FileUpload) Cancel() (err error) { |
1338 | - reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "cancel") |
1339 | - if err != nil { |
1340 | - return err |
1341 | - } |
1342 | - |
1343 | - if reply.Type == dbus.TypeError { |
1344 | - return fmt.Errorf("DBus Error: %", reply.ErrorName) |
1345 | - } |
1346 | - |
1347 | - return nil |
1348 | -} |
1349 | - |
1350 | -func (upload *FileUpload) connectToStarted() { |
1351 | - |
1352 | - go func() { |
1353 | - for msg := range upload.started_w.Chanel() { |
1354 | - var started bool |
1355 | - readArgs(msg, &started) |
1356 | - upload.started <- started |
1357 | - } |
1358 | - close(upload.started) |
1359 | - }() |
1360 | -} |
1361 | - |
1362 | -// Started returns a channel that will be used to communicate the started signals. |
1363 | -func (upload *FileUpload) Started() chan bool { |
1364 | - return upload.started |
1365 | -} |
1366 | - |
1367 | -func (upload *FileUpload) connectToCanceled() { |
1368 | - go func() { |
1369 | - for msg := range upload.canceled_w.Chanel() { |
1370 | - var canceled bool |
1371 | - readArgs(msg, &canceled) |
1372 | - upload.canceled <- canceled |
1373 | - } |
1374 | - close(upload.canceled) |
1375 | - }() |
1376 | -} |
1377 | - |
1378 | -// Canceled returns a channel that will be used to communicate the canceled signals. |
1379 | -func (upload *FileUpload) Canceled() chan bool { |
1380 | - return upload.canceled |
1381 | -} |
1382 | - |
1383 | -func (upload *FileUpload) connectToFinished() { |
1384 | - go func() { |
1385 | - for msg := range upload.finished_w.Chanel() { |
1386 | - var path string |
1387 | - readArgs(msg, &path) |
1388 | - upload.finished <- path |
1389 | - } |
1390 | - close(upload.finished) |
1391 | - }() |
1392 | -} |
1393 | - |
1394 | -// Finished returns a channel that will ne used to communicate the finished signals. |
1395 | -func (upload *FileUpload) Finished() chan string { |
1396 | - return upload.finished |
1397 | -} |
1398 | - |
1399 | -func (upload *FileUpload) connectToError() { |
1400 | - go func() { |
1401 | - for msg := range upload.error_w.Chanel() { |
1402 | - var reason string |
1403 | - readArgs(msg, &reason) |
1404 | - upload.errors <- errors.New(reason) |
1405 | - } |
1406 | - close(upload.errors) |
1407 | - }() |
1408 | -} |
1409 | - |
1410 | -// Error returns the channel that will be used to communicate the error signals. |
1411 | -func (upload *FileUpload) Error() chan error { |
1412 | - return upload.errors |
1413 | -} |
1414 | - |
1415 | -func (upload *FileUpload) connectToProgress() { |
1416 | - go func() { |
1417 | - for msg := range upload.progress_w.Chanel() { |
1418 | - var received uint64 |
1419 | - var total uint64 |
1420 | - readArgs(msg, &received, &total) |
1421 | - upload.progress <- Progress{received, total} |
1422 | - } |
1423 | - close(upload.progress) |
1424 | - }() |
1425 | -} |
1426 | - |
1427 | -// UploadProgress returns a channel that will be used to communicate the progress |
1428 | -// signals. |
1429 | -func (upload *FileUpload) UploadProgress() chan Progress { |
1430 | - return upload.progress |
1431 | -} |
1432 | - |
1433 | -type UploadManager struct { |
1434 | - conn *dbus.Connection |
1435 | - proxy *dbus.ObjectProxy |
1436 | -} |
1437 | - |
1438 | -// NewUploadManager creates a new manager that can be used to create download in the |
1439 | -// udm daemon. |
1440 | -func NewUploadManager() (*UploadManager, error) { |
1441 | - conn, err := dbus.Connect(dbus.SessionBus) |
1442 | - if err != nil { |
1443 | - return nil, err |
1444 | - } |
1445 | - |
1446 | - if err != nil { |
1447 | - return nil, err |
1448 | - } |
1449 | - |
1450 | - proxy := conn.Object(UPLOAD_SERVICE, "/") |
1451 | - d := UploadManager{conn, proxy} |
1452 | - return &d, nil |
1453 | -} |
1454 | - |
1455 | -func (man *UploadManager) CreateUpload(url string, file string, metadata map[string]interface{}, headers map[string]string) (upload Upload, err error) { |
1456 | - var t map[string]*dbus.Variant |
1457 | - for key, value := range metadata { |
1458 | - t[key] = &dbus.Variant{Value: value} |
1459 | - } |
1460 | - s := struct { |
1461 | - U string |
1462 | - F string |
1463 | - M map[string]*dbus.Variant |
1464 | - HD map[string]string |
1465 | - }{url, file, t, headers} |
1466 | - var path dbus.ObjectPath |
1467 | - reply, err := man.proxy.Call(UPLOAD_MANAGER_INTERFACE, "createUpload", s) |
1468 | - if err != nil || reply.Type == dbus.TypeError { |
1469 | - return nil, err |
1470 | - } |
1471 | - if err = readArgs(reply, &path); err != nil { |
1472 | - return nil, err |
1473 | - } |
1474 | - upload, err = newFileUpload(man.conn, path) |
1475 | - return upload, err |
1476 | -} |
1477 | - |
1478 | -func (man *UploadManager) CreateMmsUpload(url string, file string, hostname string, port int32) (upload Upload, err error) { |
1479 | - var path dbus.ObjectPath |
1480 | - reply, err := man.proxy.Call(UPLOAD_MANAGER_INTERFACE, "createMmsUpload", url, file, hostname, port) |
1481 | - if err != nil || reply.Type == dbus.TypeError { |
1482 | - return nil, err |
1483 | - } |
1484 | - if err = readArgs(reply, &path); err != nil { |
1485 | - return nil, err |
1486 | - } |
1487 | - upload, err = newFileUpload(man.conn, path) |
1488 | - return upload, err |
1489 | -} |
1490 | |
1491 | === removed file 'bindings/golang/uploader_test.go' |
1492 | --- bindings/golang/uploader_test.go 2014-05-13 08:50:46 +0000 |
1493 | +++ bindings/golang/uploader_test.go 1970-01-01 00:00:00 +0000 |
1494 | @@ -1,215 +0,0 @@ |
1495 | -/* |
1496 | - * Copyright 2014 Canonical Ltd. |
1497 | - * |
1498 | - * Authors: |
1499 | - * Manuel de la Pena: manuel.delapena@canonical.com |
1500 | - * |
1501 | - * This file is part of ubuntu-download-manager. |
1502 | - * |
1503 | - * ubuntu-download-manager is free software; you can redistribute it and/or modify |
1504 | - * it under the terms of the GNU General Public License as published by |
1505 | - * the Free Software Foundation; version 3. |
1506 | - * |
1507 | - * ubuntu-download-manager is distributed in the hope that it will be useful, |
1508 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1509 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1510 | - * GNU General Public License for more details. |
1511 | - * |
1512 | - * You should have received a copy of the GNU General Public License |
1513 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1514 | - */ |
1515 | - |
1516 | -package udm |
1517 | - |
1518 | -import ( |
1519 | - "errors" |
1520 | - . "gopkg.in/check.v1" |
1521 | - "launchpad.net/go-dbus/v1" |
1522 | - "reflect" |
1523 | -) |
1524 | - |
1525 | -type UploadSuite struct { |
1526 | - proxy *fakeProxy |
1527 | - upload *FileUpload |
1528 | - msg_args []interface{} |
1529 | - msg_args_err error |
1530 | - started_ch chan bool |
1531 | - started_w watch |
1532 | - canceled_ch chan bool |
1533 | - canceled_w watch |
1534 | - finished_ch chan string |
1535 | - finished_w watch |
1536 | - errors_ch chan error |
1537 | - errors_w watch |
1538 | - progress_ch chan Progress |
1539 | - progress_w watch |
1540 | -} |
1541 | - |
1542 | -var _ = Suite(&UploadSuite{}) |
1543 | - |
1544 | -func (s *UploadSuite) SetUpTest(c *C) { |
1545 | - s.proxy = &fakeProxy{} |
1546 | - s.started_ch = make(chan bool) |
1547 | - s.started_w = newFakeWatch() |
1548 | - s.canceled_ch = make(chan bool) |
1549 | - s.canceled_w = newFakeWatch() |
1550 | - s.finished_ch = make(chan string) |
1551 | - s.finished_w = newFakeWatch() |
1552 | - s.errors_ch = make(chan error) |
1553 | - s.errors_w = newFakeWatch() |
1554 | - s.progress_ch = make(chan Progress) |
1555 | - s.progress_w = newFakeWatch() |
1556 | - s.upload = &FileUpload{nil, s.proxy, "", s.started_ch, s.started_w, s.canceled_ch, s.canceled_w, s.finished_ch, s.finished_w, s.errors_ch, s.errors_w, s.progress_ch, s.progress_w} |
1557 | - |
1558 | - readArgs = func(msg *dbus.Message, args ...interface{}) error { |
1559 | - for i, arg := range args { |
1560 | - v := reflect.ValueOf(arg) |
1561 | - e := v.Elem() |
1562 | - switch s.msg_args[i].(type) { |
1563 | - default: |
1564 | - return errors.New("unexpected type") |
1565 | - case bool: |
1566 | - e.SetBool(s.msg_args[i].(bool)) |
1567 | - case uint64: |
1568 | - e.SetUint(s.msg_args[i].(uint64)) |
1569 | - } |
1570 | - } |
1571 | - return s.msg_args_err |
1572 | - } |
1573 | -} |
1574 | - |
1575 | -func (s *UploadSuite) TestProgressError(c *C) { |
1576 | - s.proxy.Result = newDBusError() |
1577 | - progress, err := s.upload.Progress() |
1578 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1579 | - c.Assert(s.proxy.MethodName, Equals, "progress") |
1580 | - c.Assert(progress, Equals, uint64(0)) |
1581 | - c.Assert(err, NotNil) |
1582 | -} |
1583 | - |
1584 | -func (s *UploadSuite) TestProgress(c *C) { |
1585 | - expected_progress := uint64(98) |
1586 | - s.proxy.Result = newDBusReturn() |
1587 | - s.msg_args = make([]interface{}, 1) |
1588 | - s.msg_args[0] = expected_progress |
1589 | - s.msg_args_err = nil |
1590 | - progress, err := s.upload.Progress() |
1591 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1592 | - c.Assert(s.proxy.MethodName, Equals, "progress") |
1593 | - c.Assert(err, IsNil) |
1594 | - c.Assert(progress, Equals, expected_progress) |
1595 | -} |
1596 | - |
1597 | -func (s *UploadSuite) TestMetadataError(c *C) { |
1598 | - s.proxy.Result = newDBusError() |
1599 | - metadata, err := s.upload.Metadata() |
1600 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1601 | - c.Assert(s.proxy.MethodName, Equals, "metadata") |
1602 | - c.Assert(metadata, IsNil) |
1603 | - c.Assert(err, NotNil) |
1604 | -} |
1605 | - |
1606 | -func (s *UploadSuite) TestSetThrotthleError(c *C) { |
1607 | - throttle := uint64(9) |
1608 | - s.proxy.Result = newDBusError() |
1609 | - err := s.upload.SetThrottle(throttle) |
1610 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1611 | - c.Assert(s.proxy.MethodName, Equals, "setThrottle") |
1612 | - c.Assert(err, NotNil) |
1613 | - c.Assert(s.proxy.Args[0], Equals, throttle) |
1614 | -} |
1615 | - |
1616 | -func (s *UploadSuite) TestSetThrottle(c *C) { |
1617 | - s.proxy.Result = newDBusReturn() |
1618 | - err := s.upload.SetThrottle(uint64(9)) |
1619 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1620 | - c.Assert(s.proxy.MethodName, Equals, "setThrottle") |
1621 | - c.Assert(err, IsNil) |
1622 | -} |
1623 | - |
1624 | -func (s *UploadSuite) TestThrottle(c *C) { |
1625 | - expected_throttle := uint64(98) |
1626 | - s.proxy.Result = newDBusReturn() |
1627 | - s.msg_args = make([]interface{}, 1) |
1628 | - s.msg_args[0] = expected_throttle |
1629 | - s.msg_args_err = nil |
1630 | - throttle, err := s.upload.Throttle() |
1631 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1632 | - c.Assert(s.proxy.MethodName, Equals, "throttle") |
1633 | - c.Assert(err, IsNil) |
1634 | - c.Assert(throttle, Equals, expected_throttle) |
1635 | -} |
1636 | - |
1637 | -func (s *UploadSuite) TestAllowMobileUploadError(c *C) { |
1638 | - s.proxy.Result = newDBusError() |
1639 | - err := s.upload.AllowMobileUpload(true) |
1640 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1641 | - c.Assert(s.proxy.MethodName, Equals, "allowMobileUpload") |
1642 | - c.Assert(err, NotNil) |
1643 | -} |
1644 | - |
1645 | -func (s *UploadSuite) TestAllowMobileUpload(c *C) { |
1646 | - expected_allowed := true |
1647 | - s.proxy.Result = newDBusReturn() |
1648 | - err := s.upload.AllowMobileUpload(expected_allowed) |
1649 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1650 | - c.Assert(s.proxy.MethodName, Equals, "allowMobileUpload") |
1651 | - c.Assert(err, IsNil) |
1652 | - c.Assert(s.proxy.Args[0], Equals, expected_allowed) |
1653 | -} |
1654 | - |
1655 | -func (s *UploadSuite) TestIsMobileUploadError(c *C) { |
1656 | - s.proxy.Result = newDBusError() |
1657 | - allowed, err := s.upload.IsMobileUpload() |
1658 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1659 | - c.Assert(s.proxy.MethodName, Equals, "isMobileUploadAllowed") |
1660 | - c.Assert(allowed, Equals, false) |
1661 | - c.Assert(err, NotNil) |
1662 | -} |
1663 | - |
1664 | -func (s *UploadSuite) TestIsMobileUpload(c *C) { |
1665 | - expected_allowed := true |
1666 | - s.proxy.Result = newDBusReturn() |
1667 | - s.msg_args = make([]interface{}, 1) |
1668 | - s.msg_args[0] = expected_allowed |
1669 | - s.msg_args_err = nil |
1670 | - allowed, err := s.upload.IsMobileUpload() |
1671 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1672 | - c.Assert(s.proxy.MethodName, Equals, "isMobileUploadAllowed") |
1673 | - c.Assert(err, IsNil) |
1674 | - c.Assert(allowed, Equals, expected_allowed) |
1675 | -} |
1676 | - |
1677 | -func (s *UploadSuite) TestStartDBusError(c *C) { |
1678 | - s.proxy.Result = newDBusError() |
1679 | - err := s.upload.Start() |
1680 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1681 | - c.Assert(s.proxy.MethodName, Equals, "start") |
1682 | - c.Assert(err, NotNil) |
1683 | -} |
1684 | - |
1685 | -func (s *UploadSuite) TestStartError(c *C) { |
1686 | - s.proxy.Result = newDBusReturn() |
1687 | - s.proxy.Err = errors.New("Fake error") |
1688 | - err := s.upload.Start() |
1689 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1690 | - c.Assert(s.proxy.MethodName, Equals, "start") |
1691 | - c.Assert(err, NotNil) |
1692 | -} |
1693 | - |
1694 | -func (s *UploadSuite) TestCancelDBusError(c *C) { |
1695 | - s.proxy.Result = newDBusError() |
1696 | - err := s.upload.Cancel() |
1697 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1698 | - c.Assert(s.proxy.MethodName, Equals, "cancel") |
1699 | - c.Assert(err, NotNil) |
1700 | -} |
1701 | - |
1702 | -func (s *UploadSuite) TestCancelError(c *C) { |
1703 | - s.proxy.Result = newDBusReturn() |
1704 | - s.proxy.Err = errors.New("Fake error") |
1705 | - err := s.upload.Cancel() |
1706 | - c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE) |
1707 | - c.Assert(s.proxy.MethodName, Equals, "cancel") |
1708 | - c.Assert(err, NotNil) |
1709 | -} |
1710 | |
1711 | === modified file 'docs/com.canonical.applications.upload_manager.xml' |
1712 | --- docs/com.canonical.applications.upload_manager.xml 2014-02-21 11:56:12 +0000 |
1713 | +++ docs/com.canonical.applications.upload_manager.xml 2014-05-13 08:50:47 +0000 |
1714 | @@ -11,8 +11,6 @@ |
1715 | <arg name="file" type="s" direction="in" /> |
1716 | <arg name="hostname" type="s" direction="in" /> |
1717 | <arg name="port" type="i" direction="in" /> |
1718 | - <arg name="username" type="s" direction="in" /> |
1719 | - <arg name="password" type="s" direction="in" /> |
1720 | <arg name="uploadPath" type="o" direction="out" /> |
1721 | </method> |
1722 | |
1723 | |
1724 | === modified file 'src/uploads/priv/ubuntu/uploads/factory.cpp' |
1725 | --- src/uploads/priv/ubuntu/uploads/factory.cpp 2014-05-13 08:50:46 +0000 |
1726 | +++ src/uploads/priv/ubuntu/uploads/factory.cpp 2014-05-13 08:50:47 +0000 |
1727 | @@ -89,11 +89,9 @@ |
1728 | const QUrl& url, |
1729 | const QString& filePath, |
1730 | const QString& hostname, |
1731 | - int port, |
1732 | - const QString& username, |
1733 | - const QString& password) { |
1734 | + int port) { |
1735 | QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname, |
1736 | - port, username, password); |
1737 | + port); |
1738 | QVariantMap metadata; |
1739 | QMap<QString, QString> headers; |
1740 | QScopedPointer<SecurityDetails> details( |
1741 | |
1742 | === modified file 'src/uploads/priv/ubuntu/uploads/factory.h' |
1743 | --- src/uploads/priv/ubuntu/uploads/factory.h 2014-03-26 10:00:28 +0000 |
1744 | +++ src/uploads/priv/ubuntu/uploads/factory.h 2014-05-13 08:50:47 +0000 |
1745 | @@ -51,9 +51,7 @@ |
1746 | const QUrl& url, |
1747 | const QString& filePath, |
1748 | const QString& hostname, |
1749 | - int port, |
1750 | - const QString& username, |
1751 | - const QString& password); |
1752 | + int port); |
1753 | |
1754 | // mainly for testing purposes |
1755 | virtual QList<QSslCertificate> acceptedCertificates(); |
1756 | |
1757 | === modified file 'src/uploads/priv/ubuntu/uploads/manager.cpp' |
1758 | --- src/uploads/priv/ubuntu/uploads/manager.cpp 2014-03-04 13:17:09 +0000 |
1759 | +++ src/uploads/priv/ubuntu/uploads/manager.cpp 2014-05-13 08:50:47 +0000 |
1760 | @@ -128,16 +128,13 @@ |
1761 | UploadManager::createMmsUpload(const QString& url, |
1762 | const QString& file, |
1763 | const QString& hostname, |
1764 | - int port, |
1765 | - const QString& username, |
1766 | - const QString& password) { |
1767 | + int port) { |
1768 | LOG(INFO) << "Create MMS upload == {url:" << url << " filePath: " |
1769 | - << file << " hostname:" << hostname << " port:" |
1770 | - << port << " username:" << username << " pwd: " << password << "}"; |
1771 | + << file << " hostname:" << hostname << " port:" << port << "}"; |
1772 | UploadCreationFunc createUploadFunc = |
1773 | - [this, url, file, hostname, port, username, password](QString owner) { |
1774 | + [this, url, file, hostname, port](QString owner) { |
1775 | auto upload = _factory->createMmsUpload(owner, url, file, hostname, |
1776 | - port, username, password); |
1777 | + port); |
1778 | return upload; |
1779 | }; |
1780 | return createUpload(createUploadFunc); |
1781 | |
1782 | === modified file 'src/uploads/priv/ubuntu/uploads/manager.h' |
1783 | --- src/uploads/priv/ubuntu/uploads/manager.h 2014-03-03 23:28:01 +0000 |
1784 | +++ src/uploads/priv/ubuntu/uploads/manager.h 2014-05-13 08:50:47 +0000 |
1785 | @@ -64,9 +64,7 @@ |
1786 | QDBusObjectPath createMmsUpload(const QString& url, |
1787 | const QString& file, |
1788 | const QString& hostname, |
1789 | - int port, |
1790 | - const QString& username, |
1791 | - const QString& password); |
1792 | + int port); |
1793 | QDBusObjectPath createUpload(const QString& url, |
1794 | const QString& filePath, |
1795 | const QVariantMap& metadata, |
1796 | |
1797 | === modified file 'src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp' |
1798 | --- src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp 2014-02-26 19:54:31 +0000 |
1799 | +++ src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp 2014-05-13 08:50:47 +0000 |
1800 | @@ -44,11 +44,11 @@ |
1801 | QMetaObject::invokeMethod(parent(), "allowMobileUpload", Q_ARG(bool, allowed)); |
1802 | } |
1803 | |
1804 | -QDBusObjectPath UploadManagerAdaptor::createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port, const QString &username, const QString &password) |
1805 | +QDBusObjectPath UploadManagerAdaptor::createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port) |
1806 | { |
1807 | // handle method call com.canonical.applications.UploadManager.createMmsUpload |
1808 | QDBusObjectPath uploadPath; |
1809 | - QMetaObject::invokeMethod(parent(), "createMmsUpload", Q_RETURN_ARG(QDBusObjectPath, uploadPath), Q_ARG(QString, url), Q_ARG(QString, file), Q_ARG(QString, hostname), Q_ARG(int, port), Q_ARG(QString, username), Q_ARG(QString, password)); |
1810 | + QMetaObject::invokeMethod(parent(), "createMmsUpload", Q_RETURN_ARG(QDBusObjectPath, uploadPath), Q_ARG(QString, url), Q_ARG(QString, file), Q_ARG(QString, hostname), Q_ARG(int, port)); |
1811 | return uploadPath; |
1812 | } |
1813 | |
1814 | |
1815 | === modified file 'src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h' |
1816 | --- src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h 2014-02-26 19:54:31 +0000 |
1817 | +++ src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h 2014-05-13 08:50:47 +0000 |
1818 | @@ -50,8 +50,6 @@ |
1819 | " <arg direction=\"in\" type=\"s\" name=\"file\"/>\n" |
1820 | " <arg direction=\"in\" type=\"s\" name=\"hostname\"/>\n" |
1821 | " <arg direction=\"in\" type=\"i\" name=\"port\"/>\n" |
1822 | -" <arg direction=\"in\" type=\"s\" name=\"username\"/>\n" |
1823 | -" <arg direction=\"in\" type=\"s\" name=\"password\"/>\n" |
1824 | " <arg direction=\"out\" type=\"o\" name=\"uploadPath\"/>\n" |
1825 | " </method>\n" |
1826 | " <method name=\"getAllUploads\">\n" |
1827 | @@ -87,7 +85,7 @@ |
1828 | public: // PROPERTIES |
1829 | public Q_SLOTS: // METHODS |
1830 | void allowMobileUpload(bool allowed); |
1831 | - QDBusObjectPath createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port, const QString &username, const QString &password); |
1832 | + QDBusObjectPath createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port); |
1833 | QDBusObjectPath createUpload(UploadStruct upload); |
1834 | qulonglong defaultThrottle(); |
1835 | void exit(); |
PASSED: Continuous integration, rev:261 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- ci/634/ jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- amd64-ci/ 524 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- armhf-ci/ 523
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/ubuntu- download- manager- ci/634/ rebuild
http://