Fix race condition in CreateLocalFileTask

It's possible that between the isdir() check and
the makedirs() check that another thread has come along
and created the directory.

We also need to make sure that any uncaught exception will
cause the download to be cancelled.