#! /bin/bash ################################################################################ # # Copyright (c) 2023, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # DATE # # $Date: 2023/05/15 $ # # SYNOPSIS # # # DESCRIPTION # # This script checks the size of files synced by a user. # This script is intended to be use with this trigger: # check-sync-size command pre-user-sync "path/check-sync-size.sh %serverport% # %user% %client% %clientcwd% %argsQuoted% 1000000" # where 1000000 is the sync maximum size in bytes # ################################################################################ p4port=$1 p4user=$2 p4client=$3 clientcwd=$4 args=$5 maxSize=$6 totalSize=0 IFS="," p4 -s -p $p4port login $p4user > /dev/null for arg in $args do if [ "$arg" = "-n" ]; then exit 0 else if [ "${arg::1}" = "/" ]; then if [[ ! $arg =~ "#0" ]] && [[ ! $arg =~ "#none" ]]; then depotFile=`p4 -p $p4port -u $p4user -c $p4client -H $clientcwd -ztag -F "%depotFile%" where $arg` size=`p4 -p $p4port -u $p4user -c $p4client -ztag -F %totalFileSize% sync -n -q -s $depotFile` totalSize=$((totalSize + size)) fi fi fi done if [[ "$totalSize" -gt "$maxSize" ]]; then echo "Warning: sync restricted to $maxSize bytes maximum." echo -n " " echo "Please, reduce the scope of your sync command!" exit 1 fi exit 0
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 29557 | Pascal Soccard | Perform the p4 commands in the script as the user syncing the files | ||
#1 | 29556 | Pascal Soccard |
This trigger script enforces the maximum size of files that a user is allowed to sync. |