Revert "remove dirname compat"

This reverts commit f1a3cc7bd3c93b963bf079a4be87c7c900e24ed2.