Skip to content

Commit

Permalink
[JENKINS-41124] Found a side-effect where the constructor would have …
Browse files Browse the repository at this point in the history
…side-effects on-disk
  • Loading branch information
stephenc committed Jan 18, 2017
1 parent 7a55e52 commit 9d6e119
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -215,23 +247,6 @@ protected final ChildObserver<I> createEventsChildObserver() {
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}
*/
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9d6e119

Please sign in to comment.