Support long paths v3

This fixes the bug discussed in (closed) PR #122

To be more specific, the first short commit does fix it, the second one is a cleanup.

I would like to squash both of these with the original long paths patch, so that it could be submitted upstream as one patch.  (That it why I cheekily named the branch kb-long-paths-v3 .)
@kblees, would you agree?