SFTP w/ proper atomic put and locking
Robey Pointer
robey at lag.net
Sat Nov 12 02:57:48 GMT 2005
On 5 Nov 2005, at 0:56, John Arbash Meinel wrote:
> The current implementation of SFTPTransport did not handle file
> locking,
> or putting atomically. Since this is about to be used by a bunch of
> people, who are going to be collaborating with it, we need at least a
> little bit of safety that we won't clobber someone else's changes, or
> have the network connection die in the middle of a push, and have the
> remote tree broken.
>
> So I did 2 things, first, I 'put' into temporary files, and then
> rename
> them into place.
>
> Second, I open a file with O_EXCL which is .bzr/branch-lock.write-
> lock,
> it is a cheesy way to implement "Transport.lock_write()", but I
> think it
> is something that will work for us.
> If SFTPTransport tries to lock the file, but finds the lock is already
> there, it will throw a LockError exception, which generally prevents
> further changes to that branch.
Well, you've definitely convinced me that paramiko's SFTPClient.file
() should have some kind of file-flag translation for O_EXCL. :) I
picked 'x' (someone please shout out if this is a bad choice) and it
should be in 1.5.2 or whatever the next version turns out to be. I
promise not to break your version any time soon. :)
I think you're right that if we're going to rely on transports to do
read/write locking, we'll need some way to ask for locks to be
broken. This makes me feel pretty icky. But it should probably just
be part of the transport interface.
robey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051111/8afd2c32/attachment.pgp
More information about the bazaar
mailing list