From 60aecedca1781f9aa7be31ae32c006e15f191b3a Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Tue, 17 Nov 2015 14:53:45 +0100 Subject: [PATCH] fix a bug in the cache store where swap dirs did not get deleted --- .../repo/channel/apm/store/CacheStore.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.packagedrone.repo.channel.apm/src/org/eclipse/packagedrone/repo/channel/apm/store/CacheStore.java b/bundles/org.eclipse.packagedrone.repo.channel.apm/src/org/eclipse/packagedrone/repo/channel/apm/store/CacheStore.java index 9e5db3aa..568bc53b 100644 --- a/bundles/org.eclipse.packagedrone.repo.channel.apm/src/org/eclipse/packagedrone/repo/channel/apm/store/CacheStore.java +++ b/bundles/org.eclipse.packagedrone.repo.channel.apm/src/org/eclipse/packagedrone/repo/channel/apm/store/CacheStore.java @@ -103,14 +103,19 @@ public void commit () return; } - Path tmp2 = null; - try { + // first delete the swap dir + if ( Files.exists ( CacheStore.this.swapPath ) ) + { + Files.walkFileTree ( CacheStore.this.swapPath, new RecursiveDeleteVisitor () ); + } + + // move away old data path if ( Files.exists ( CacheStore.this.dataPath ) ) { - tmp2 = Files.createTempDirectory ( this.tmp, "swap" ); - Files.move ( CacheStore.this.dataPath, tmp2, StandardCopyOption.ATOMIC_MOVE ); + Files.createDirectories ( CacheStore.this.swapPath.getParent () ); + Files.move ( CacheStore.this.dataPath, CacheStore.this.swapPath, StandardCopyOption.ATOMIC_MOVE ); } Files.move ( this.tmp, CacheStore.this.dataPath, StandardCopyOption.ATOMIC_MOVE ); @@ -120,11 +125,11 @@ public void commit () throw new RuntimeException ( e ); } - if ( tmp2 != null ) + if ( Files.exists ( CacheStore.this.swapPath ) ) { try { - Files.walkFileTree ( this.tmp, new RecursiveDeleteVisitor () ); + Files.walkFileTree ( CacheStore.this.swapPath, new RecursiveDeleteVisitor () ); } catch ( final IOException e ) { @@ -177,10 +182,13 @@ public interface Transaction private final Path tmpPath; + private final Path swapPath; + public CacheStore ( final Path path ) throws IOException { this.dataPath = path.resolve ( "data" ); this.tmpPath = path.resolve ( "tmp" ); + this.swapPath = path.resolve ( "swap" ); Files.createDirectories ( this.dataPath ); Files.createDirectories ( this.tmpPath );