Two ways to fail with symlinks and the above code... and don't know the solution.
Way #1
Run this to create a test:
echo test > testfile
mkdir dirtodelete
ln -s badlink dirtodelete/badlinktodelete
Here you see your test file and test directory:
$ ls testfile dirtodelete
testfile
dirtodelete:
linktodelete
Then run your commons-io deleteDirectory(). It crashes saying the file is not found. Not sure what the other examples do here. The Linux rm command would simply delete the link, and rm -r on the directory would also.
Exception in thread "main" java.io.FileNotFoundException: File does not exist: /tmp/dirtodelete/linktodelete
Way #2
Run this to create a test:
mkdir testdir
echo test > testdir/testfile
mkdir dirtodelete
ln -s ../testdir dirtodelete/dirlinktodelete
Here you see your test file and test directory:
$ ls dirtodelete testdir
dirtodelete:
dirlinktodelete
testdir:
testfile
Then run your commons-io deleteDirectory() or the example code people posted. It deletes not only the directory, but your testfile which is outside the directory being deleted. (It dereferences the directory implicitly, and deletes the contents). rm -r would delete the link only. You need to use something like this delete the dereferenced files: "find -L dirtodelete -type f -exec rm {} \;".
$ ls dirtodelete testdir
ls: cannot access dirtodelete: No such file or directory
testdir: