Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
Lachlan Roberts 2023-10-18 15:35:11 +11:00
commit 52b91c42df
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
{