Improve long-filename handling during syncing

This will hopefully fix some remaining issues with long filenames during
syncing, particularly on Linux with encrypted filenames (which have a
filename length of 143).

(This may have reintroduced some edge case bugs, so it needs some
testing.)