예제 #1
0
func updateConfig(config *lib.Config, configMap map[string]interface{}) bool {
	dirty := commonUpdateConfig(config, configMap)

	if _, exists := configMap["log_file_name"]; !exists {
		dirty = true
		fmt.Println("Added log_file_name")
		config.LogFileName = lib.DefaultConfig.LogFileName
	}
	if _, exists := configMap["log_file_max_megabytes"]; !exists {
		dirty = true
		fmt.Println("Added log_file_max_megabytes")
		config.LogFileMaxMegabytes = lib.DefaultConfig.LogFileMaxMegabytes
	}
	if _, exists := configMap["log_max_files"]; !exists {
		dirty = true
		fmt.Println("Added log_max_files")
		config.LogMaxFiles = lib.DefaultConfig.LogMaxFiles
	}
	if _, exists := configMap["log_to_journal"]; !exists {
		dirty = true
		fmt.Println("Added log_to_journal")
		config.LogToJournal = lib.DefaultConfig.LogToJournal
	}
	if _, exists := configMap["monitor_socket_filename"]; !exists {
		dirty = true
		fmt.Println("Added monitor_socket_filename")
		config.MonitorSocketFilename = lib.DefaultConfig.MonitorSocketFilename
	}
	if _, exists := configMap["cups_max_connections"]; !exists {
		dirty = true
		fmt.Println("Added cups_max_connections")
		config.CUPSMaxConnections = lib.DefaultConfig.CUPSMaxConnections
	}
	if _, exists := configMap["cups_connect_timeout"]; !exists {
		dirty = true
		fmt.Println("Added cups_connect_timeout")
		config.CUPSConnectTimeout = lib.DefaultConfig.CUPSConnectTimeout
	}
	if _, exists := configMap["cups_printer_attributes"]; !exists {
		dirty = true
		fmt.Println("Added cups_printer_attributes")
		config.CUPSPrinterAttributes = lib.DefaultConfig.CUPSPrinterAttributes
	} else {
		// Make sure all required attributes are present.
		s := make(map[string]struct{}, len(config.CUPSPrinterAttributes))
		for _, a := range config.CUPSPrinterAttributes {
			s[a] = struct{}{}
		}
		for _, a := range lib.DefaultConfig.CUPSPrinterAttributes {
			if _, exists := s[a]; !exists {
				dirty = true
				fmt.Printf("Added %s to cups_printer_attributes\n", a)
				config.CUPSPrinterAttributes = append(config.CUPSPrinterAttributes, a)
			}
		}
	}
	if _, exists := configMap["cups_job_full_username"]; !exists {
		dirty = true
		fmt.Println("Added cups_job_full_username")
		config.CUPSJobFullUsername = lib.DefaultConfig.CUPSJobFullUsername
	}
	if _, exists := configMap["cups_ignore_raw_printers"]; !exists {
		dirty = true
		fmt.Println("Added cups_ignore_raw_printers")
		config.CUPSIgnoreRawPrinters = lib.DefaultConfig.CUPSIgnoreRawPrinters
	}
	if _, exists := configMap["cups_ignore_class_printers"]; !exists {
		dirty = true
		fmt.Println("Added cups_ignore_class_printers")
		config.CUPSIgnoreClassPrinters = lib.DefaultConfig.CUPSIgnoreClassPrinters
	}
	if _, exists := configMap["copy_printer_info_to_display_name"]; !exists {
		dirty = true
		fmt.Println("Added copy_printer_info_to_display_name")
		config.CUPSCopyPrinterInfoToDisplayName = lib.DefaultConfig.CUPSCopyPrinterInfoToDisplayName
	}

	return dirty
}