newdb: Shorten filenames correctly

Ensure that the total path length is <= PATH_LIMIT * 4 and that no
component is longer than PATH_LIMIT on unix.