diff --git a/ChangeLog b/ChangeLog index bf24cdabe..460894331 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-10-10 Richard Frith-Macdonald + + * Source/NSURLHandle.m: alter file handle to nitice if a file has + changed. + 2005-10-09 Richard Frith-Macdonald * Headers/Additions/GNUstepBase/GSFileHandle.h: diff --git a/Source/NSURLHandle.m b/Source/NSURLHandle.m index 0f621a502..23d4dbeb8 100644 --- a/Source/NSURLHandle.m +++ b/Source/NSURLHandle.m @@ -663,9 +663,42 @@ static NSLock *fileLock = nil; fileLock = [NSLock new]; } +- (NSData*) availableResourceData +{ + if (_data != nil) + { + NSDictionary *dict; + + dict = [[NSFileManager defaultManager] fileAttributesAtPath: _path + traverseLink: YES]; + if (dict == nil) + { + // File no longer exists. + DESTROY(_data); + DESTROY(_attributes); + } + else + { + NSDate *original; + NSDate *latest; + + original = [_attributes fileModificationDate]; + latest = [dict fileModificationDate]; + if ([latest earlierDate: original] != latest) + { + // File has been modified + DESTROY(_data); + DESTROY(_attributes); + } + } + } + return [super availableResourceData]; +} + - (void) dealloc { RELEASE(_path); + RELEASE(_attributes); [super dealloc]; } @@ -736,7 +769,12 @@ static NSLock *fileLock = nil; - (NSData*) loadInForeground { NSData *d = [NSData dataWithContentsOfFile: _path]; + NSDictionary *dict; + dict = [[NSFileManager defaultManager] fileAttributesAtPath: _path + traverseLink: YES]; + RELEASE(_attributes); + _attributes = [dict mutableCopy]; [self didLoadBytes: d loadComplete: YES]; return d; }