copy dll to target path, randomly got "file COPY cannot set permissions on", but break my build pipeline

It seems not an error like the stacktrace says “No error.​” But the build pipeline will stop.
Wonder anyone got the same issue, please help.
Want to know how to prevent the “cannot set permissions” or ways to ignore the error.

The code:

file(COPY ${RESOLVED_DEPS} DESTINATION ${target_path} FOLLOW_SYMLINK_CHAIN NO_SOURCE_PERMISSIONS)

The error:

CMake Error at D:/projects/flv_extractor/copy_dlls.cmake:38 (file):​
  file COPY cannot set permissions on​
  "D:/projects/flv_extractor/build/Release_x64/output-2022/flvpruge.dll":​
  No error.​
Call Stack (most recent call first):​
  D:/projects/flv_extractor/copy_dlls.cmake:42 (copy_runtime_deps)

Looking at the code, it appears as if _wchmod somehow returned an error without setting errno?

Cc: @brad.king

After two times successly run pipeline, this time got an error “Permission denied.”

  file COPY cannot set permissions on
  "D:/projects/flv_extractor/build/Release_x64/output-6144/FlvGeom.dll":
  Permission denied.

Suspecting the impact of security software but finding it difficult to pinpoint, as it cannot be consistently reproduced. Having an option to ignore permission modification failures and receive a warning in the log would be a good solution.

Ah, no, that is not what is going wrong. The return status is checked and then thrown away. Some stream operations are performed and then the error message is requested. This may involve resetting an error state if something happens. I’ll have an MR up shortly.

I found other instances of the same pattern as well: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9023