Skip to content
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

Improve DEBUG during WebInfConfiguration.unpack #11455

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions jetty-core/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,22 @@ public void testDeleteNonExistentFile(WorkDir workDir)
assertFalse(IO.delete(noFile.toFile()));
}

@Test
public void testDeleteTreeDeep(WorkDir workDir) throws IOException
{
Path dir = workDir.getEmptyPathDir();
FS.ensureEmpty(dir);

Files.createDirectory(dir.resolve("foo"));
Files.createDirectory(dir.resolve("foo/bar"));
Files.createDirectory(dir.resolve("foo/zed"));
Files.createDirectory(dir.resolve("foo/zed/one"));
Files.writeString(dir.resolve("foo/bar/test.txt"), "Test");
Files.writeString(dir.resolve("foo/zed/one/test.txt"), "Test");

assertTrue(IO.delete(dir));
}

@Test
public void testIsEmptyNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ public static boolean delete(File file)
return file.delete();
}

/**
* Delete the path, recursively.
*
* @param path the path to delete
* @return true if able to delete the path, false if unable to delete the path.
*/
public static boolean delete(Path path)
{
if (path == null)
Expand All @@ -406,6 +412,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
}
catch (IOException e)
{
if (LOG.isDebugEnabled())
LOG.debug("Unable to delete path: {}", path, e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,17 @@ public void unpack(WebAppContext context) throws IOException
if (originalWarResource.lastModified().isAfter(Files.getLastModifiedTime(extractedWebAppDir).toInstant()) || extractionLock.exists())
{
extractionLock.createNewFile();
IO.delete(extractedWebAppDir);
Files.createDirectory(extractedWebAppDir);
// Best effort delete
if (IO.delete(extractedWebAppDir))
{
// Recreate the directory if it was deleted.
Files.createDirectory(extractedWebAppDir);
}
else
{
if (LOG.isInfoEnabled())
LOG.info("Unable to delete path {}, reusing existing path", extractedWebAppDir);
}
if (LOG.isDebugEnabled())
LOG.debug("Extract {} to {}", webApp, extractedWebAppDir);
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,17 @@ public void unpack(WebAppContext context) throws IOException
if (originalWarResource.lastModified().isAfter(Files.getLastModifiedTime(extractedWebAppDir).toInstant()) || extractionLock.exists())
{
extractionLock.createNewFile();
IO.delete(extractedWebAppDir);
Files.createDirectory(extractedWebAppDir);
// Best effort delete
if (IO.delete(extractedWebAppDir))
{
// Recreate the directory if it was deleted.
Files.createDirectory(extractedWebAppDir);
}
else
{
if (LOG.isInfoEnabled())
LOG.info("Unable to delete path {}, reusing existing path", extractedWebAppDir);
}
if (LOG.isDebugEnabled())
LOG.debug("Extract {} to {}", webApp, extractedWebAppDir);
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
Expand Down
Loading