Improve DEBUG during WebInfConfiguration.unpack

This commit is contained in:
Joakim Erdfelt 2024-02-27 10:15:24 -06:00
parent 2803f5a872
commit 54aaa3a398
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
4 changed files with 46 additions and 4 deletions

View File

@ -472,6 +472,22 @@ public class IOTest
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()
{

View File

@ -380,6 +380,12 @@ public class IO
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)
@ -406,6 +412,8 @@ public class IO
}
catch (IOException e)
{
if (LOG.isDebugEnabled())
LOG.debug("Unable to delete path: {}", path, e);
return false;
}
}

View File

@ -291,8 +291,17 @@ public class WebInfConfiguration extends AbstractConfiguration
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())

View File

@ -293,8 +293,17 @@ public class WebInfConfiguration extends AbstractConfiguration
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())