Skip to content

Commit

Permalink
fix a bug in the cache store where swap dirs did not get deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Nov 17, 2015
1 parent bbd4491 commit 60aeced
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 60aeced

Please sign in to comment.