Merge pull request #10675 from OlexYarm/jetty-10.0.x

Fixed issue 10305 Embedded Jetty server fails to start when requests path contains not existed directory
This commit is contained in:
Lachlan 2023-10-18 15:34:50 +11:00 committed by GitHub
commit caddfb5a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 2 deletions

View File

@ -233,9 +233,19 @@ public class RolloverFileOutputStream extends OutputStream
File file = new File(_filename);
_filename = file.getCanonicalPath();
file = new File(_filename);
File dir = new File(file.getParent());
if (!dir.isDirectory() || !dir.canWrite())
File dir = file.getParentFile();
if (!dir.exists())
{
throw new IOException("Log directory does not exist. Path=" + dir);
}
else if (!dir.isDirectory())
{
throw new IOException("Path for Log directory is not a directory. Path=" + dir);
}
else if (!dir.canWrite())
{
throw new IOException("Cannot write log directory " + dir);
}
// Is this a rollover file?
String filename = file.getName();

View File

@ -36,7 +36,10 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(WorkDirExtension.class)
public class RolloverFileOutputStreamTest
@ -181,6 +184,26 @@ public class RolloverFileOutputStreamTest
assertSequence(midnight, expected);
}
@Test
public void testMissingDirectory()
{
String templateString = "missingDir/test-rofos-yyyy_mm_dd.log";
Throwable error;
try (RolloverFileOutputStream rofos = new RolloverFileOutputStream(templateString))
{
throw new IllegalStateException();
}
catch (Throwable t)
{
error = t;
}
assertNotNull(error);
assertThat(error, instanceOf(IOException.class));
error.getMessage();
assertThat(error.getMessage(), containsString("Log directory does not exist."));
}
@Test
public void testFileHandling() throws Exception
{