Andras Bokor Thank you for taking care of all the issues. The new patch looks quite good. However I am wondering if there is a small race condition in the cleanup path.
There are two functions where we have this same pattern. we do localfs.rename(dir2, copyPath); and after rename execute a bunch of statements. I am presuming that any of these statements can fail, but little later at the end of the try block we do dir2=copyPath; based on this assignment we invoke cleanup without checking if the file exists.
if we get a failure in the bunch of lines between rename and assignment, I am worried that cleanup will fail, that is dir2 will not be null, yet the file will not exist. In the earlier code we checked if the file exists before calling cleanup which avoided this problem. You can fix it by making sure that there are no statements that can fail between rename and dir2=copyPath assignment or by bringing back the check for file before invoking cleanup.
As I said at the start, the next function has a very similar code pattern.