Multiple Application Instances Opening same local db file

Ernesto Giannotta erne at apimac.com
Sun Feb 27 18:56:37 CST 2011


On 27-feb-2011, at 23:20, Ruslan Zasukhin wrote:

> On 2/27/11 7:02 PM, "Ernesto Giannotta" <erne at apimac.com> wrote:
> 
> Hi Guys,
> 
>>>> Is there a way to tell the file has already been open?
>>> 
>>> On linux exists   technique of lock file.
> 
>>> YOUR family of apps, can follow to rule
>>> That app check for my_db.lck file
>>> If not found then it can open it and create such lock file.
>>> 
>>> All others will see lock file and not touch db.
>>> E.g. Archicad do this on WIN and MAC ...
>> 
>> in Cocoa when I try to open an already open DB Vale gracefully throws an
>> NSException whose name is:
>> 
>> File "Untitled Notes.notepad" cannot be opened because it is used by another
>> application.
>> 
>> How does she know?
> 
> Ops,  I really have point linux-only way.
> 
> On MAC OS X and Windows all is simpler.
>    Valentina engine open local db files in the EXCLUSIVE mode,
>    so other apps if try will get back OS error -- file is busy.
> 

Thanks Ruslan,

I was looking for a way to check if file is busy without try to open it, but just couldn't find one.
There's a NSFileBusy key in the fileAttributes dictionary returned by fileManager, but it never seems to be set.
If I test with a file that I know is busy, this is the fileAttributes dictionary I get:

    NSFileCreationDate = 2011-02-20 23:08:45 +0100;
    NSFileExtensionHidden = 1;
    NSFileGroupOwnerAccountID = 20;
    NSFileGroupOwnerAccountName = staff;
    NSFileHFSCreatorCode = 1664176206;
    NSFileHFSTypeCode = 1449423715;
    NSFileModificationDate = 2011-02-27 12:49:18 +0100;
    NSFileOwnerAccountID = 501;
    NSFileOwnerAccountName = erne;
    NSFilePosixPermissions = 420;
    NSFileReferenceCount = 1;
    NSFileSize = 1806336;
    NSFileSystemFileNumber = 11866285;
    NSFileSystemNumber = 234881027;
    NSFileType = NSFileTypeRegular;

> 
>> BTW why you set the name and not the reason with this info?
> 

talk about the NSException object that Vale raises.
It contains  
name = File "Untitled Notes.notepad" cannot be opened because it is used by another application.
reason = ErrorNumber:0x59501

I'd expect to find the more user friendly message into reason rather than name.

From the NSException docs:

name
Returns an NSString object used to uniquely identify the receiver.

reason
Returns an NSString object containing a “human-readable” reason for the receiver.

userInfo
Returns an NSDictionary object containing application-specific data pertaining to the receiver.






More information about the Valentina mailing list