mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
[JENKINS-67372] Restore support for symbolic links in the Jenkins home directory (#6059)
This commit is contained in:
1 parent
a21070985f
commit
27646d11e4
15 files changed
+125
-16
No files matched your search
@@ -67,6 +67,7 @@ import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.DosFileAttributes;
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.security.DigestInputStream;
|
||||
@@ -1727,6 +1728,63 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory by creating all nonexistent parent directories first.
|
||||
*
|
||||
* <p>Unlike {@link Files#createDirectory}, an exception is not thrown
|
||||
* if the directory could not be created because it already exists.
|
||||
* Unlike {@link Files#createDirectories}, an exception is not thrown
|
||||
* if the directory (or one of its parents) is a symbolic link.
|
||||
*
|
||||
* <p>The {@code attrs} parameter contains optional {@link FileAttribute file attributes}
|
||||
* to set atomically when creating the nonexistent directories.
|
||||
* Each file attribute is identified by its {@link FileAttribute#name}.
|
||||
* If more than one attribute of the same name is included in the array,
|
||||
* then all but the last occurrence is ignored.
|
||||
*
|
||||
* <p>If this method fails,
|
||||
* then it may do so after creating some, but not all, of the parent directories.
|
||||
*
|
||||
* @param dir The directory to create.
|
||||
* @param attrs An optional list of file attributes to set atomically
|
||||
* when creating the directory.
|
||||
* @return The directory.
|
||||
* @throws UnsupportedOperationException If the array contains an attribute
|
||||
* that cannot be set atomically when creating the directory.
|
||||
* @throws FileAlreadyExistsException If {@code dir} exists but is not a directory.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
* @see Files#createDirectories(Path, FileAttribute[])
|
||||
*/
|
||||
@Restricted(NoExternalUse.class)
|
||||
public static Path createDirectories(@NonNull Path dir, FileAttribute<?>... attrs) throws IOException {
|
||||
dir = dir.toAbsolutePath();
|
||||
|
||||
Path parent;
|
||||
for (parent = dir.getParent(); parent != null; parent = parent.getParent()) {
|
||||
if (Files.exists(parent)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent == null) {
|
||||
if (Files.isDirectory(dir)) {
|
||||
return dir;
|
||||
} else {
|
||||
return Files.createDirectory(dir, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
Path child = parent;
|
||||
for (Path name : parent.relativize(dir)) {
|
||||
child = child.resolve(name);
|
||||
if (!Files.isDirectory(child)) {
|
||||
Files.createDirectory(child, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the number of calendar days elapsed since the given date.
|
||||
* As it's only the calendar days difference that matter, "11.00pm" to "2.00am the day after" returns 1,
|
||||
|
||||
Reference in new issue
Block a user