Skip to content

Commit

Permalink
Merge branch 'tribits_github_snapshot' into atdv-241-skip-nonowning-i…
Browse files Browse the repository at this point in the history
…nstall-base-dir (ATDV-241)

Avoids trying to change the group or permissions on a base install dir you
don't own.  (See TriBITSPub/TriBITS#314)
  • Loading branch information
bartlettroscoe committed May 1, 2020
2 parents ace4ed2 + 244b331 commit a12599f
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ SET(projectSubdirPathsArray "@PROJECT_SUBDIR_PATHS_ARRAY@")
SET(PROJECT_MAKE_INSTALL_GROUP "@PROJECT_MAKE_INSTALL_GROUP@")
SET(PROJECT_MAKE_INSTALL_PERMS_CHANGE "@PROJECT_MAKE_INSTALL_PERMS_CHANGE@")

#
# Helper functions
#

SET(CHMOD_CHGRP_IDX 0)

Expand All @@ -26,25 +28,43 @@ ENDFUNCTION()

FUNCTION(SET_DIR_OWNER_AND_PERMS dirPath recurseFlag)

IF (NOT "${PROJECT_MAKE_INSTALL_GROUP}" STREQUAL "")
ECHO_AND_RUN_CMND(
chgrp ${PROJECT_MAKE_INSTALL_GROUP} ${recurseFlag} "${dirPath}")
ENDIF()
EXECUTE_PROCESS(COMMAND stat -c %U "${dirPath}"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE dirOwner)

IF (NOT "${dirOwner}" STREQUAL "${CURRENT_USER_RUNNING_INSTALL}")

MESSAGE(STATUS "${CHMOD_CHGRP_IDX}: NOTE: Not calling chgrp and chmod on ${dirPath} since owner '${dirOwner}' != current owner '${CURRENT_USER_RUNNING_INSTALL}'!")

ELSE()

IF (NOT "${PROJECT_MAKE_INSTALL_GROUP}" STREQUAL "")
ECHO_AND_RUN_CMND(
chgrp ${PROJECT_MAKE_INSTALL_GROUP} ${recurseFlag} "${dirPath}")
ENDIF()

IF (NOT "${PROJECT_MAKE_INSTALL_PERMS_CHANGE}" STREQUAL "")
ECHO_AND_RUN_CMND(
chmod ${PROJECT_MAKE_INSTALL_PERMS_CHANGE} ${recurseFlag} "${dirPath}")
ENDIF()

IF (NOT "${PROJECT_MAKE_INSTALL_PERMS_CHANGE}" STREQUAL "")
ECHO_AND_RUN_CMND(
chmod ${PROJECT_MAKE_INSTALL_PERMS_CHANGE} ${recurseFlag} "${dirPath}")
ENDIF()

MATH(EXPR CHMOD_CHGRP_IDX "${CHMOD_CHGRP_IDX}+1")
SET(CHMOD_CHGRP_IDX ${CHMOD_CHGRP_IDX} PARENT_SCOPE)

ENDFUNCTION()

#
# Executable script
#

IF (EXISTS "${projectInstallBaseDir}")

EXECUTE_PROCESS(COMMAND whoami
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE CURRENT_USER_RUNNING_INSTALL)

LIST(LENGTH projectSubdirPathsArray numSubDirs)

# Get projectSubdirPathsArrayLessOne and CMAKE_INSTALL_PREFIX
Expand Down

0 comments on commit a12599f

Please sign in to comment.