mikeash.com: Name/comment conflict
source link: https://www.mikeash.com/pyblog/namecomment-conflict.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Going through some code, I came across a function called AtomicReplaceDirectory
. The very first line of this function was a comment that said:note, despite the name, this is *not* atomic.
Isn't it great when the name and the comments are at odds?
It's not quite as bad as it sounds; it turns out that an atomic directory replace operation is impossible to perform on Mac OS X (and pretty much any other OS/FS combination). This function performs a best effort at something that approximates an atomic directory replacement, so its name is reasonable in the end.
Comments:
Atomic file swaps are usually pretty easy. You get the files on the same disk, make a system call, the OS swaps the pointers around and you’re good. No matter what happens, you’ll either get the old file still there or you’ll get the new file. You’ll never get a corrupted or empty file. This technique doesn’t work for directories, though, so you just have to approximate it.
Comments RSS feed for this page
Add your thoughts, post a comment:
Spam and off-topic posts will be deleted without notice. Culprits may be publicly humiliated at my sole discretion.
Name:The Answer to the Ultimate Question of Life, the Universe, and Everything?Comment:Formatting: <i> <b> <blockquote> <code>.NOTE: Due to an increase in spam, URLs are forbidden! Please provide search terms or fragment your URLs so they don't look like URLs.Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK