Buildbot Script loop problem/question

Hi all,

I’m building an old MacMini into a buildbot for various open source projects I make snapshots for. I’m triggering snapshots when I receive mails from the commit mailing lists and have Mail.app show me a dialog and run the correct shell script (see http://macscripter.net/viewtopic.php?id=39298).
Now sometimes the projects have new commits while I’m still compiling and when that happens it can wreak havoc with the current build or the next one.
To solve this I thought of the following:

  • the above mentioned AppleScript creates a lockfile #1 which the shell script will delete at the end of its run (or when it encounters an error)

  • When another commit triggers the AppleScript, it will see there is lockfile #1, create another lockfile #2 and will wait for lockfile #1 to get deleted and will then delete lockfile #2 and start anew with creating lockfile #1 and running the shell script

  • When the AppleScript is triggered yet again while the AppleScript is still looping and waiting for lockfile #1 to be deleted it will just quit (return).

This is what I’m doing and I wonder if I’m doing it wrong altogether. The lockfile #2 seems a bit error prone. Also sometimes when testing I’d cancel the looping script and manually deleted both lockfiles. When I then ran the script again it stopped with step three (reporting there is lockfile #2 and quitting the script) even though the files were gone. Running it again worked then.

set fullpath to (path to home folder as Unicode text) & ".local" -- ~/.local
set subj to "Test"
set lockfile1 to (fullpath & ":" & subj & "build1.lockfile")
set lockfile2 to (fullpath & ":" & subj & "build2.lockfile")
tell application "Finder"
	if exists file lockfile1 then
		if exists file lockfile2 then
			display dialog (POSIX path of lockfile2) & " exists" -- just for debug
			return
		else
			make new file at fullpath with properties {name:subj & "build2.lockfile"}
			repeat while (file lockfile1 exists) = true
			end repeat
			delete file lockfile2
			make new file at fullpath with properties {name:subj & "build1.lockfile"}
		end if
	else
		make new file at fullpath with properties {name:subj & "build1.lockfile"}
		if exists file lockfile2 then
			delete file lockfile2
		end if
	end if
end tell
display dialog "Now do other stuff"