~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Source/NSURLHandle.m

Tags: upstream-1.11.2
ImportĀ upstreamĀ versionĀ 1.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
   You should have received a copy of the GNU Library General Public
22
22
   License along with this library; if not, write to the Free
23
 
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
23
   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
24
24
 
25
25
   <title>NSURLHandle class reference</title>
26
 
   $Date: 2005/02/22 11:22:44 $ $Revision: 1.36 $
 
26
   $Date: 2005/11/06 13:53:40 $ $Revision: 1.43 $
27
27
*/
28
28
 
29
29
#include "config.h"
38
38
#include "Foundation/NSRunLoop.h"
39
39
#include "Foundation/NSFileManager.h"
40
40
 
41
 
@class  GSFileURLHandle;
 
41
 
42
42
@class  GSFTPURLHandle;
 
43
@interface GSFTPURLHandle : NSObject    // Help the compiler
 
44
@end
43
45
@class  GSHTTPURLHandle;
 
46
@interface GSHTTPURLHandle : NSObject   // Help the compiler
 
47
@end
 
48
 
 
49
@interface      GSFileURLHandle : NSURLHandle
 
50
{
 
51
  NSString              *_path;
 
52
  NSMutableDictionary   *_attributes;
 
53
}
 
54
@end
44
55
 
45
56
/*
46
57
 * Keys for NSURLHandle
306
317
 */
307
318
- (void) cancelLoadInBackground
308
319
{
 
320
  RETAIN(self);
309
321
  [_clients makeObjectsPerformSelector:
310
322
    @selector(URLHandleResourceDidCancelLoading:)
311
323
    withObject: self];
312
324
  [self endLoadInBackground];
 
325
  RELEASE(self);
313
326
}
314
327
 
315
328
- (void) dealloc
562
575
 * </p>
563
576
 * <p>
564
577
 *   The GNUstep implementation for <em>ftp:</em> sets the specified data
565
 
 *   as information to be weitten to the URL next time it is loaded - so
 
578
 *   as information to be written to the URL next time it is loaded - so
566
579
 *   the method always returns YES.
567
580
 * </p>
568
581
 */
593
606
 
594
607
@end
595
608
 
596
 
@interface      GSFileURLHandle : NSURLHandle
597
 
{
598
 
  NSString              *_path;
599
 
  NSMutableDictionary   *_attributes;
600
 
}
601
 
@end
602
 
 
603
609
/**
604
610
 * <p>
605
611
 *   This is a <em>PRIVATE</em> subclass of NSURLHandle.
659
665
  fileLock = [NSLock new];
660
666
}
661
667
 
 
668
- (NSData*) availableResourceData
 
669
{
 
670
  if (_data != nil)
 
671
    {
 
672
      NSDictionary      *dict;
 
673
 
 
674
      dict = [[NSFileManager defaultManager] fileAttributesAtPath: _path
 
675
                                                     traverseLink: YES];
 
676
      if (dict == nil)
 
677
        {
 
678
          // File no longer exists.
 
679
          DESTROY(_data);
 
680
          DESTROY(_attributes);
 
681
        }
 
682
      else
 
683
        {
 
684
          NSDate        *original;
 
685
          NSDate        *latest;
 
686
 
 
687
          original = [_attributes fileModificationDate];
 
688
          latest = [dict fileModificationDate];
 
689
          if ([latest earlierDate: original] != latest)
 
690
            {
 
691
              // File has been modified
 
692
              DESTROY(_data);
 
693
              DESTROY(_attributes);
 
694
            }
 
695
        }
 
696
    }
 
697
  return [super availableResourceData];
 
698
}
 
699
 
662
700
- (void) dealloc
663
701
{
664
702
  RELEASE(_path);
 
703
  RELEASE(_attributes);
665
704
  [super dealloc];
666
705
}
667
706
 
732
771
- (NSData*) loadInForeground
733
772
{
734
773
  NSData        *d = [NSData dataWithContentsOfFile: _path];
 
774
  NSDictionary  *dict;
735
775
 
 
776
  dict = [[NSFileManager defaultManager] fileAttributesAtPath: _path
 
777
                                                 traverseLink: YES];
 
778
  RELEASE(_attributes);
 
779
  _attributes = [dict mutableCopy];
736
780
  [self didLoadBytes: d loadComplete: YES];
737
781
  return d;
738
782
}