> I've come across this problem - instead of uploading the file to it's > > intended directory, upload it to a temp directory, with a unique name > (say uuuuuyyyymmddhhmmss where uuuuu is username and the rest are > obvious) and then *rename* it to it's correct name in the real > destination directory. Do the move in a try... except block and if it > fails, take evasive action. > > In FTP a rename (i.e. move) is usually an atomic action but an upload is > not. You have an unavoidable race condition here trying to lock a file > (even if ftp allowed it) but with the method described above, you can > avoid it, but get the same effect.
This is a good method for transferring files, it handles broken-transfers especially well (if something on the other end is waiting for a particular filename.) But I think it just moves the locking problem from the upload to a rename. What happends if two clients try to rename their files at a half-second interval: both succeed, but the first-clients changes are clobbered. Actually, speaking of atomic functions, maybe you could use directory creation instead of a rename, because only one directory creation can succeed. This might be able to be incorperated into some sort of locking mechanism. cheers, -kt (obnoxious corporate .sig below) -- Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. -- http://mail.python.org/mailman/listinfo/python-list