diff options
author | Jakob Borg <jakob@nym.se> | 2014-05-25 20:49:08 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-05-25 20:49:08 +0200 |
commit | 3d055bbb79166e3dfe35d496ddd0fc94fd2f7563 (patch) | |
tree | fcb5aed5d6d654a088b2683c8a34d291f25561e7 /config | |
parent | dd971b56e502795310bb4e24b8df4998e38f7a14 (diff) |
Simple file versioning (fixes #218)
Diffstat (limited to 'config')
-rw-r--r-- | config/config.go | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/config/config.go b/config/config.go index 18acd27097..1698650dd9 100644 --- a/config/config.go +++ b/config/config.go @@ -27,13 +27,56 @@ type Configuration struct { } type RepositoryConfiguration struct { - ID string `xml:"id,attr"` - Directory string `xml:"directory,attr"` - Nodes []NodeConfiguration `xml:"node"` - ReadOnly bool `xml:"ro,attr"` - IgnorePerms bool `xml:"ignorePerms,attr"` - Invalid string `xml:"-"` // Set at runtime when there is an error, not saved - nodeIDs []string + ID string `xml:"id,attr"` + Directory string `xml:"directory,attr"` + Nodes []NodeConfiguration `xml:"node"` + ReadOnly bool `xml:"ro,attr"` + IgnorePerms bool `xml:"ignorePerms,attr"` + Invalid string `xml:"-"` // Set at runtime when there is an error, not saved + Versioning VersioningConfiguration `xml:"versioning"` + + nodeIDs []string +} + +type VersioningConfiguration struct { + Type string `xml:"type,attr"` + Params map[string]string +} + +type InternalVersioningConfiguration struct { + Type string `xml:"type,attr,omitempty"` + Params []InternalParam `xml:"param"` +} + +type InternalParam struct { + Key string `xml:"key,attr"` + Val string `xml:"val,attr"` +} + +func (c *VersioningConfiguration) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + var tmp InternalVersioningConfiguration + tmp.Type = c.Type + for k, v := range c.Params { + tmp.Params = append(tmp.Params, InternalParam{k, v}) + } + + return e.EncodeElement(tmp, start) + +} + +func (c *VersioningConfiguration) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + var tmp InternalVersioningConfiguration + err := d.DecodeElement(&tmp, &start) + if err != nil { + return err + } + + c.Type = tmp.Type + c.Params = make(map[string]string, len(tmp.Params)) + for _, p := range tmp.Params { + c.Params[p.Key] = p.Val + } + return nil } func (r *RepositoryConfiguration) NodeIDs() []string { |