From: Paul Archer Date: 2009-07-18T12:34:55+09:00 Subject: Re: making sure a file isn't being written/copied before moving 5:28pm, Brian Candler wrote: > Paul Archer wrote: >> Perhaps you missed it in my original post (or perhaps I simply wasn't >> clear), but I may be operating on files that are added arbitrarily. My >> concern is that the script starts acting on a file that is still being >> copied. Renaming it won't help there. > > The program which drops files into the directory has to work the same > way: > > - open temporary file > - write to it > - close it > - fsync if you want to be sure it's on disk even if power is pulled > - rename it to final location > > That's why I said to look at Maildir semantics - adding new E-mails to a > maildir works like this. (They are written into the tmp/ directory, and > then renamed into the new/ directory) > -- I see what you're saying. My issue was that I will be moving files into this directory by hand as I go through my old, unmanaged digital images and put them in this directory to be renamed and start the DAM (digital asset management) process. Of course, this is all moot now that I've found inotify will solve the problem for me. Actually, it solves three problems: 1) It blocks, so I don't have to poll the directory. 2) It lets me know when a file has been moved to or written in the directory (even if it's in a subdirectory). 3) It tells me the name of the file, so I don't have to go out and find it. Paul