public static File createTempDir ( ) throws IOException { // The previously used approach of creating a temporary file, deleting // it, and making a new directory having the same name in its place is // potentially problematic: // https://stackoverflow.com/questions/617414/how-to-create-a-temporary-directory-folder-in-java // We can use the Java 7 Files.createTempDirectory() API, but note that // by default, the permissions of the created directory are 0700&(~umask) // whereas the old approach created a temporary directory with permissions // 0777&(~umask). // To avoid permissions problems like https://issues.jenkins-ci.org/browse/JENKINS-48407 // we can pass POSIX file permissions as an attribute (see, for example, // https://github.com/jenkinsci/jenkins/pull/3161 ) final Path tempPath ; final String tempDirNamePrefix = "jenkins" ; if ( FileSystems . getDefault ( ) . supportedFileAttributeViews ( ) . contains ( "posix" ) ) { tempPath = Files . createTempDirectory ( tempDirNamePrefix , PosixFilePermissions . asFileAttribute ( EnumSet . allOf ( PosixFilePermission . class ) ) ) ; } else { tempPath = Files . createTempDirectory ( tempDirNamePrefix ) ; } return tempPath . toFile ( ) ; }
Creates a new temporary directory .