<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>15340</bug_id>
          
          <creation_ts>2024-01-10 09:15:46 +0000</creation_ts>
          <short_desc>&apos;opkg remove&apos; is deleting /lib directory when removing service file</short_desc>
          <delta_ts>2026-09-29 21:33:57 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>opkg</product>
          <component>opkg</component>
          <version>0.6.2</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Undecided</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Allan Jones">allan</reporter>
          <assigned_to name="Alex Stewart">alex.stewart</assigned_to>
          
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>97767</commentid>
    <comment_count>0</comment_count>
    <who name="Allan Jones">allan</who>
    <bug_when>2024-01-10 09:15:46 +0000</bug_when>
    <thetext>I&apos;m building a package using CMake and adding a service file into /lib/systemd/system.  Installation works fine but when I remove the package it deletes the /lib directory.
Here&apos;s a minimum CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(simplePack)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS -pthread)
add_executable(${PROJECT_NAME} &quot;main.cpp&quot;)
install(TARGETS ${PROJECT_NAME} DESTINATION /etc/simple)
set(CPACK_DEBIAN_PACKAGE_DEPENDS &quot;&quot;)
set(CPACK_PACKAGE_NAME &quot;TEST-MODEL&quot;)
set(CPACK_PACKAGE_VENDOR InventDesignBuild)
set(CPACK_PACKAGE_VERSION_MAJOR &quot;1&quot;)
set(CPACK_PACKAGE_VERSION_MINOR &quot;2&quot;)
set(CPACK_PACKAGE_VERSION_PATCH &quot;15&quot;)
set(CPACK_PACKAGE_CONTACT info@...)
set(CPACK_GENERATOR &quot;DEB&quot;)
set(CPACK_SET_DESTDIR true)
set(CPACK_INSTALL_PREFIX &quot;/&quot;)
install(FILES ${CMAKE_SOURCE_DIR}/hyperion-bridge.service DESTINATION lib/systemd/system)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE &quot;aarch64&quot;)
include(CPack)

This is a minimum build to reproduce the problem. The hyperion-bridge.service file is included at the end (I don&apos;t think its contents are relevant). 

The executable is a simple &apos;hello, world&apos; - code at the end.

The package is installed correctly using;
# opkg -V4 install ./TEST-MODEL-1.2.15-Linux.deb


Here&apos;s the output for removing the package;

# opkg -V4 remove test-model                     
pkg_hash_load_status_files:
pkg_vec_insert_merge: Adding new pkg=test-model version=1.2.15 arch=aarch64.
pkg_info_preinstall_check: Updating file owner list.
Removing test-model (1.2.15) from root...
pkg_run_script: Running script //var/lib/opkg/info/test-model.prerm.
remove_data_files_and_list: Deleting /etc/simple/simplePack.
remove_data_files_and_list: Deleting /lib/systemd/system/hyperion-bridge.service.
remove_data_files_and_list: Deleting /etc/simple.
remove_data_files_and_list: Deleting /lib.
pkg_run_script: Running script //var/lib/opkg/info/test-model.postrm.
remove_maintainer_scripts: Deleting //var/lib/opkg/info/test-model.control.
remove_maintainer_scripts: Deleting //var/lib/opkg/info/test-model.md5sums.
write_status_files_if_changed: Writing status file.
pkg_write_changed_filelists: Saving changed filelists.
hash_table: pkg-hash, 24576 bytes
    n_buckets=1024, n_elements=1, n_collisions=0
    max_bucket_len=0, n_used_buckets=1, ave_bucket_len=1.00
    n_hits=1, n_misses=1
hash_table: file-hash, 24576 bytes
    n_buckets=1024, n_elements=7, n_collisions=0
    max_bucket_len=0, n_used_buckets=7, ave_bucket_len=1.00
    n_hits=10, n_misses=7
hash_table: dir-hash, 24576 bytes
    n_buckets=1024, n_elements=5, n_collisions=0
    max_bucket_len=0, n_used_buckets=5, ave_bucket_len=1.00
    n_hits=10, n_misses=5
hash_table: obs-file-hash, 1536 bytes
    n_buckets=64, n_elements=0, n_collisions=0
    max_bucket_len=0, n_used_buckets=0, ave_bucket_len=0.00
    n_hits=0, n_misses=0

For some reason opkg seems to be removing the /lib directory hence the Linux system becomes unusable. 

Initially I was using opkg 4.2 built as part of my &apos;buildroot&apos; build. I also see exactly the same effect having built and tested version 6.3.

Interestingly the /etc/ directory is not deleted when removing the package.

// hyperion-bridge.service file //
[Unit]
Description=Hyperion MQTT bridge
Wants=network.target
Wants=mosquitto.service

[Service]
Type=simple
WorkingDirectory=/etc/hyperion
ExecStart=/etc/hyperion/hypBridge -c config/bridgeConfig.yaml
Restart=always
RestartSec=5s
WatchdogSec=120s

[Install]
WantedBy=multi-user.target

// Source for the executable //
#include &lt;iostream&gt;

int main()
{
	std::cout &lt;&lt; &quot;Hello World!&quot; &lt;&lt; std::endl;
	return 0;
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98192</commentid>
    <comment_count>1</comment_count>
    <who name="Alex Stewart">alex.stewart</who>
    <bug_when>2024-02-12 23:30:36 +0000</bug_when>
    <thetext>Hey Allan. Sorry for the delayed reply.

Clarification question. Are you instrumenting opkg via buildroot such that all the files in the rootfs are being installed with opkg? And therefore opkg has a complete manifest picture of what is installed to the system when you perform the `remove` operation? Or is it rather that something else is building the rootfs, and then you are installing-and-removing the service file package with opkg. (I&apos;m not super familiar with buildroot.)

If it&apos;s the latter, then I can easily imagine how opkg believes that nothing else on the system is using /lib and it is safe to remove.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106962</commentid>
    <comment_count>2</comment_count>
    <who name="Alex Stewart">alex.stewart</who>
    <bug_when>2026-09-29 21:33:57 +0000</bug_when>
    <thetext>Need someone to revisit this bug and determine if this is intended behavior, before we can triage it.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>