Backport ensure permissions are preserved copy package

This is a backport of #336.