LEFT | RIGHT |
(no file at all) | |
1 // launchpad.net/juju/state | 1 // launchpad.net/juju/state |
2 // | 2 // |
3 // Copyright (c) 2011-2012 Canonical Ltd. | 3 // Copyright (c) 2011-2012 Canonical Ltd. |
4 | 4 |
5 package state | 5 package state |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "fmt" | 9 "fmt" |
10 "launchpad.net/goyaml" | 10 "launchpad.net/goyaml" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 c := &ConfigNode{ | 73 c := &ConfigNode{ |
74 zk: zk, | 74 zk: zk, |
75 path: path, | 75 path: path, |
76 pristineCache: make(map[string]interface{}), | 76 pristineCache: make(map[string]interface{}), |
77 cache: copyCache(values), | 77 cache: copyCache(values), |
78 } | 78 } |
79 _, err := c.Write() | 79 _, err := c.Write() |
80 if err != nil { | 80 if err != nil { |
81 return nil, err | 81 return nil, err |
82 } | 82 } |
| 83 return c, nil |
| 84 } |
| 85 |
| 86 // parseConfigNode creates a config node based on a pre-read content. |
| 87 func parseConfigNode(zk *zookeeper.Conn, path, content string) (*ConfigNode, err
or) { |
| 88 c := &ConfigNode{ |
| 89 zk: zk, |
| 90 path: path, |
| 91 } |
| 92 if err := goyaml.Unmarshal([]byte(content), &c.cache); err != nil { |
| 93 return nil, err |
| 94 } |
| 95 c.pristineCache = copyCache(c.cache) |
83 return c, nil | 96 return c, nil |
84 } | 97 } |
85 | 98 |
86 // readConfigNode returns the ConfigNode for path. | 99 // readConfigNode returns the ConfigNode for path. |
87 func readConfigNode(zk *zookeeper.Conn, path string) (*ConfigNode, error) { | 100 func readConfigNode(zk *zookeeper.Conn, path string) (*ConfigNode, error) { |
88 c := &ConfigNode{ | 101 c := &ConfigNode{ |
89 zk: zk, | 102 zk: zk, |
90 path: path, | 103 path: path, |
91 } | 104 } |
92 if err := c.Read(); err != nil { | 105 if err := c.Read(); err != nil { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 b >= '0' && b <= '9', | 298 b >= '0' && b <= '9', |
286 b == '.', | 299 b == '.', |
287 b == '-': | 300 b == '-': |
288 safe = append(safe, b) | 301 safe = append(safe, b) |
289 default: | 302 default: |
290 safe = append(safe, fmt.Sprintf("_%02x_", b)...) | 303 safe = append(safe, fmt.Sprintf("_%02x_", b)...) |
291 } | 304 } |
292 } | 305 } |
293 return string(safe) | 306 return string(safe) |
294 } | 307 } |
LEFT | RIGHT |