# # # INHIBIT_DUPLICATE_ELE.pl # # Before allowing a new element to be created make sure that the # element does not already exist in for this directory in some # branch that is invisible to thie current view. If the element # already exist warn the user and disallow the action. # # If the user is the VOB_OWNER then give the option to abort the # mkelem or perform the action anyway. # # Author: Charles W. Clarke III (ABS) # email: charles@abs-consulting.com # URL: http://www.abs-consulting.com # Date: Apr. 08, 1998 ########################################################### # History: 04/08/98 : Created for A Better Solution, Inc. # : 11/11/00 : Added line for ClearCase 4.0 # : 08/22/01 : Tweaked for UNIX - Thanx - Maggie Stearns # : 01/23/02 : Changed "Windows_NT" to "Windows*" # : 04/23/02 : Changed to be called from lnname:mkelem # : 04/27/02 : Change algorythm to a faster one. # : 09/04/02 : Removed trailing space - thanx Mark Jaskilka # : 03/02/03 : Changed to also work for ln, ln -s # : as well as mkelem and "move" command. # : 07/01/03 : - Compressed some "if" statements # : - Test if possible dupe is same named branch # : 03/19/07 : Added change for slink # : 06/19/08 : Added case for snapshpt views (thanx Greg) ########################################################### $OS="$ENV{'OS'}"; $PN="$ENV{'CLEARCASE_PN'}"; $VIEW_KIND="$ENV{'CLEARCASE_VIEW_KIND'}"; if ($OS =~ /[Ww]indows*/ ) { #################################################################### # Convert any "X:\view_tag\vob_tag\.\*" to "X:\view_tag\vob_tag\*" # #################################################################### $PN =~ s/\\\.\\/\\/ ; $DIR_DELIM = "\\"; $TRASH = "NUL"; } else { $DIR_DELIM = "/"; $TRASH = "/dev/null"; } ########################## # Get short element name # ########################## @PARTS = split (/[\/\\]/, $PN); $ELEMENT_NAME = $PARTS[$#PARTS]; ############################# # Get parent directory name # ############################# $PARENT = $PN; while (chop ($PARENT) !~ /[\\\/]/) { ; } ############################# # Make parent directory DNA # ############################# $PARENT_DNA = "$PARENT"."$DIR_DELIM".".$ENV{'CLEARCASE_XN_SFX'}"; @PARENT_DIR_BRANCHES=`cleartool lsvtree -all -s "$PARENT_DNA"`; ####################### # Look for evil twins # ####################### $FOUND="NONE"; if ("$VIEW_KIND" eq "dynamic") { ##################### # For Dynamic views # ##################### foreach $PARENT_DIR_BRANCH (@PARENT_DIR_BRANCHES) { chomp ($PARENT_DIR_BRANCH); $POSSIBLE_DUPE = "$PARENT_DIR_BRANCH"."$DIR_DELIM"."$ELEMENT_NAME"; if ( -e "$POSSIBLE_DUPE" ) { $type = `cleartool desc -fmt %m "$POSSIBLE_DUPE"`; chomp ($type); if ("$type" ne "branch") { $FOUND="TRUE"; last; } } } } else { ###################### # For snapshot views # ###################### foreach $PARENT_DIR_BRANCH (@PARENT_DIR_BRANCHES) { chomp ($PARENT_DIR_BRANCH); $POSSIBLE_DUPE = "$PARENT_DIR_BRANCH"."$DIR_DELIM"."$ELEMENT_NAME"; `cleartool ls -s \"$POSSIBLE_DUPE\" > $TRASH 2> $TRASH`; if (!$?) { $type = `cleartool desc -fmt %m "$POSSIBLE_DUPE"`; chomp ($type); if ("$type" ne "branch") { $FOUND="TRUE"; last; } } } } if ("$FOUND" eq "NONE") { ######################################################## # No duplicate element is found on invisible branches. # # Allow the creation of the element. # ######################################################## exit 0; } ################################################################ # Possible duplicate element is found on invisible branche(s). # ################################################################ $USER = "$ENV{'CLEARCASE_USER'}"; $VOB_PN = "$ENV{'CLEARCASE_VOB_PN'}"; $POP_KIND = "$ENV{'CLEARCASE_POP_KIND'}"; ####################################### # Only use ONE of the next two lines. # ####################################### #$VOB_OWNER=`cleartool desc -fmt %u -vob $VOB_PN`; # For ClearCase 3.2.1 or previous # $VOB_OWNER=`cleartool desc -fmt %u vob:$VOB_PN`; # For ClearCase 4.0 or later # ########################################################################### # In actuality this does not return the "owner" it returns the "creator". # # cleatool describe -fmt %[owner]p vob:{vot_tag} should return the owner # # of the VOB like it does for many other objects but is doesn't as of 5.0 # # # # But this is a teaching script so it shall suffice. # ########################################################################### if ($POP_KIND eq "mkelem") { ######################### # From a mkelem command # ######################### $PROMPT="\"This element ($ELEMENT_NAME) ALREADY exists for the directory ($PARENT)\n"; } else { #################################### # From a ln, ln -s or "mv" command # #################################### $PN="$ENV{'CLEARCASE_PN2'}"; @PARTS = split (/[\\\/]/, $PN); $OLD_ELEMENT_NAME = $PARTS[$#PARTS]; if (!$POP_KIND || ($POP_KIND eq "rmname") || ($POP_KIND eq "mkslink")) { $PROMPT="\"This element ($ELEMENT_NAME) ALREADY exists for the directory ($PARENT)\n"; } } $PROMPT="$PROMPT in another branch as ($POSSIBLE_DUPE).\n\n"; $PROMPT="$PROMPT You probably should create a ClearCase hardlink to that on instead.\n\n"; if ( $USER eq $VOB_OWNER ) { $PROMPT="$PROMPT NOTE: As VOB_OWNER you may choose to create this \n"; $PROMPT="$PROMPT VOB element anyway.\n\n\""; $RETURN = system ("clearprompt yes_no -mask yes,abort -default abort -pre -pro $PROMPT"); if ( $RETURN == 0) { ######################################################## # Duplicate was found but the VOB_OWNER has decided to # # create the element anyway. # ######################################################## exit 0; } } else { $PROMPT="$PROMPT NOTE: If you feel you really need to perform this action \n"; $PROMPT="$PROMPT e-mail the VOB_OWNER ($VOB_OWNER).\n\n\""; system ("clearprompt yes_no -mask abort -default abort -pre -pro $PROMPT"); } #################################################### # Dissallow the creation of the duplicate element. # #################################################### exit 1;