Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-2276

Install tries to remove empty directories

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 3.7.0, 3.6.6, 3.7.0-beta1
    • Affects Version/s: None
    • Component/s: Build
    • None

      Installing mongo-cxx-driver 3.6.3 (on macOS) tries to delete empty directories within the install prefix. This is unexpected, especially if the install prefix already contains other unrelated software. When mongo-cxx-driver is installed by MacPorts, at least some directory deletion attempts fail:

      -- Installing: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_mongo-cxx-driver/mongo-cxx-driver/work/destroot/opt/local/lib/pkgconfig/libmongocxx.pc
      find: -delete: rmdir(/opt/local/var/macports/home/Library/Preferences): Operation not permitted
      find: -delete: rmdir(/opt/local/var/macports/incoming/verified): Operation not permitted
      find: -delete: rmdir(/opt/local/var/lib): Operation not permitted
      find: -delete: rmdir(/opt/local/var/db/texmf/web2c/luajittex): Operation not permitted
      find: -delete: rmdir(/opt/local/var/db/texmf/web2c/pdftex): Operation not permitted
      find: -delete: rmdir(/opt/local/var/db/texmf/web2c/tex): Operation not permitted
      find: -delete: rmdir(/opt/local/var/db/texmf/web2c/luahbtex): Operation not permitted
      find: -delete: rmdir(/opt/local/var/db/texmf/web2c/luatex): Operation not permitted
      find: -delete: rmdir(/opt/local/var/db/texmf/web2c/luajithbtex): Operation not permitted
      find: -delete: rmdir(/opt/local/var/db/texmf/web2c/metafont): Operation not permitted
      find: -delete: rmdir(/opt/local/share/fonts/urw-core35-fonts): Operation not permitted
      find: -delete: rmdir(/opt/local/share/fonts/Type1/gsfonts): Operation not permitted
      find: -delete: rmdir(/opt/local/share/fonts/dejavu-fonts): Operation not permitted
      -- Installing: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_mongo-cxx-driver/mongo-cxx-driver/work/destroot/opt/local/share/mongo-cxx-driver/uninstall.sh

      Full log here: https://build.macports.org/builders/ports-11_arm64-builder/builds/17498/steps/install-port/logs/stdio

      MacPorts prevents ports from doing things they should not do, like deleting things that do not belong to them. Users installing mongo-cxx-driver outside of the protection MacPorts provides will just find these directories unexpectedly deleted.

      An empty directory is not necessarily useless. For example, one may have been created with a particular owner and permissions in order to facilitate files being written there by some process.

      This problem even caused the build to fail on one of our build machines which uses a slow hard drive and where numerous large unrelated temporary directories within the install prefix had inadvertently not been cleaned up. Traversing the entire install prefix looking for empty directories took longer than one hour, and our build machines cancel a build if no output had been produced by the build for one hour.

      The problem originates from these lines in your CMakeLists.txt:

            execute_process (
                  find ${CMAKE_INSTALL_PREFIX} -type d -empty -delete

      I suggest deleting these lines.

      If your goal was only to delete empty directories that might have been created by the mongo-cxx-driver installation process, then you could confine the deletions to the destination directory that the user (or MacPorts on the user's behalf) specified via the DESTDIR variable when invoking make, e.g. we ran:

      /usr/bin/make -w install/fast DESTDIR=/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_mongo-cxx-driver/mongo-cxx-driver/work/destroot

      and the installation prefix was /opt/local so you should only perform empty directory deletions in /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_devel_mongo-cxx-driver/mongo-cxx-driver/work/destroot/opt/local. However, that won't help if the user didn't specify a DESTDIR. Therefore the safest solution is not to attempt to delete empty directories at all.

      Or, if you know which directories you created during the build that might still be empty, delete only those by name rather than traversing the filesystem.

            roberto.sanchez@mongodb.com Roberto Sanchez
            ryandesign Ryan Schmidt
            0 Vote for this issue
            4 Start watching this issue