Revert "Revert "use set_perm instead of set_metadata""

This reverts commit 2fb8342e3d5e70c90aa421c37c2fb8381f85a40a.