Fix assertion failure if timeline switch happened at page boundary.

If the master and standby diverged at a page boundary, we would start the
scan for the last checkpoint record at the page boundary. XLogReadRecord
is not cool with that; it expects there to be a valid WAL record at the
start point. To fix, skip over the page header.
Refactor test suite.

This makes it easier to write separate test cases, instead of doing
everything as one test case.

The pg_rewind.sh script has been split into several parts. Initialization
happens in config_test.sh, and actually running the test in run_test.sh.
The test case -specific logic is in "basictest.sql", which defines four
functions describing the things to do in various steps in the test, and
calls config_test.sh and run_test.sh

Create the log files with predictable names. I don't think there's much
value in keeping old logs - we don't keep the regression.diffs file either,
for example.
Handle creation/removal of directory trees correctly.

If there is a directory with files or subdirectories in it in the source
that are not present in the destination, we will remove them all. But we
must be careful to remove the contents of the directory before the directory
itself, otherwise rmdir() failes with ENOTEMPTY.

Also add a test case for that.

I believe this fixes issue #34 reported by Thom Brown, where a subdir in
pg_replslot was present in source but not destination.
Plug memory leak.

pg_rewind only runs once so minor leaks don't generally matter. But this
runs once for file, so it's probably worth plugging.
Flush output after printing the filemap.

Makes the log nicer to read when stdout and stderr outputs are not mixed
up so badly.
Fix rewinding over DROP DATABSE.

The PG_VERSION file was ignored in source and destination, and hence not
deleted. Removing the directory then failed, because the PG_VERSION file
was still in it.

Also add a regression test.
Use REGRESS_OPTS instead of EXTRA_REGRESS_OPTS.

The latter doesn't seem to work on REL9_3_STABLE. I'm not sure what the
distinction is, but REGRESS_OPTS seems to work so let's use that.
Fix removal of subdirectories.

The previous commit to fix directory tree removal didn't take into account
the case of nested subdirs, ie. "dir/subdir/file", where the whole tree
is removed.

Pointed out by Samrat Revagade.