buildutil: Fix atomic_symlink_swap()

Check if the temporary link path exists and is a directory before
removing it, otherwise an exception will be raised.
Also fix symbolic link creation and determine the relative path
properly.
task: Fix versions handling

Search for directory named after versions, don't look for files.
Remove old versions only if the directory exists to avoid exceptions.