-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jetty 12 - Issue #8474 - return null on resolve() if resource doesn't exist #8597
Changes from 19 commits
20f4b5c
bd29121
8482ce3
74acb62
7f86ec1
d2e57e4
1812737
9ad61ec
0c05840
1a49f7e
cb795ab
5b811f5
459ea92
72abb2a
7edb795
1f2b73d
1e43680
2335007
fdba6ed
c549a97
dedf53d
7369e11
ebe0ce4
4438232
ade5345
6fa6199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,7 +226,7 @@ protected void doStart() throws Exception | |
List<Path> files = new ArrayList<>(); | ||
for (Resource resource : _monitored) | ||
{ | ||
if (resource.exists() && Files.isReadable(resource.getPath())) | ||
if (resource != null && Files.isReadable(resource.getPath())) | ||
files.add(resource.getPath()); | ||
else | ||
LOG.warn("Does not exist: {}", resource); | ||
|
@@ -339,7 +339,11 @@ public void setDeploymentManager(DeploymentManager deploymentManager) | |
public void setMonitoredResources(List<Resource> resources) | ||
{ | ||
_monitored.clear(); | ||
_monitored.addAll(resources); | ||
for (Resource resource: resources) | ||
{ | ||
if (resource != null) | ||
_monitored.addAll(resources); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding the |
||
} | ||
} | ||
|
||
public List<Resource> getMonitoredResources() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ DO NOT USE IN PRODUCTION!!! | |
demo | ||
ssl | ||
|
||
[depend] | ||
[before] | ||
ssl | ||
|
||
[files] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -720,7 +720,18 @@ public void setBaseResource(Resource resourceBase) | |
|
||
public void setBaseResource(Path path) | ||
{ | ||
setBaseResource(path == null ? null : ResourceFactory.root().newResource(path)); | ||
if (path == null) | ||
{ | ||
// allow user to unset variable | ||
setBaseResource((Resource)null); | ||
return; | ||
} | ||
|
||
Resource resource = ResourceFactory.root().newResource(path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
if (resource == null) | ||
throw new IllegalArgumentException("Base Resource does not exist: " + path); | ||
|
||
setBaseResource(resource); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.eclipse.jetty.util.URIUtil; | ||
|
||
|
@@ -26,6 +28,14 @@ | |
*/ | ||
public class MountedPathResource extends PathResource | ||
{ | ||
public static MountedPathResource of(URI uri) throws IOException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
{ | ||
Path path = Paths.get(uri.normalize()); | ||
if (!Files.exists(path)) | ||
return null; | ||
return new MountedPathResource(path, uri); | ||
} | ||
|
||
private final URI containerUri; | ||
|
||
MountedPathResource(URI uri) throws IOException | ||
|
@@ -34,6 +44,18 @@ public class MountedPathResource extends PathResource | |
containerUri = URIUtil.unwrapContainer(getURI()); | ||
} | ||
|
||
MountedPathResource(Path path, URI uri) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the other constructor still needed? |
||
{ | ||
super(path, uri, true); | ||
containerUri = URIUtil.unwrapContainer(getURI()); | ||
} | ||
|
||
@Override | ||
protected Resource newResource(Path path, URI uri) | ||
{ | ||
return new MountedPathResource(path, uri); | ||
} | ||
|
||
@Override | ||
public boolean isContainedIn(Resource r) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,14 @@ public class PathResource extends Resource | |
.with("jrt") | ||
.build(); | ||
|
||
public static PathResource of(URI uri) throws IOException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
{ | ||
Path path = Paths.get(uri.normalize()); | ||
if (!Files.exists(path)) | ||
return null; | ||
return new PathResource(path, uri, false); | ||
} | ||
|
||
private final Path path; | ||
private final URI uri; | ||
private boolean targetResolved = false; | ||
|
@@ -247,9 +255,53 @@ public int hashCode() | |
return Objects.hashCode(path); | ||
} | ||
|
||
@Override | ||
public Resource resolve(String subUriPath) | ||
joakime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// Check that the path is within the root, | ||
// but use the original path to create the | ||
// resource, to preserve aliasing. | ||
// TODO do a URI safe encoding? | ||
if (URIUtil.isNotNormalWithinSelf(subUriPath)) | ||
throw new IllegalArgumentException(subUriPath); | ||
|
||
if (URIUtil.SLASH.equals(subUriPath)) | ||
return this; | ||
|
||
// Sub-paths are always resolved under the given URI, | ||
// we compensate for input sub-paths like "/subdir" | ||
// where default resolve behavior would be to treat | ||
// that like an absolute path. | ||
while (subUriPath.startsWith(URIUtil.SLASH)) | ||
{ | ||
// TODO XXX this appears entirely unnecessary and inefficient. We already have utilities | ||
// to handle appending path strings with/without slashes. | ||
subUriPath = subUriPath.substring(1); | ||
} | ||
joakime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
URI uri = getURI(); | ||
URI resolvedUri = URIUtil.addPath(uri, subUriPath); | ||
Path path = Paths.get(resolvedUri.normalize()); | ||
joakime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (Files.exists(path)) | ||
return newResource(path, resolvedUri); | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Internal override for creating a new PathResource. | ||
* Used by MountedPathResource (eg) | ||
*/ | ||
protected Resource newResource(Path path, URI uri) | ||
{ | ||
return new PathResource(path, uri, true); | ||
} | ||
|
||
@Override | ||
public boolean isContainedIn(Resource r) | ||
{ | ||
if (r == null) | ||
return false; | ||
return r.getClass() == PathResource.class && path.startsWith(r.getPath()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,8 +126,8 @@ public Resource resolve(String subUriPath) | |
for (Resource res : _resources) | ||
{ | ||
addedResource = res.resolve(subUriPath); | ||
if (!addedResource.exists()) | ||
continue; | ||
if (addedResource == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think more changes below are needed for code clarity. specifically if resources == null, can we just explicitly return null? |
||
continue; // skip, doesn't exist | ||
if (!addedResource.isDirectory()) | ||
return addedResource; // Return simple (non-directory) Resource | ||
if (resources == null) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not adding
null
s into_monitored
for non-existing resources, so this null check can go away.