I'm writing a script which modifes mailbox files (the purpose of this is to delete messages which are older than a certain date). My intention is to run this script as a Cron job. In order to avoid trouble if I try to modify a mailbox file at the same time that TCH's mail software is also modifying it, I need to be able to lock the file before I modify it, and unlock it again afterwards. This lock/unlock needs to be done in the same way that the TCH mail software does it.<br /><br />Does anyone know how to do this?<br /><br />Failing that, what is the software that TCH uses to process mail, i.e. to receive it via SMTP, to allow it to be fetched via POP3 or IMAP, and to do the webmail stuff? Presumably all of this software needs to be able to lock and unlock mailbox files. If I know what this software is I'll try to find out how it does lock/unlock.<br /><br />Many thanks - Rowan<!--content-->
create a file called "inbox.lock" in the same directory as the inbox - and delete it again once you have finished.<!--content-->
<!--quoteo(post=203966:date=Apr 9 2007, 08:22 AM:name=TCH-Andy)--><div class='quotetop'>QUOTE(TCH-Andy @ Apr 9 2007, 08:22 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=203966"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->create a file called "inbox.lock" in the same directory as the inbox - and delete it again once you have finished.<!--QuoteEnd--></div><!--QuoteEEnd--><br />Presumably I have to check for the existence of the file before creating it, and if it's already there wait a while?<br /><br />And how do I create the lock file in an atomic way? I have read that the straightforward way of doing this can result in race conditions, especially if NFS is being used. Does TCH use NFS?<br /><br />The recommended solution to this is said to be to create the lock file as a link to a previously created uniquely named file. Would you recommend this approach? Is this what the mail software used on TCH actually does? Or is there a better way?<br /><br />Thanks for your help - Rowan<!--content-->
create a file called "inbox.lock" in the same directory as the inbox - and delete it again once you have finished.<!--content-->
<!--quoteo(post=203966:date=Apr 9 2007, 08:22 AM:name=TCH-Andy)--><div class='quotetop'>QUOTE(TCH-Andy @ Apr 9 2007, 08:22 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=203966"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->create a file called "inbox.lock" in the same directory as the inbox - and delete it again once you have finished.<!--QuoteEnd--></div><!--QuoteEEnd--><br />Presumably I have to check for the existence of the file before creating it, and if it's already there wait a while?<br /><br />And how do I create the lock file in an atomic way? I have read that the straightforward way of doing this can result in race conditions, especially if NFS is being used. Does TCH use NFS?<br /><br />The recommended solution to this is said to be to create the lock file as a link to a previously created uniquely named file. Would you recommend this approach? Is this what the mail software used on TCH actually does? Or is there a better way?<br /><br />Thanks for your help - Rowan<!--content-->