ldbGenericReplace: correctly handle files with same version but different flags.

This fixes syncthing bug #819.
Merge pull request #820 from seehuhn/fixes

ldbGenericReplace: correctly handle files with same version but different flags
Reinstate ignore permissions
Refactor out functions in main
Emit info level log when deleting directory fails