Added ensureRootdirExists function