Fix cabal-install build error

Distribution/Client/Sandbox.hs:695:9: parse error on input `}'
Merge pull request #1365 from jhenahan/master

Fix cabal-install build error
Refactoring.

Introduce two helper functions to break a giant case statement.
Formatting.
Refactoring.

Split 'onBuildConfig' into two (local) functions.
Rename a function.
Detect when a sandbox was created for an already configured package.

In this case we need to reconfigure immediately, skipping reinstallation of
add-source deps.

Fixes #1349.
'checkSandboxConfigNewer': Check that the sandbox config exists.
Saves and restores current directory for detailed tests
Merge pull request #1370 from NovaDenizen/fixtest

Saves and restores current directory for detailed tests