Commit 23a4c0eb authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

9780596004590

0 → 120000
+1 −0
Changes for 9780596004590: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
9780596004590
 No newline at end of file

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
  
# Essential CVS, by Jennifer Vesperman
  
[![Essential CVS, by Jennifer Vesperman](http://akamaicovers.oreilly.com/images/9780596004590/cat.gif)](https://www.safaribooksonline.com/library/view/title/0596004591//)
  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.

freeze.sh

0 → 100755
+113 −0
Changes for freeze.sh: 113 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/sh
# Freeze - Lock a whole repository for backup.

KEYMAGIC=$$
TMPFILE=/tmp/freeze.$KEYMAGIC
bail_out () {
	# Exit abruptly. Return a failure code and display
	# an error message.
	echo "$1"
	rm -f $TMPFILE
	exit 1
}

freeze_directory () {
	echo "FREEZE: $1"
	# Obtain the master lock
	mkdir "$1/#cvslock"
	if [ $? != 0  ]
		then
                # Could not get master lock
		return 1
		fi
	# Create the readlock
	touch "$1/#cvs.rfl.$KEYMAGIC"
	# Record it in case of trouble
	echo $1 >> $TMPFILE
	rmdir "$1/#cvslock"
	return 0
}

thaw_repository () {
	# If we encounter anyone else playing with the
	# CVS locks during this, then there's a small risk
	# of deadlock. In that event, we should undo everything
	# we've done to the repository, wait and try again.
	# This function removes all the locks we've produced during
	# the run so far.
	for dir in `cat $TMPFILE`
		do
		echo "** THAW ** $dir"
		mkdir "$dir/#cvslock"
		if [ $? ]
			then
			# Remove readlock
			rm -f "$dir/#cvs.rfl.$KEYMAGIC"
			# Remove masterlock
			rmdir "$dir/#cvslock"
			fi
		done
	return 0
}

freeze_repository () {
	for dirname in `find $CVSROOT/$REPOSITORY -type d ! -iname CVS ! -iname Attic ! -iname "#cvslock"`
		do
		freeze_directory $dirname
		if [ $? != 0 ]
			then
			# We couldn't get the master lock.
			# Someone else must be working on the
			# repository
			thaw_repository
			return 1
			fi
		done
	return 0
}

if [ "$CVSROOT" == "" ]
	then
	echo "No CVSROOT specified in the environment"
	bail_out "Aborting"
	fi

if [ "$KEYROOT" == "" ]
	then
	KEYROOT="$CVSROOT"
	fi

if [ "$1" == "" ]
	then
	echo "No Repository specified."
	echo "Usage: $0 repository"
	bail_out "Aborting"
else
	REPOSITORY="$1"
	fi

# Double-check the validity of supplied paths
KEYFILE=$KEYROOT/.$REPOSITORY
test -d $CVSROOT || bail_out "Can't access $CVSROOT - is it a directory?"
touch $KEYFILE || bail_out "Can't access $KEYFILE - aborting"

TRIES=0
while	! freeze_repository
	do
	let TRIES=$TRIES+1
	echo "Could not freeze. Repository in use. (Attempt $TRIES)"
	if [ $TRIES -gt 9 ]
		then
		bail_out "Giving up"
		fi
	echo " Sleeping 1 second."
	sleep 1
	rm -f $TMPFILE
	echo "Trying again.."
	done
echo "** Repository $REPOSITORY frozen"
echo "$KEYMAGIC" >> $KEYROOT/.$REPOSITORY

rm -f $TMPFILE
exit 0

logo.png

0 → 100644
+2.9 KiB
Loading image diff...

unfreeze.sh

0 → 100755
+92 −0
Changes for unfreeze.sh: 92 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/sh
# Unfreeze - Unlock a whole repository.


bail_out () {
	# Exit abruptly. Return a failure code and display
	# an error message.
	echo "$*"
	rm -f $TMPFILE
	exit 1
}


unfreeze_directory () {
	echo "UNFREEZE: $1"
	mkdir "$1/#cvslock"
	if [ $? != 0  ]
		then
		# Could not get master lock
		return 1
		fi
	test -f "$1/#cvs.rfl.$KEYMAGIC" || echo "THAW: Expected to find a lockfile: $1/#cvs.rfl.$KEYMAGIC"
	# Proceed anyway.
	rm -f "$1/#cvs.rfl.$KEYMAGIC"
	rmdir "$1/#cvslock"
	return 0
}

unfreeze_repository () {
	TMPFILE=/tmp/freeze.$KEYMAGIC
	for dirname in `find $CVSROOT/$REPOSITORY -type d ! -iname CVS ! -iname Attic ! -iname "#cvslock"`
		do
		unfreeze_directory $dirname
		if [ $? != 0 ]
			then
			return 1
			fi
		done
	return 0
}

if [ "$CVSROOT" == "" ]
	then
	echo "No CVSROOT specified in the environment"
	bail_out "Aborting"
	fi

if [ "$KEYROOT" == "" ]
	then
	KEYROOT="$CVSROOT"
	fi

if [ "$1" == "" ]
	then
	echo "No Repository specified."
	echo "Usage: $0 repository"
	bail_out "Aborting"
else
REPOSITORY="$1"
	fi

# Double-check the validity of supplied paths
KEYFILE=$KEYROOT/.$REPOSITORY
test -d $CVSROOT || bail_out "Can't access $CVSROOT - is it a directory?"
test -f $KEYFILE || bail_out "No $KEYFILE appears to exist. Repository does not appear to be frozen"
TRIES=0

# Walk through each of the keys that the repository has been frozen with
# and unlock each one in turn. A single run of unfreeze, thaws multiple
# runs of freeze.
for KEYMAGIC in `cat $KEYFILE`
	do
	unfreeze_repository 
	if [ "$?" = "1" ]
		then
		echo "** Unable to obtain master locks for all directories."
		let TRIES=$TRIES+1
		if [ "$TRIES" = "10" ]
			then
			bail_out "Too many attempts. Giving up."
			fi
		sleep 1
		echo "** Trying again."
	else
		echo "** Repository $REPOSITORY thawed from freeze $KEYMAGIC"
		fi
		
	done
echo "** Unfreeze complete"
echo "** Repository $REPOSITORY thawed"
rm -f $KEYFILE
exit 0