Fix chown of target directory when adding file.

Fixes #5235

Adds an integration test for this case.

Docker-DCO-1.1-Signed-off-by: Paul Nasrat <pnasrat@gmail.com> (github:pnasrat)