Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a tmp directory when such doesn't exist. In some cases the tmp… #10002

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/src/main/java/hudson/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@
// https://github.com/jenkinsci/jenkins/pull/3161 )
final Path tempPath;
final String tempDirNamePrefix = "jenkins";

final Path systemTmpDirectoryPath = Path.of(System.getProperty("java.io.tmpdir"));
if (!systemTmpDirectoryPath.toFile().exists()){

Check warning on line 441 in core/src/main/java/hudson/Util.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 441 is only partially covered, one branch is missing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!systemTmpDirectoryPath.toFile().exists()){
if (!systemTmpDirectoryPath.toFile().exists()) {

// In some cases the tmp directory set in the java.io.tmpdir property will not exist and hence will have to
// be created here.
systemTmpDirectoryPath.toFile().mkdirs();

Check warning on line 444 in core/src/main/java/hudson/Util.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 444 is not covered by tests

Check warning on line 444 in core/src/main/java/hudson/Util.java

View check run for this annotation

ci.jenkins.io / SpotBugs

RV_RETURN_VALUE_IGNORED_BAD_PRACTICE

NORMAL: Exceptional return value of java.io.File.mkdirs() ignored in hudson.Util.createTempDir()
Raw output
<p> This method returns a value that is not checked. The return value should be checked since it can indicate an unusual or unexpected function execution. For example, the <code>File.delete()</code> method returns false if the file could not be successfully deleted (rather than throwing an Exception). If you don't check the result, you won't notice if the method invocation signals unexpected behavior by returning an atypical return value. </p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Files.createDirectory instead should avoid the SpotBugs warning.

}

if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
tempPath = Files.createTempDirectory(tempDirNamePrefix,
PosixFilePermissions.asFileAttribute(EnumSet.allOf(PosixFilePermission.class)));
Expand Down
Loading