Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3f01a77
[JENKINS-49635] Defining new VirtualFile methods to better support ex…
jglick Feb 19, 2018
8e603a5
[JENKINS-26810] Added VirtualFile.mode.
jglick Feb 21, 2018
e773bdb
New VirtualFile.list overload with more capabilities and more precise…
jglick Feb 21, 2018
4911c5c
More compatible default implementation of VirtualFile.list(String, St…
jglick Feb 21, 2018
e3e6d57
VirtualFile.readLink
jglick Feb 21, 2018
2e070ca
Forgotten since tags.
jglick Feb 21, 2018
9735a34
Compilation error.
jglick Feb 21, 2018
a9430d3
Mistake caught by DirectoryBrowserSupportTest.zipDownload.
jglick Feb 21, 2018
e0fab1a
list(String, String, boolean) was returning \-separated paths on Wind…
jglick Feb 21, 2018
9ccffba
SelectorUtils.tokenizePath apparently expects the native path separat…
jglick Feb 21, 2018
7131067
Minor comments and simplifications.
jglick Feb 21, 2018
9b9f81d
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Feb 28, 2018
23f12fd
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Mar 5, 2018
63885e6
Typo noticed by @olivergondza.
jglick Mar 5, 2018
64ee6fd
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Mar 6, 2018
c7372cc
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Mar 12, 2018
fca93db
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Mar 13, 2018
d32b9b1
@oleg-nenashev suggests documenting behavior of VirtualFile.mode on s…
jglick Mar 14, 2018
beea2aa
More details on toURI and toExternalURL.
jglick Mar 14, 2018
7223632
Should not attempt to call VirtualFile.child with the empty string.
jglick Mar 16, 2018
d3f5346
Merge branch 'SystemProperties-JENKINS-46386' into VirtualFile-JENKIN…
jglick Mar 21, 2018
2e1af78
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Mar 23, 2018
90fd89f
Use run(Callable) from the default list(String, String, boolean) so i…
jglick Mar 23, 2018
9b75cd2
Making Run.getArtifactsUpTo call VirtualFile.run.
jglick Mar 23, 2018
8e60538
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Mar 26, 2018
2090468
Using new beta annotation.
jglick Mar 26, 2018
a345051
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Apr 2, 2018
547fd6f
Removing VirtualFile.asRemotable in favor of toExternalURL.
jglick Apr 2, 2018
a54d49b
access-modifier.version=1.14
jglick Apr 3, 2018
d25c0b2
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Apr 13, 2018
8f5d1d3
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Apr 16, 2018
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
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ public static File resolveSymlinkToFile(@Nonnull File link) throws InterruptedEx
* The relative path is meant to be resolved from the location of the symlink.
*/
@CheckForNull
public static String resolveSymlink(@Nonnull File link) throws InterruptedException, IOException {
public static String resolveSymlink(@Nonnull File link) throws IOException {
Copy link
Member Author

Choose a reason for hiding this comment

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

Binary compatible simplification—the body never actually threw that exception.

Copy link
Member

Choose a reason for hiding this comment

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

Not source compatible IIRC (javac fails when there is a catch block for impossible exception), may impact PCT. There are usages of it externally, e.g. in the Support Core plugin: https://github.com/search?p=1&q=org%3Ajenkinsci+resolveSymlink&type=Code

I would propose to detach it to a separate PR if you feel it's important enough

Copy link
Member

Choose a reason for hiding this comment

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

@oleg-nenashev Jesse already disputed this in #3340 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, PCT should be unaffected, though it could impede

buildPlugin(jenkinsVersions: [null, '2.222']) // or whatever

Why the Java language treats an exception which cannot be thrown as a fatal error rather than a warning (ditto unreachable statements etc.), I do not know.

Copy link
Member Author

Choose a reason for hiding this comment

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

The simple workaround for the buildPlugin case would be to just catch (Exception I guess.

Copy link
Member

Choose a reason for hiding this comment

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

would be better to fix it tho

try {
Path path = link.toPath();
return Files.readSymbolicLink(path).toString();
Expand All @@ -1415,7 +1415,7 @@ public static String resolveSymlink(@Nonnull File link) throws InterruptedExcept
} catch (IOException x) {
throw x;
} catch (Exception x) {
throw (IOException) new IOException(x.toString()).initCause(x);
throw new IOException(x);
}
}

Expand Down
19 changes: 15 additions & 4 deletions core/src/main/java/hudson/model/DirectoryBrowserSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.URL;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
Expand All @@ -51,6 +53,7 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand Down Expand Up @@ -295,6 +298,14 @@ private void serveFile(StaplerRequest req, StaplerResponse rsp, VirtualFile root
return;
}

URL external = baseFile.toExternalURL();
if (external != null) {
// or this URL could be emitted directly from dir.jelly
// though we would prefer to delay toExternalURL calls unless and until needed
rsp.sendRedirect2(external.toExternalForm());
return;
}

long lastModified = baseFile.lastModified();
long length = baseFile.length();

Expand Down Expand Up @@ -355,7 +366,7 @@ private static String createBackRef(int times) {
private static void zip(OutputStream outputStream, VirtualFile dir, String glob) throws IOException {
try (ZipOutputStream zos = new ZipOutputStream(outputStream)) {
zos.setEncoding(System.getProperty("file.encoding")); // TODO JENKINS-20663 make this overridable via query parameter
for (String n : dir.list(glob.length() == 0 ? "**" : glob)) {
for (String n : dir.list(glob.isEmpty() ? "**" : glob, null, /* TODO what is the user expectation? */true)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Retaining default excludes functionality here to maintain semantics but I am unsure whether users would want this or not.

String relativePath;
if (glob.length() == 0) {
// JENKINS-19947: traditional behavior is to prepend the directory name
Expand Down Expand Up @@ -535,10 +546,10 @@ private static List<List<Path>> buildChildPaths(VirtualFile cur, Locale locale)
* @param baseRef String like "../../../" that cancels the 'rest' portion. Can be "./"
*/
private static List<List<Path>> patternScan(VirtualFile baseDir, String pattern, String baseRef) throws IOException {
String[] files = baseDir.list(pattern);
Collection<String> files = baseDir.list(pattern, null, /* TODO what is the user expectation? */true);
Copy link
Member

Choose a reason for hiding this comment

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

Note that there was a JEP-200 regression in the similar code recently

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, in DirScanner.Glob IIRC, which is called by some list implementations.


if (files.length > 0) {
List<List<Path>> r = new ArrayList<List<Path>>(files.length);
if (!files.isEmpty()) {
List<List<Path>> r = new ArrayList<List<Path>>(files.size());
for (String match : files) {
List<Path> file = buildPathList(baseDir, baseDir.child(match), baseRef);
r.add(file);
Expand Down
21 changes: 8 additions & 13 deletions core/src/main/java/hudson/util/DirScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.Serializable;

import static hudson.Util.fixEmpty;
Expand All @@ -31,19 +30,15 @@ public abstract class DirScanner implements Serializable {
*/
protected final void scanSingle(File f, String relative, FileVisitor visitor) throws IOException {
if (visitor.understandsSymlink()) {
String target;
try {
String target;
try {
target = Util.resolveSymlink(f);
} catch (IOException x) { // JENKINS-13202
target = null;
}
if (target != null) {
visitor.visitSymlink(f, target, relative);
return;
}
} catch (InterruptedException e) {
throw (IOException) new InterruptedIOException().initCause(e);
target = Util.resolveSymlink(f);
} catch (IOException x) { // JENKINS-13202
target = null;
Copy link
Member

Choose a reason for hiding this comment

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

Add logging while you are around?

Copy link
Member Author

Choose a reason for hiding this comment

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

Preferred to avoid making unrelated changes.

Copy link
Member

Choose a reason for hiding this comment

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

agreed

}
if (target != null) {
visitor.visitSymlink(f, target, relative);
return;
}
}
visitor.visit(f, relative);
Expand Down
Loading