Fix race conditions while creating symlinks.
Fix race conditions while creating symlinks.

We were having race condition issues while creating symlinks. If the
link we're trying to create already exists as a folder (for example the
sites/default/files folder of Drupal) we first copy all contents of that
folder to the folder the link will point to, and then we remove it so
that we can create the link. We do this because a folder might contain
(for example) an `.htaccess` file that we want to preserve. We have to
delete the folder before creating the symlink or we get an error while
creating the symlink ("cannot overwrite directory").

Now, for the race condition: We experienced this while deploying a
pretty high traffic Drupal website. In the presymlink task we loop over
all symlinks, mirror the directory to where the symlink will point and
then remove the directory. Once we've done all this for all symlinks, we
create the symlinks themselves. For this particular site, by the time we
got to actually create the symlink for sites/default/files, Drupal had
already created new aggregated js files, thus recreating the
sites/default/files folder (resulting in the "cannot overwrite
directory" error).

As for the fix in this commit: We keep the old behavior (looping over
all symlinks and copying and removing the folders first, then creating
all symlinks). This package is open source after all, and we want to
ensure backward compatibility. But, we added extra behavior: Before
creating each individual symlink, we check again if the folder needs to
be copied (if it exists and thus has been recreated), and we remove it
again. This way the `rm` command and the `ln` command follow each other
immediately and _should_ result in no more race conditions.

digipolisgent/robo-digipolis-helpers