Re: Locking
Re: Locking
- Subject: Re: Locking
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Wed, 16 Jun 2004 10:11:48 +0200
On 16.06.2004, at 02:43, Wade Tregaskis wrote:
I have an application which does
[ fileManager removeFileAtPath: aPath handler: self ]
When "aPath" is in use by Xcode this fails.
But Finder tells me that "aPath" is not locked.
So: how does Xcode prevent the removal of "aPath" ?
The 'Locked' attribute is distinct from being in use. XCode
presumably has the file open, possibly with exclusive access... I'm
not sure what is necessary to prevent deletion, i.e. whether just
having it open for non-exclusive reading will be enough.
FWIW, it's possibly a bug that the file is kept open... unless you're
planning to access the file in the very near future, and/or regularly,
you should generally always close them to prevent these kinds of
problems. I've noticed XCode is pretty bad with this, although it's
far from the only one.
I just did some more tests.
1. opened a file in TextEdit and made some modifications (without
saving - so the fie is documentEdited): it can be deleted without
problem by NSFileManager.
2. locked the file with FInder - can NOT be deleted by NSFileManager.
2a tried rm. It asked me "override uchg", I answered "y", it replied
"Operation not permitted". So why ask in the first place? But at least
consistent.
(The file now has: "NSFileImmutable=1")
3. Opened the project in Xcode - can be deleted
I tried al sort of things but failed to make Xcode lock (or keep open)
the file. So Xcode is a bit inconsistent.
4. Wrote a small programm which does fopen("myFile","r") without
fclose().
NSFileManager can NOT delete the file. Makes sense.
5. did rm myFile. File has disappeared in Finder, no more in ls, not
known to NSFIleManager any more.
The app which did the fopen() can still do fgetc() without problem
though.
(Interesting aside: Xcode noticed that "myFile" had disappeare and
offered to re-create it. So it seems to keep copies of (all?) project
files somewhere).
But now the final question: how can I find out the app, which has the
file still open?
Which probably amounts to the question: has the filesystem only a bit
"file open" or a list of int flags "file open by pid 12345" , "file
open by pid 4321", ... ?
Gerriet.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >Locking (From: "Gerriet M. Denkmann" <email@hidden>) |