Skip to content

Commit

Permalink
Fix spotbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandell committed Jan 21, 2022
1 parent e50b8cc commit 416cdaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.jenkinsci.plugins.pipeline.utility.steps.fs;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Set;
Expand Down Expand Up @@ -146,9 +147,12 @@ protected FileWrapper run() throws Exception {
final FilePath ws = this.getContext().get(FilePath.class);
assert ws != null;
final FilePath file = ws.child(this.step.getFile());
if (!file.exists()) {
file.getParent().mkdirs();
FilePath parent = file.getParent();
if (!file.exists() && parent != null) {
parent.mkdirs();
file.touch(System.currentTimeMillis());
} else if (parent == null) {
throw new IOException("No parent path for " + file.getRemote());
}
final String content = this.step.getContent();
final String originalContent = file.readToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;

import java.io.IOException;
import java.util.Collections;
import java.util.Set;

Expand Down Expand Up @@ -143,7 +144,12 @@ protected FileWrapper run() throws Exception {
assert ws != null;
FilePath file = ws.child(step.getFile());
long timestamp = step.getTimestamp() != null ? step.getTimestamp() : System.currentTimeMillis();
file.getParent().mkdirs();
final FilePath parent = file.getParent();
if (parent != null) {
parent.mkdirs();
} else {
throw new IOException("No parent path for " + file.getRemote());
}
file.touch(timestamp);
return new FileWrapper(file);
}
Expand Down

0 comments on commit 416cdaa

Please sign in to comment.