Copy test fails when destination directory contains other files not accessible to the user executing Gradle

Hi,
I have a scenario where my Gradle build script copies (using the copy task) a file to a directory that contains other files that are not accessible to my user. For instance it might contain the following file:

drwxr-x— 4 root root 4096 Apr 7 22:11 mywebappInitial

My user doesn’t have access to to the mywebappInitial directory.

I’m new to Gradle, but this is my synopsis of the problem: when the Copy task runs, Gradle seems to attempt to traverse all directories and hash the contents. If it can’t access an item in the destination directory it throws an error.

It throws a different error depending on whether it can’t access a file or directory.

File error:

  • What went wrong:
    Failed to capture snapshot of output files for task ‘:deployToWebserver’ property ‘destinationDir’ during up-to-date check.
    > Failed to create MD5 hash for file ‘/home/donovanh/fake/a’ as it does not exist.

Directory Error:

  • What went wrong:
    Failed to capture snapshot of output files for task ‘:deployToWebserver’ property ‘destinationDir’ during up-to-date check.
    > Could not read path ‘/home/donovanh/fake/a’.

What is the most appropriate way to work around this issue?
I’ve tried this on 4.8.1 and 5.3.1.