Proper cross-platform path handling.

Don't write DB if it hasn't changed. Don't save directories in DB.
Only write db if changed in line mode as well