Thursday, December 5, 2013

guava Files - unable to delete temporaly directory

I had strange problem on my Mac. Following code:
File indexBaseFile = com.google.common.io.Files.createTempDir();

... some creating of files inside directory

Files.deleteRecursively(indexBaseFile);
always ends with following exception:
java.io.IOException: Failed to delete /var/folders/c5/j25r9j1j1jx_t4wzrzmf53300000gn/T/1386264920188-0
 at com.google.common.io.Files.deleteRecursively(Files.java:537)
The trick is that guava library before deleting file check that deleted file is not a symbolic link. On Mac /var is pointing to /private/var. So now to fix this problem was easy:
File indexBaseFile = com.google.common.io.Files.createTempDir().getAbsolutePath();

... some creating of files inside directory

Files.deleteRecursively(indexBaseFile);
There is extra .getAbsolutePath() calling. This method return absolute path with resolved symbolic links.

No comments:

Post a Comment