file monitored by kqueue isn't deleted
file monitored by kqueue isn't deleted
- Subject: file monitored by kqueue isn't deleted
- From: Eric Ocean <email@hidden>
- Date: Fri, 15 Oct 2004 16:11:18 -0700
(This was first posted on cocoa-dev, but I think that darwin-dev is a more appropriate list.)
I'm monitoring an Adobe Illustrator file for changes using a kqueue. When saving a file, Illustrator first renames that file, then creates a new file with the original filename/path, and finally deletes the old, renamed file. Fine.
So I get a rename notification, and then I get a delete notification, but I will not get a subsequent write notification on the old path when the new file is written, presumably because kqueue monitors file descriptors and the new file has a new file descriptor. Fine.
I'm currently removing the old fd from the kqueue, re-adding the new fd to my kqueue, and then running my "file modified" code. This works, and is safe according to this message post: http://lists.apple.com/archives/darwin-development/2004/Feb/msg00075.html
Here's the problem: the file Illustrator renamed is never removed. I know Illustrator is calling unlink() after the rename, because that's what causes the delete notification to be sent according to the kqueue man page. However, after I terminate my program, the file remains. I'm assuming that because kqueue had an open file descriptor (or something similar down in the kernel), it prevented the file from being truly removed
while the kqueue was running. Okay, then once I close the kqueue and the fd, the file should then have no further kernel references and be deleted, right?
And even if somehow my program did have an extra file descriptor open to the old file, when I quit my program, the file descriptor should be closed and the unlink should succeed, shouldn't it?
Well, since that isn't happening, I'm thinking, I'll just use a hammer and call unlink() on the old file myself. No problem...except that I don't know the file name it was renamed to, and unlink() takes a path! AFAICT after googling for a while, there isn't a function with the unlink() functionality that takes a file descriptor (nor should there be, when you think about it).
I'm out of ideas. Manually doing an unlink() on the renamed file seems like a hack to me. I don't understand why the file isn't being removed to begin with. And I'm not sure how to go about finding the file's renamed path if I go down that path. The kqueue API doesn't appear to give you that handy piece of information; perhaps I just missed it. I'm guessing I would have to loop over the inodes of the files in the directory until I found one with the same inode as the old file. That's pretty low-level for such a simple piece of functionality.
Thanks for any assistance.
Regards,
Eric Ocean
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden