Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25227

Re: How to safely maintain a status file

Date 2012-07-12 19:38 +0200
From Laszlo Nagy <gandalf@shopzeus.com>
Subject Re: How to safely maintain a status file
References (1 earlier) <sanjv7lo0vb3rlhip4ov1gpgp4gs51bvfr@invalid.netcom.com> <4FF9F454.40207@shopzeus.com> <jtcvf8$ock$1@dough.gmane.org> <4FFEC371.5040703@shopzeus.com> <4FFECB96.9040601@cheimes.de>
Newsgroups comp.lang.python
Message-ID <mailman.2051.1342114916.4697.python-list@python.org> (permalink)

Show all headers | View raw


> Sorry, but you are wrong. It's just one operation that boils down to
> "point name to a different inode". After the rename op the file name
> either points to a different inode or still to the old name in case of
> an error. The OS guarantees that all processes either see the first or
> second state (in other words: atomic).
>
> POSIX has no operation that actually deletes a file. It just has an
> unlink() syscall that removes an associated name from an inode. As soon
> as an inode has no names and is not references by a file descriptor, the
> file content and inode is removed by the operating system. rename() is
> more like a link() followed by an unlink() wrapped in a system wide
> global lock.
Then please help me understand this.

"Good" case:

process #1:  unlink(old status file)
process #1: rename(new status file)
process#2: open(new status file)
process#2: read(new status file)

"Bad" case:

process #1:  unlink(old status file)
process#2: open(???) -- there is no file on disk here, this system call 
returns with an error!
process #1: rename(new status file)

If it would be possible to rename + unlink in one step, then it would be 
okay. Can you please explain what am I missing?

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to safely maintain a status file Laszlo Nagy <gandalf@shopzeus.com> - 2012-07-12 19:38 +0200

csiph-web