Sometimes permissions get messed up, it's normally easy to fix, but if the problem also breaks your access control lists (ACLs) then the fix can be much more time consuming (especially when external drives are involved).
Most of the time, for a quick fix, I use the commands below to clone the permissions and ACLs from a known good folder to my broken folder. Usually, this is all I need.
Either set the environmental variables as you need to or replace them directly (liberal use of
sudo may also be required depending on the folder being updated).
I can't take credit for the above commands, I discovered them on StackOverflow a good while ago and added them to my useful snippets - if I come across the original I will add the necessary credit.