Skip to content
Permalink
Browse files

[JENKINS-41124] Found a side-effect where the constructor would have …

…side-effects on-disk
  • Loading branch information...
stephenc committed Jan 18, 2017
1 parent 7a55e52 commit 9d6e1198966b2f5e01fd39487678e015dbe0c083
@@ -151,7 +151,39 @@ protected final void init() {
for (Trigger t : triggers) {
t.start(this, Items.currentlyUpdatingByXml());
}
loadComputation();
synchronized (this) {
computation = createComputation(null);
}
}

@Override
public void onCreatedFromScratch() {
try {
FileUtils.forceMkdir(getComputationDir());
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
super.onCreatedFromScratch();
}

@Override
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
try {
FileUtils.forceMkdir(getComputationDir());
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
synchronized (this) {
XmlFile file = computation.getDataFile();
if (file.exists()) {
try {
file.unmarshal(computation);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load " + file, e);
}
}
}
super.onLoad(parent, name);
}

/**
@@ -215,23 +247,6 @@ final void updateChildren(final TaskListener listener) throws IOException, Inter
return new EventChildObserver();
}

private synchronized void loadComputation() {
try {
FileUtils.forceMkdir(getComputationDir());
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
computation = createComputation(null);
XmlFile file = computation.getDataFile();
if (file != null && file.exists()) {
try {
file.unmarshal(computation);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load " + file, e);
}
}
}

/**
* {@inheritDoc}
*/
@@ -60,6 +60,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.jelly.XMLOutput;
import org.kohsuke.stapler.framework.io.ByteBuffer;

@@ -118,6 +119,7 @@ public void run() {
StreamBuildListener listener;
try {
File logFile = getLogFile();
FileUtils.forceMkdir(logFile.getParentFile());
OutputStream os;
if (BACKUP_LOG_COUNT != null) {
os = new ReopenableRotatingFileOutputStream(logFile, BACKUP_LOG_COUNT);
@@ -195,6 +197,7 @@ public File getEventsFile() {

public TaskListener createEventsListener() throws IOException {
File eventsFile = getEventsFile();
FileUtils.forceMkdir(eventsFile.getParentFile());
boolean rotate = eventsFile.length() > EVENT_LOG_MAX_SIZE * 1024;
OutputStream os;
if (BACKUP_LOG_COUNT != null) {

0 comments on commit 9d6e119

Please sign in to comment.
You can’t perform that action at this time.