From: Paul Archer Date: 2009-07-17T03:37:02+09:00 Subject: making sure a file isn't being written/copied before moving So, I'm (still) working on some scripts to rename and reorganize my image files. Right now, I have a script on my laptop that pulls images off the CF card and stores them locally. I have another script that rsync's the images to my server at home whenever there's a connection available. These scripts don't step on each other because they look at the process list for instances of rsync. But I need to write two more scripts that take the image files from an incoming directory, rename them, and drop them into a directory for me to work on them; then once I've done whatever I'm going to do (cull, keyword, etc), then I put them into a directory for archiving. The images are going to be pulled from that directory, put in an archive directory, and have the immutable extended attribute (xattr) set. My problem/issue is that I don't want to do anything with a file that is in the process of being moved into one of these directories. I have to be sure that the file is not still being moved/copied. Now, these directories are all on the same filesystem, so it *should* be an atomic change by the filesystem (technically a rename of the file from one directory/file name to another). But I want to be sure--plus I may be dropping files into the incoming directory from elsewhere from time to time. (I plan on going through my backlog of old untagged files eventually.) Can someone suggest an easy (or at least reliable) way to make sure that any file I'm about to modify isn't being touched by another program? Paul