Skip to content

Commit

Permalink
Missing VirtualFile.run usage in DirectoryBrowserSupport (#8874)
Browse files Browse the repository at this point in the history
* Missing `VirtualFile.run` usage in `DirectoryBrowserSupport`

* Might as well handle `containsSymLink` the same way. Will never matter for artifact display with either the built-in or pluggable managers, but could improve performance of workspace listing with slow agent connections.

* Checkstyle

---------

Co-authored-by: Daniel Beck <daniel-beck@users.noreply.github.com>
  • Loading branch information
jglick and daniel-beck authored Jan 25, 2024
1 parent ae9b71c commit a665b45
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions core/src/main/java/hudson/model/DirectoryBrowserSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ private void serveFile(StaplerRequest req, StaplerResponse rsp, VirtualFile root
} else
if (serveDirIndex) {
// serve directory index
glob = baseFile.run(new BuildChildPaths(root, baseFile, req.getLocale()));
containsSymlink = baseFile.containsSymLinkChild(getOpenOptions());
containsTmpDir = baseFile.containsTmpDirChild(getOpenOptions());
var result = baseFile.run(new BuildChildPaths(baseFile, req.getLocale(), getOpenOptions()));
glob = result.glob;
containsSymlink = result.containsSymLink;
containsTmpDir = result.containsTmpDir;
}

if (glob != null) {
Expand Down Expand Up @@ -747,19 +748,32 @@ private int dirRank(VirtualFile f) {
}
}

private static final class BuildChildPaths extends MasterToSlaveCallable<List<List<Path>>, IOException> {
private VirtualFile root;
private static final class BuildChildPathsResult implements Serializable { // TODO Java 21+ record
private static final long serialVersionUID = 1;
private final List<List<Path>> glob;
private final boolean containsSymLink;
private final boolean containsTmpDir;

BuildChildPathsResult(List<List<Path>> glob, boolean containsSymLink, boolean containsTmpDir) {
this.glob = glob;
this.containsSymLink = containsSymLink;
this.containsTmpDir = containsTmpDir;
}
}

private static final class BuildChildPaths extends MasterToSlaveCallable<BuildChildPathsResult, IOException> {
private final VirtualFile cur;
private final Locale locale;
private final OpenOption[] openOptions;

BuildChildPaths(VirtualFile root, VirtualFile cur, Locale locale) {
this.root = root;
BuildChildPaths(VirtualFile cur, Locale locale, OpenOption[] openOptions) {
this.cur = cur;
this.locale = locale;
this.openOptions = openOptions;
}

@Override public List<List<Path>> call() throws IOException {
return buildChildPaths(cur, locale);
@Override public BuildChildPathsResult call() throws IOException {
return new BuildChildPathsResult(buildChildPaths(cur, locale), cur.containsSymLinkChild(openOptions), cur.containsTmpDirChild(openOptions));
}
}
/**
Expand Down

0 comments on commit a665b45

Please sign in to comment.