Diskpacked: add lazy (periodic) sync option

This syncPeriodSeconds option tells how often should
the written file Sync()ed.

If it is zero, then the old behaviour remains: Sync() after each and
every append.

If it is less then zero, then the default (1s) is used.

If it is non-zero (seconds can be set in the config), then Sync() is
called periodically.

The default for not specifying this option is 0, thus the safe
behaviour.

Add s.writer.Close() to s.Close(), and call s.writer.Close() on every
change of s.writer (new pack file).

In periodicSync call Sync only if it is really needed: the file is
dirty.

Change-Id: Ia12dee4343fa44724913fb8db4c73fce0bd0b432