提交 f23b93a6 编写于 作者: M mawinter69 提交者: Oleg Nenashev

[JENKINS-57855] read-only flag of folders on windows (#4059)

* [JENKINS-57855] read-only flag of folders on windows

On windows the current way of removing the read only flag is not working
for folders.
Using the Files api this can be solved.

* code formatting
上级 cd5d67d4
......@@ -24,18 +24,13 @@
package jenkins.util.io;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Functions;
import hudson.Util;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
......@@ -45,6 +40,15 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Functions;
import hudson.Util;
@Restricted(NoExternalUse.class)
public class PathRemover {
......@@ -285,6 +289,14 @@ public class PathRemover {
} catch (UnsupportedOperationException ignored) {
// PosixFileAttributes not supported, fall back to old IO.
}
} else {
/*
* If on Windows a folder has a read only attribute set, the file.setWritable(true) doesn't work (JENKINS-57855)
*/
DosFileAttributeView dos = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (dos != null) {
dos.setReadOnly(false);
}
}
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册