Remove unnecessary MAX macro uses.
Rewrite path_ensure_directories logic to call mkdir before stat, and ignore EEXIST errno.
Sync toolkit.