Apache Lucene open-source search software
Clean up junk from gradle's user home (~/.gradle/.tmp). #14385 (#14387)
Dawid Weissc4f118318f47
diff --git a/gradle/hacks/wipe-temp.gradle b/gradle/hacks/wipe-temp.gradleindex 2b7e56ad947..6d9a201042d 100644--- a/gradle/hacks/wipe-temp.gradle+++ b/gradle/hacks/wipe-temp.gradle@@ -14,15 +14,35 @@* See the License for the specific language governing permissions and* limitations under the License.*/+import java.nio.file.Files+import java.time.temporal.ChronoUnit+import java.time.Instant+// See LUCENE-9471. We redirect temporary location for gradle// so that it doesn't pollute user's tmp. Wipe it during a clean though.configure(rootProject) {gradle.buildFinished {+ // we clean up the java.io.tmpdir we've redirected gradle to use (LUCENE-9471).+ // these are still used and populated with junk.rootProject.delete fileTree(".gradle/tmp").matching {include "gradle-worker-classpath*"}++ // clean up any files older than 3 hours from the user's gradle temp. the time+ // limit is added so that we don't interfere with any concurrent builds... just in case.+ def gradleTmp = rootProject.gradle.gradleUserHomeDir.toPath().resolve(".tmp")+ if (Files.exists(gradleTmp)) {+ Instant deadline = Instant.now().minus(3, ChronoUnit.HOURS);+ try (var stream = Files.list(gradleTmp)) {+ stream.forEach(path -> {+ if (Files.getLastModifiedTime(path).toInstant().isBefore(deadline)) {+ Files.deleteIfExists(path);+ }+ });+ }+ }}}