LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package agent | 4 package agent |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "path" | 8 "path" |
9 "regexp" | 9 "regexp" |
10 "sync" | 10 "sync" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 401 } |
402 | 402 |
403 func (c *configInternal) Write() error { | 403 func (c *configInternal) Write() error { |
404 // Lock is taken prior to generating any content to write. | 404 // Lock is taken prior to generating any content to write. |
405 configMutex.Lock() | 405 configMutex.Lock() |
406 defer configMutex.Unlock() | 406 defer configMutex.Unlock() |
407 return currentFormatter.write(c) | 407 return currentFormatter.write(c) |
408 } | 408 } |
409 | 409 |
410 func (c *configInternal) WriteUpgradedToVersion(newVersion version.Number) error
{ | 410 func (c *configInternal) WriteUpgradedToVersion(newVersion version.Number) error
{ |
| 411 originalVersion := c.upgradedToVersion |
411 c.upgradedToVersion = newVersion | 412 c.upgradedToVersion = newVersion |
412 » return c.Write() | 413 » err := c.Write() |
| 414 » if err != nil { |
| 415 » » // We don't want to retain the new version if there's been an er
ror writing the file. |
| 416 » » c.upgradedToVersion = originalVersion |
| 417 » } |
| 418 » return err |
413 } | 419 } |
414 | 420 |
415 func (c *configInternal) WriteCommands() ([]string, error) { | 421 func (c *configInternal) WriteCommands() ([]string, error) { |
416 return currentFormatter.writeCommands(c) | 422 return currentFormatter.writeCommands(c) |
417 } | 423 } |
418 | 424 |
419 func (c *configInternal) OpenAPI(dialOpts api.DialOpts) (st *api.State, newPassw
ord string, err error) { | 425 func (c *configInternal) OpenAPI(dialOpts api.DialOpts) (st *api.State, newPassw
ord string, err error) { |
420 info := api.Info{ | 426 info := api.Info{ |
421 Addrs: c.apiDetails.addresses, | 427 Addrs: c.apiDetails.addresses, |
422 Password: c.apiDetails.password, | 428 Password: c.apiDetails.password, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 } | 473 } |
468 // TODO(rog) remove this fallback behaviour when | 474 // TODO(rog) remove this fallback behaviour when |
469 // all initial connections are via the API. | 475 // all initial connections are via the API. |
470 if !errors.IsUnauthorizedError(err) { | 476 if !errors.IsUnauthorizedError(err) { |
471 return nil, err | 477 return nil, err |
472 } | 478 } |
473 } | 479 } |
474 info.Password = c.oldPassword | 480 info.Password = c.oldPassword |
475 return state.Open(&info, state.DefaultDialOpts(), policy) | 481 return state.Open(&info, state.DefaultDialOpts(), policy) |
476 } | 482 } |
LEFT | RIGHT |