Bug fix and minor improvements.

A bug was found in craft.actions.sync. When trying to create some
necessary directories using mkdir(), the first call to mkdir() could
fail, raising OSError. The second mkdir() call would therefore not be
executed, effectively making the first chdir() call also raise an
exception. This is now fixed as both mkdir() calls are handled
separately.

Some other minor improvements have also been added, but they are not
greatly relevant. Please check this commit's diff for more details.