github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/agent/export_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package agent
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  
    10  	"github.com/juju/juju/state/multiwatcher"
    11  )
    12  
    13  func PatchConfig(config Config, fieldName string, value interface{}) error {
    14  	conf := config.(*configInternal)
    15  	switch fieldName {
    16  	case "Paths":
    17  		paths := value.(Paths)
    18  		if paths.DataDir != "" {
    19  			conf.paths.DataDir = paths.DataDir
    20  		}
    21  		if paths.LogDir != "" {
    22  			conf.paths.LogDir = paths.LogDir
    23  		}
    24  	case "Jobs":
    25  		conf.jobs = value.([]multiwatcher.MachineJob)[:]
    26  	case "DeleteValues":
    27  		for _, key := range value.([]string) {
    28  			delete(conf.values, key)
    29  		}
    30  	case "Values":
    31  		for key, val := range value.(map[string]string) {
    32  			if conf.values == nil {
    33  				conf.values = make(map[string]string)
    34  			}
    35  			conf.values[key] = val
    36  		}
    37  	default:
    38  		return fmt.Errorf("unknown field %q", fieldName)
    39  	}
    40  	conf.configFilePath = ConfigPath(conf.paths.DataDir, conf.tag)
    41  	return nil
    42  }
    43  
    44  func ConfigFileExists(config Config) bool {
    45  	conf := config.(*configInternal)
    46  	_, err := os.Lstat(conf.configFilePath)
    47  	return err == nil
    48  }
    49  
    50  func EmptyConfig() Config {
    51  	return &configInternal{}
    52  }