Dedup code

This commit is contained in:
Fritz Elfert committed 2015-10-09 10:40:34 +02:00
1 parent 63d01f6b9d
commit e1fb8f449e
1 file changed
+19 -16
+19 -16
View File
@@ -137,14 +137,24 @@ public class Nodes implements Saveable {
jenkins.trimLabels();
}
});
// no need for a full save() so we just do the minimum
if (node instanceof EphemeralNode) {
Util.deleteRecursive(new File(getNodesDir(), node.getNodeName()));
} else {
XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM,
new File(new File(getNodesDir(), node.getNodeName()), "config.xml"));
xmlFile.write(node);
}
persistNode(node);
}
}
/**
* Actually persists a node on disk.
*
* @param node the node to be persisted.
* @throws IOException if the node could not be persisted.
*/
private void persistNode(final @Nonnull Node node) throws IOException {
// no need for a full save() so we just do the minimum
if (node instanceof EphemeralNode) {
Util.deleteRecursive(new File(getNodesDir(), node.getNodeName()));
} else {
XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM,
new File(new File(getNodesDir(), node.getNodeName()), "config.xml"));
xmlFile.write(node);
}
}
@@ -156,14 +166,7 @@ public class Nodes implements Saveable {
*/
public void updateNode(final @Nonnull Node node) throws IOException {
if (node == nodes.get(node.getNodeName())) {
// no need for a full save() so we just do the minimum
if (node instanceof EphemeralNode) {
Util.deleteRecursive(new File(getNodesDir(), node.getNodeName()));
} else {
XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM,
new File(new File(getNodesDir(), node.getNodeName()), "config.xml"));
xmlFile.write(node);
}
persistNode(node);
}
}