discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defaults being destroyed


From: Richard Frith-Macdonald
Subject: Re: Defaults being destroyed
Date: Tue, 27 Aug 2002 10:03:34 +0100

On Tuesday, August 27, 2002, at 08:29 AM, Alexey I. Froloff wrote:

On Tue, Aug 27, 2002 at 08:14:55AM +0100, Richard Frith-Macdonald wrote:
On Tue, Aug 27, 2002 at 07:15:07AM +0100, Stefan Urbanek wrote:
[/dev/null]
It seems, that if a program does not see some domain in
database at program startup, it will not write it back. It
may be a problem in -[NSUserDefaults synchronize] I think,
but I am not sure.
-[NSUserDefaults synchronize] uses NSLock than works between
threads but not processes. Writinig defaults database is not
atomic operation.
Actually, it uses writeToFile:atomically: with the second argument
set to YES ... so it *IS* an atomic operation.
This is *NOT* atomic operation.

NSData.m:

- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile
{
[/dev/null]
  if (useAuxiliaryFile)
    {
      NSFileManager             *mgr = [NSFileManager defaultManager];
      NSMutableDictionary       *att = nil;

      if ([mgr fileExistsAtPath: path])
        {
          att = [[mgr fileAttributesAtPath: path
                              traverseLink: YES] mutableCopy];
          IF_NO_GC(TEST_AUTORELEASE(att));
          [mgr removeFileAtPath: path handler: nil];

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Thanks.
That's a bug ... fixed in CVS now.  This might have been the problem.

However, thinking about this it occurred to me that there might also be
another problem related to the way writeToFile:atomically: works.

The method first writes a temporary file, then renames it - it occurred
to me that the modification time of the resulting file is the time at
which the temporary file was written, not the time at which it was renamed.

This leaves a window in which different processes could get out of sync
with their ideas of what was updated when.
In order to prevent this, I've added use of NSDistributedLock to NSUserDefaults
anyway.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]