You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2021/11/01 13:16:13 UTC

[archiva-components] branch master updated: Adding additional checks

This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva-components.git


The following commit(s) were added to refs/heads/master by this push:
     new c9a0171  Adding additional checks
c9a0171 is described below

commit c9a0171e60732315cfb6756af336f32e28c605f7
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Mon Nov 1 14:15:58 2021 +0100

    Adding additional checks
---
 .../components/cache/ehcache/EhcacheCache.java     | 23 ++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/components/cache/ehcache/EhcacheCache.java b/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/components/cache/ehcache/EhcacheCache.java
index ec92316..4d6e014 100644
--- a/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/components/cache/ehcache/EhcacheCache.java
+++ b/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/components/cache/ehcache/EhcacheCache.java
@@ -37,8 +37,10 @@ import org.slf4j.LoggerFactory;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 
 /**
  * EhcacheCache
@@ -231,6 +233,18 @@ public class EhcacheCache<V, T>
             {
                 configuration = new Configuration( );
             }
+            Path diskStore = Paths.get( getDiskStorePath( ) );
+            if (!Files.exists( diskStore ))
+            {
+                try
+                {
+                    Files.createDirectories( diskStore );
+                }
+                catch ( IOException e )
+                {
+                    log.error( "Could not create cache path " + e.getMessage( ) );
+                }
+            }
             this.cacheManager = new CacheManager( configuration.name( getName( ) ).diskStore(
                 new DiskStoreConfiguration( ).path( getDiskStorePath( ) ) ) );
         }
@@ -297,8 +311,13 @@ public class EhcacheCache<V, T>
             log.info( "Disposing cache: {}", ehcache );
             if ( this.ehcache != null )
             {
-                this.cacheManager.removeCache( this.ehcache.getName( ) );
-                this.ehcache = null;
+                try
+                {
+                    this.cacheManager.removeCache( this.ehcache.getName( ) );
+                    this.ehcache = null;
+                } catch (Throwable e) {
+                    log.error( "Cache removal failed: {}", e.getMessage( ), e );
+                }
             }
         }
         else