zonkyio / embedded-postgres

Java embedded PostgreSQL component for testing
Apache License 2.0
344 stars 43 forks source link

Old working directories are not removed #76

Open TovarischZhukov opened 2 years ago

TovarischZhukov commented 2 years ago
  1. When a working directory is created, it is created outside the parent directory.

if (builderDataDirectory == null) { builderDataDirectory = Files.createTempDirectory("epg").toFile(); }

But at the moment when a search is performed for obsolete ones, their path is calculated relative to the parent.

private void cleanOldDataDirectories(File parentDirectory) { final File[] children = parentDirectory.listFiles();

  1. If we still find such a directory, we try to take the lock, but without releasing it, we delete the folder, an exception occurs

    try (FileOutputStream fos = new FileOutputStream(lockFile); FileLock lock = fos.getChannel().tryLock()) { if (lock != null) { //..... FileUtils.deleteDirectory(dir); } }

  2. Sometimes, when the test ends abnormally, the "epg-lock" file is not created, so these folders are also not cleared during subsequent runs.

final File lockFile = new File(dir, LOCK_FILE_NAME); final boolean isTooNew = System.currentTimeMillis() - lockFile.lastModified() < 10 * 60 * 1000; if (!lockFile.exists() || isTooNew) { continue; }

rasharab commented 1 year ago

Just noticed this today as well. I can attempt to fix this if you'd like?

tomix26 commented 1 year ago

If you have an idea how to fix it, help is always welcome.