DRY near-duplicate code between parse-{addresses,prefixces}
This commit is contained in:
parent
907a9de773
commit
9487cb2567
1 changed files with 8 additions and 8 deletions
|
@ -40,21 +40,21 @@
|
||||||
(merge {: address : len : preferred : valid} (parse-extra extra))))
|
(merge {: address : len : preferred : valid} (parse-extra extra))))
|
||||||
|
|
||||||
|
|
||||||
(fn write-addresses [addresses]
|
(fn write-addresses-thing [prefix addresses]
|
||||||
(each [_ a (ipairs (split " " addresses))]
|
(each [_ a (ipairs (split " " addresses))]
|
||||||
(let [address (parse-address a)
|
(let [address (parse-address a)
|
||||||
keydir (.. "address/" (address.address:gsub ":" "-"))]
|
keydir (.. prefix (-> address.address
|
||||||
|
(: :gsub "::$" "")
|
||||||
|
(: :gsub ":" "-")))]
|
||||||
(mkdir (.. state-directory "/" keydir))
|
(mkdir (.. state-directory "/" keydir))
|
||||||
(each [k v (pairs address)]
|
(each [k v (pairs address)]
|
||||||
(write-value (.. keydir "/" k) v)))))
|
(write-value (.. keydir "/" k) v)))))
|
||||||
|
|
||||||
|
(fn write-addresses [addresses]
|
||||||
|
(write-addresses-thing "address/" addresses))
|
||||||
|
|
||||||
(fn write-prefixes [prefixes]
|
(fn write-prefixes [prefixes]
|
||||||
(each [_ a (ipairs (split " " prefixes))]
|
(write-addresses-thing "prefix/" prefixes))
|
||||||
(let [prefix (parse-prefix a)
|
|
||||||
keydir (.. "prefix/" (prefix.prefix:gsub ":" "-"))]
|
|
||||||
(mkdir (.. state-directory "/" keydir))
|
|
||||||
(each [k v (pairs prefix)]
|
|
||||||
(write-value (.. keydir "/" k) v)))))
|
|
||||||
|
|
||||||
;; we remove state before updating to ensure that consumers don't get
|
;; we remove state before updating to ensure that consumers don't get
|
||||||
;; a half-updated snapshot
|
;; a half-updated snapshot
|
||||||
|
|
Loading…
Reference in a new issue