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

**URL:** https://discourse.cmake.org/t/copy-dll-to-target-path-randomly-got-file-copy-cannot-set-permissions-on-but-break-my-build-pipeline/9539
**Category:** Usage
**Tags:** os:windows
**Created:** [December 1, 2023, 1:23pm UTC](https://discourse.cmake.org/t/copy-dll-to-target-path-randomly-got-file-copy-cannot-set-permissions-on-but-break-my-build-pipeline/9539 "2023-12-01T13:23:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Huanle](https://discourse.cmake.org/user_avatar/discourse.cmake.org/huanle/32/4048_2.png) [@Huanle](https://discourse.cmake.org/u/Huanle)
#### Post date: [December 1, 2023, 1:23pm UTC](https://discourse.cmake.org/t/copy-dll-to-target-path-randomly-got-file-copy-cannot-set-permissions-on-but-break-my-build-pipeline/9539/1 "2023-12-01T13:23:24Z")

</div>

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:

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

```

The error:

```txt
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)

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 1, 2023, 3:49pm UTC](https://discourse.cmake.org/t/copy-dll-to-target-path-randomly-got-file-copy-cannot-set-permissions-on-but-break-my-build-pipeline/9539/2 "2023-12-01T15:49:09Z")

</div>

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

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![Huanle](https://discourse.cmake.org/user_avatar/discourse.cmake.org/huanle/32/4048_2.png) [@Huanle](https://discourse.cmake.org/u/Huanle)
#### Post date: [December 2, 2023, 2:30am UTC](https://discourse.cmake.org/t/copy-dll-to-target-path-randomly-got-file-copy-cannot-set-permissions-on-but-break-my-build-pipeline/9539/3 "2023-12-02T02:30:46Z")

</div>

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

```txt
  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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 2, 2023, 3:17am UTC](https://discourse.cmake.org/t/copy-dll-to-target-path-randomly-got-file-copy-cannot-set-permissions-on-but-break-my-build-pipeline/9539/4 "2023-12-02T03:17:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 2, 2023, 3:51am UTC](https://discourse.cmake.org/t/copy-dll-to-target-path-randomly-got-file-copy-cannot-set-permissions-on-but-break-my-build-pipeline/9539/5 "2023-12-02T03:51:49Z")

</div>

I found other instances of the same pattern as well: [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/9023](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9023)
