# CPack DEB generator is following symlinks of directories

**URL:** <https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045>\
**Category:** Code\
**Created:** [April 16, 2020, 8:44pm UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045 "2020-04-16T20:44:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DKLind](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dklind/32/526_2.png) [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Post date:** [April 16, 2020, 8:44pm UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/1 "2020-04-16T20:44:10Z")

</div>

The following link indicates this issue was fixed: [https://gitlab.kitware.com/cmake/cmake/issues/19448](https://gitlab.kitware.com/cmake/cmake/issues/19448)

But, for me it still remains with CMake v3.15.7.

The following code illustrates the issue:

```
install(CODE "
    EXECUTE_PROCESS(
        COMMAND ${CMAKE_COMMAND} -E create_symlink
            /lib/x86_64-linux-gnu
            lib64
        WORKING_DIRECTORY \$ENV{DESTDIR}
    )
    EXECUTE_PROCESS(
        COMMAND ${CMAKE_COMMAND} -E create_symlink
            /usr/lib/x86_64-linux-gnu
            lib64
        WORKING_DIRECTORY \$ENV{DESTDIR}/usr
    )"
    COMPONENT ${PROJECT_NAME}
)

```

This installs two symlinks. I can see the symlinks are correct in the temporary \_CPack\_Packages directory structure when CPack is executed. However, looking at the contents of data.tar.gz with Archive Manger I see the following:  
[Screenshot from 2020-04-16 12-38-20|594x247](https://discourse.cmake.org/uploads/short-url/vHy99abUsljbDHQBzc55dc9gKAC.png)

---

<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:** [April 17, 2020, 11:29am UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/2 "2020-04-17T11:29:50Z")

</div>

Hmm. Something may have changed in libarchive. @brad.king @kyle.edwards

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [April 17, 2020, 11:59am UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/3 "2020-04-17T11:59:57Z")

</div>

I cannot reproduce this with CMake 3.15.7:

```auto
$ cat ../CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(Issue12284 NONE)
include(CPack)

install(CODE [[
  execute_process(
    COMMAND ${CMAKE_COMMAND} -E create_symlink /lib/x86_64-linux-gnu lib64
    WORKING_DIRECTORY $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}
  )
  file(MAKE_DIRECTORY "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/usr")
  execute_process(
    COMMAND ${CMAKE_COMMAND} -E create_symlink /usr/lib/x86_64-linux-gnu lib64
    WORKING_DIRECTORY $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/usr
  )
]])
$ cmake ..
$ make
$ cpack -G TGZ
$ tar tzf Issue12284-0.1.1-Linux.tar.gz
Issue12284-0.1.1-Linux/lib64
Issue12284-0.1.1-Linux/usr/
Issue12284-0.1.1-Linux/usr/lib64

```

---

<div class="post-metadata">

**Author:** ![DKLind](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dklind/32/526_2.png) [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Post date:** [April 17, 2020, 4:59pm UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/4 "2020-04-17T16:59:10Z")

</div>

Here’s how to duplicate it:

```
cmake_minimum_required(VERSION 3.15)
project(Issue12284 NONE)

install(CODE [[
  execute_process(
    COMMAND ${CMAKE_COMMAND} -E create_symlink /lib/x86_64-linux-gnu lib64
    WORKING_DIRECTORY $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}
  )
  file(MAKE_DIRECTORY "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/usr")
  execute_process(
    COMMAND ${CMAKE_COMMAND} -E create_symlink /usr/lib/x86_64-linux-gnu lib64
    WORKING_DIRECTORY $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/usr
  )
]])

set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Test Package")
set(CPACK_DEBIAN_FILE_NAME ${PROGRAM_NAME})
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE x86-64)

set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH 0)
set(CPACK_PACKAGE_VERSION 1.0.0)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "package-maintainer <package-maintainer@xyz.com>")
set(CPACK_PACKAGE_VENDOR xyz)

include(CPack)

```

```auto
$ cmake ..
$ cpack

```

---

<div class="post-metadata">

**Author:** ![Dakon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dakon/32/854_2.png) [@Dakon](https://discourse.cmake.org/u/Dakon)\
**Post date:** [April 18, 2020, 2:10pm UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/5 "2020-04-18T14:10:36Z")

</div>

This somehow reminds me of [https://gitlab.kitware.com/cmake/cmake/-/issues/19419](https://gitlab.kitware.com/cmake/cmake/-/issues/19419)

Eike

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [April 20, 2020, 11:51am UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/6 "2020-04-20T11:51:31Z")

</div>

@DKLind thanks. Please see the fix in [CMake MR 4637](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4637).

---

<div class="post-metadata">

**Author:** ![DKLind](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dklind/32/526_2.png) [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Post date:** [April 20, 2020, 4:26pm UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/7 "2020-04-20T16:26:55Z")

</div>

@brad.king Yes, that fixes the problem, thank You!

Is this fix going to rolled into the 3.15.x code branch or only 3.17.x?

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [April 21, 2020, 11:47am UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/8 "2020-04-21T11:47:31Z")

</div>

I had scheduled it for 3.18 since this is a long-standing bug and not a regression. I’ve updated the merge request to backport the fix to the 3.17 series, but we probably won’t port it back further.

---

<div class="post-metadata">

**Author:** ![DKLind](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dklind/32/526_2.png) [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Post date:** [April 21, 2020, 5:19pm UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045/9 "2020-04-21T17:19:26Z")

</div>

I’ll watch for a 3.17.2 release. Meanwhile, I’ll just patch the source.

Thanks
