You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/06/04 09:13:21 UTC
[sling-org-apache-sling-feature] branch
bugfix/cleanup-cache-directory created (now f95ddb7)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a change to branch bugfix/cleanup-cache-directory
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git.
at f95ddb7 SLING-10451 cleanup cache directory
This branch includes the following new commits:
new f95ddb7 SLING-10451 cleanup cache directory
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-feature] 01/01: SLING-10451 cleanup cache
directory
Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch bugfix/cleanup-cache-directory
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git
commit f95ddb7fae6bd6f429bb5b14b880007a486e8abe
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Fri Jun 4 11:13:07 2021 +0200
SLING-10451 cleanup cache directory
also create it only lazily
---
.../sling/feature/io/artifacts/ArtifactManager.java | 12 ++++++++++++
.../feature/io/artifacts/ArtifactManagerConfig.java | 18 +++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java b/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java
index 021be9a..ed6cafb 100644
--- a/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java
+++ b/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java
@@ -361,9 +361,21 @@ public class ArtifactManager
@Override
public void shutdown() {
this.config = null;
+ deleteDir(cacheDir);
this.cacheDir = null;
}
+ /** recursively delete directory */
+ private static void deleteDir(File dir) {
+ File[] files = dir.listFiles();
+ if(files != null) {
+ for (final File file : files) {
+ deleteDir(file);
+ }
+ }
+ dir.delete();
+ }
+
@Override
public URL getArtifact(final String url, final String relativeCachePath) {
logger.debug("Checking url to be local file {}", url);
diff --git a/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManagerConfig.java b/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManagerConfig.java
index 876d895..eb1b969 100644
--- a/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManagerConfig.java
+++ b/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManagerConfig.java
@@ -62,11 +62,6 @@ public class ArtifactManagerConfig implements ArtifactProviderContext {
"https://repo.maven.apache.org/maven2",
"https://repository.apache.org/content/groups/snapshots"
};
- try {
- this.cacheDirectory = Files.createTempDirectory("slingfeature").toFile();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
this.repoHome = System.getProperty("user.home") + "/.m2/repository/";
}
@@ -103,9 +98,22 @@ public class ArtifactManagerConfig implements ArtifactProviderContext {
*/
@Override
public File getCacheDirectory() {
+ if (cacheDirectory == null) {
+ initCacheDirectory();
+ }
return cacheDirectory;
}
+ private synchronized void initCacheDirectory() {
+ if (cacheDirectory == null) {
+ try {
+ this.cacheDirectory = Files.createTempDirectory("slingfeature").toFile();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
/**
* Set the cache directory
* @param dir The cache directory