[Fixes #61954656] calculate the first non-restricted dir correctly