File manage fails if it needs to create directories and no mode argument was supplied

I was just having a problem that file.manage was failing with:
Unable to manage file: invalid literal for int() with base 10: 'o'
It seems it was trying to interpret the string None as a mode. My patch uses the default directory mode if it neither mode or dir_mode is specified.

I also include the debugging I added as a separate commit.