# shellcheck shell=bash # Version ID Block (comment-only -- NOT executable). Relies on +k filetype # modifier. This is a sourced library; a real 'declare' here would clobber # the sourcing script's own $Version (confirmed: they share global scope). # show_versions() greps this line's text directly; it is never evaluated. # VersionID='$Id: //p4-sdp/r26.1.0/Server/Unix/p4/common/lib/logging.lib#1 $ $Change: 33565 $' #============================================================================== # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://workshop.perforce.com/view/p4-sdp/main/LICENSE #------------------------------------------------------------------------------ #============================================================================== # This library contains functions related to handling log files. #------------------------------------------------------------------------------ # Function: get_old_log_timestamp ($log) # # Get the last modified timestamp of the old log in a cross-platform manner. # If we don't get a correct value using 'stat' (which varies across the # UNIX/Linux/MacOSX spectrum), use the current time as a fallback. In that # case, the timestamp will reflect the time the log was moved rather than when # it was last modified, but that's still reasonable. The file timestamp will # still have the correct last-modified time. #------------------------------------------------------------------------------ function get_old_log_timestamp () { local log=${1:-} local oldLogTimestamp= [[ -n "$log" ]] || return if [[ "$(uname -s)" == "Darwin" ]]; then oldLogTimestamp=$(stat -L -f %Sm -t '%Y-%m-%d-%H%M%S' "$log" 2>/dev/null) else oldLogTimestamp="$(stat -L -c '%10y' "$log" | sed -e 's@[.].*$@@g' -e 's@:@@g' -e 's@ @-@g')" fi [[ "$oldLogTimestamp" =~ ^[2-9]{1}[0-9]{3}- ]] || oldLogTimestamp=$(date +'%Y-%m-%d-%H%M%S') echo "$oldLogTimestamp" } #------------------------------------------------------------------------------ # Function: terminate # shellcheck disable=SC2317,SC2154 function terminate () { # Disable signal trapping. trap - EXIT SIGINT SIGTERM dbg "ExitCode: $ErrorCount" [[ "$Log" == "off" ]] || msg "\\nLog is: $Log\\n${H1}" # With the trap removed, exit. exit "$ErrorCount" }