File locking strategies with ex.exe and exu
- Posted by acran at readout.fsnet.co.uk Jun 14, 2002
- 368 views
Hello everyone, I'm working on a very simple helpdesk / call tracking / trouble ticket system with Euphoria. I'm sticking with a basic character cell interface using graphics.e and putting platform() calls in so it will run unmodified on either DOS32 (in a Windows DOS box) or on Linux (I'm using a very _old_ RedHat 5.1). I store information for each "call" in two files. One file holds the core call data (who opened the call, their phone number, email address and so on). The other file holds a free format "comments" record so progress on the call can be recorded. When a new call is created I need to come up with unique file names to hold the core call data and the call comments. Right now I just have a loop with a counter to form a file name (e.g. call0001) and try and open the file. If it opens it already exists so increment and try again. Once I have file that doesn't open (and therefore doesn't exist) I open the file for writing and it's mine. Now I'm fully aware that this isn't full proof in a multi user situation. If I was writing this in C on a UNIX box I'd be looking at the flock routines. What can I do in Euphoria to ensure that I can open a file and be sure that another person running the application at the same time doesn't try and open the same file? I'm thinking about using some sort of lock file that you write a random string to, close the file, open for read, read the string back and if it matches your 99.99% sure you have that file to yourself but it seems kludgy and not 100% So ideas for file locking methods for ex.exe and exu? Over to you gurus Regards, Andy Cranston.