Notive when files have changed

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21794 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-10-10 17:42:29 +00:00
parent a097b09d2b
commit 9919e36065
2 changed files with 43 additions and 0 deletions

View file

@ -1,3 +1,8 @@
2005-10-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSURLHandle.m: alter file handle to nitice if a file has
changed.
2005-10-09 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Additions/GNUstepBase/GSFileHandle.h:

View file

@ -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;
}