public void save(RawConfiguration config) throws Exception { File f = new File(config.getPath()); FileUtils.writeStringToFile(f, config.getContents()); }
public void mergeStructured(RawConfiguration from, Configuration toUpdate) throws Exception { Augeas aug = null; try { String lens = configMap.get(from.getPath()); aug = createAugeas(lens, from.getContents()); String file = getFile(aug); for (String pathSuffix : nodePaths.get(from.getPath())) { String propName = ("/files" + from.getPath() + "/" + pathSuffix).substring(rootNodePath.length()); String augeasPath = "/files" + file + "/" + pathSuffix; Property property = translator.createProperty(propName, augeasPath, aug); toUpdate.put(property); } } finally { if (aug != null) { aug.close(); } } }
builder.append("[").append(rawConfig.getPath()).append(", ").append(rawConfig.getSha256()).append("]");
public void mergeRawConfig(Configuration from, RawConfiguration existingConfig, RawConfiguration toUpdate) throws Exception { Augeas aug = null; try { String lens = configMap.get(existingConfig.getPath()); aug = createAugeas(lens, existingConfig.getContents()); String file = getFile(aug); for (String pathSuffix : nodePaths.get(existingConfig.getPath())) { String propName = ("/files" + existingConfig.getPath() + "/" + pathSuffix).substring(rootNodePath .length()); String propValue = translator.getPropertyValue(propName, from); aug.set("/files" + file + "/" + pathSuffix, propValue); } aug.save(); toUpdate.setPath(existingConfig.getPath()); String contents = FileUtils.readFileToString(new File(file)); String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents); toUpdate.setContents(contents, sha256); } finally { if (aug != null) { aug.close(); } } }