# CPack archive changing destination directory permissions

**URL:** https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919
**Category:** Usage
**Tags:** os:linux, cpack:archive
**Created:** [January 24, 2024, 12:04pm UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919 "2024-01-24T12:04:34Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![shunkica](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shunkica/32/4222_2.png) [@shunkica](https://discourse.cmake.org/u/shunkica)
#### Post date: [January 24, 2024, 12:04pm UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919/1 "2024-01-24T12:04:34Z")

</div>

I am trying to use the STGZ cpack generator to distribute my library via a shell script.  
The library installs into /usr/local/lib/  
When I run the cpack generated shell script with the /usr/local prefix, it changes the permissions of the /usr/local/lib directory to 755.  
For various reasons the /usr/local/lib directory must have 775 permissions on the system.

I have set:

> set(CMAKE\_INSTALL\_DEFAULT\_DIRECTORY\_PERMISSIONS  
> OWNER\_READ  
> OWNER\_WRITE  
> OWNER\_EXECUTE  
> GROUP\_READ  
> GROUP\_WRITE  
> GROUP\_EXECUTE  
> WORLD\_READ  
> WORLD\_EXECUTE  
> )  
> before including CPack, but that did not work.

This is the relevant code from my library:

> set(CMAKE\_INSTALL\_PREFIX “/usr/local” CACHE PATH “Install path prefix” FORCE)  
> install(TARGETS mylib LIBRARY DESTINATION lib COMPONENT mylib  
> PERMISSIONS OWNER\_READ OWNER\_WRITE OWNER\_EXECUTE GROUP\_READ GROUP\_WRITE GROUP\_EXECUTE WORLD\_READ WORLD\_EXECUTE  
> )  
> install(FILES ${PUBLIC\_HEADERS} DESTINATION include COMPONENT mylib  
> PERMISSIONS OWNER\_READ OWNER\_WRITE GROUP\_READ GROUP\_WRITE WORLD\_READ  
> )  
> cpack\_add\_component(mylib)

The same problem applies for the include files which are put in /usr/local/include.

How can I avoid changing the permissions of the install destination directories?  
The fact that the permissions are being changed on these directories is also a problem because I need anyone in a specific group to be able to install these, but now the installation doesn’t work without sudo.

---

<div class="post-metadata">

### Author: ![shunkica](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shunkica/32/4222_2.png) [@shunkica](https://discourse.cmake.org/u/shunkica)
#### Post date: [January 24, 2024, 12:17pm UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919/2 "2024-01-24T12:17:12Z")

</div>

I have solved the problem of chaning permissions for now by setting umask 002 before running cpack, but would appreciate any better way to resolve this.

I still need to run the script with sudo because:

> tar: lib: Cannot utime: Operation not permitted  
> tar: include: Cannot utime: Operation not permitted

And with pax:

> pax: Access/modification time set failed on: include: Operation not permitted  
> pax: Access/modification time set failed on: lib: Operation not permitted

---

<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: [January 26, 2024, 2:03pm UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919/3 "2024-01-26T14:03:22Z")

</div>

CMake generally just uses `libarchive` for these things; does this happen when using [`libarchive` tooling](https://github.com/libarchive/libarchive#contents-of-the-distribution) directly as well?

---

<div class="post-metadata">

### Author: ![shunkica](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shunkica/32/4222_2.png) [@shunkica](https://discourse.cmake.org/u/shunkica)
#### Post date: [January 26, 2024, 3:21pm UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919/4 "2024-01-26T15:21:11Z")

</div>

I can’t speak to that, but I think there should be a way to pass extra flags to the extractor by specifying a env var, eg CPACK\_EXTRACTOR\_PARAMS.  
That way we could pass flags to tar/pax which would prevent them from trying to set utime/mtime.

---

<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: [January 26, 2024, 5:30pm UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919/5 "2024-01-26T17:30:36Z")

</div>

There is no other tool; CMake uses `libarchive`’s library API to extraction, so any flags need interpreted and passed as arguments to these APIs. If there’s a way to get `libarchive` to do what is intended, knowing what the API difference for that would help.

Alternatively, provide either instructions or a container where the problem can be reproduced and someone else can investigate when they get a chance.

---

<div class="post-metadata">

### Author: ![shunkica](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shunkica/32/4222_2.png) [@shunkica](https://discourse.cmake.org/u/shunkica)
#### Post date: [January 27, 2024, 6:03am UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919/6 "2024-01-27T06:03:25Z")

</div>

I am talking about the shell script which is created to install (extract) the archive on the target system, not the archive itself. It has a variable which is set to pax or tar for the extraction process, but there is no way to pass additional options to it.  
Eg. tar has the --touch and --no-overwrite-dir options which could potentially solve this problem.

[https://gitlab.kitware.com/cmake/cmake/-/blame/master/Modules/Internal/CPack/CPack.STGZ\_Header.sh.in#L139](https://gitlab.kitware.com/cmake/cmake/-/blame/master/Modules/Internal/CPack/CPack.STGZ_Header.sh.in#L139)

I have added the `m` flag to tar here and rebuilt cmake, and the extraction works now.

---

<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: [February 4, 2024, 1:35pm UTC](https://discourse.cmake.org/t/cpack-archive-changing-destination-directory-permissions/9919/7 "2024-02-04T13:35:13Z")

</div>

Can you please file an issue about this?
