[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

kocienda kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:59:49 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 3c7d4dfa4b05ee8efff5a98f9942127d01066fd2
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Apr 1 00:01:04 2002 +0000

    2002-03-31  Ken Kocienda  <kocienda at apple.com>
    
            Labyrinth:
    
            Modified check file to correspond to new flow of control
            in the loader involving results returned from cache.
    
            * Tests/WebFoundation-CacheLoader/never-expires-test.chk:
    
            Tweaked output of dates
    
            * Tools/DiskCachePeek/DiskCachePeek.pbproj/project.pbxproj:
            * Tools/DiskCachePeek/main.m: (main):
    
    
            WebFoundation:
    
            Better handling of cases where a revalidated cache object is returned,
            including correct setting of headers and updating of cache object with revalidated
            results.
    
            The disk cache database now includes its own mmap code. Now, failed attempts to mmap a cache
            file return better result codes. This makes it possible for the cache
            to cut down on speculative disk I/O that had been necessary until now since
            the mmap code in Foundation does not report why an mmap attempt failed.
    
            * CacheLoader.subproj/IFHTTPURLProtocolHandler.h:
            * CacheLoader.subproj/IFHTTPURLProtocolHandler.m: (-[IFHTTPURLProtocolHandler
            initWithURLLoad:]), (+[IFHTTPURLProtocolHandler parseHTTPDateString:]),
            (-[IFHTTPURLProtocolHandler debugStringForCacheAttributeValue:]),
            (-[IFHTTPURLProtocolHandler createHTTPRequest]), (-[IFHTTPURLProtocolHandler
            cacheObjectIsValid:]), (-[IFHTTPURLProtocolHandler
            cacheObjectRequiresRevalidation:]), (-[IFHTTPURLProtocolHandler
            shouldCacheResourceData]), (-[IFHTTPURLProtocolHandler
            timeIntervalFromHTTPResponseHeader:]), (-[IFHTTPURLProtocolHandler
            calculateObjectAge]):
            * CacheLoader.subproj/IFURLLoad.m: (-[IFURLLoad succeeded]), (-[IFURLLoad
            shouldCacheResourceData]), (-[IFURLLoad didBeginLoading:]), (+[IFURLLoad
            IFURLLoadCacheCheckerRun:]):
            * Database.subproj/IFURLFileDatabase.m: (URLFileReaderInit), (-[IFURLFileReader
            initWithPath:]), (-[IFURLFileReader data]), (-[IFURLFileReader dealloc]),
            (-[IFURLFileDatabase objectForKey:]), (-[IFURLFileDatabase
            performSetObject:forKey:]), (-[IFURLFileDatabase performRemoveObjectForKey:]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@912 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/Misc.subproj/WebFileDatabase.m b/WebKit/Misc.subproj/WebFileDatabase.m
index 6598d0d..eeefe2a 100644
--- a/WebKit/Misc.subproj/WebFileDatabase.m
+++ b/WebKit/Misc.subproj/WebFileDatabase.m
@@ -2,6 +2,12 @@
 	Copyright 2002, Apple, Inc. All rights reserved.
 */
 
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <pthread.h>
+
 #import "IFURLFileDatabase.h"
 #import "IFNSFileManagerExtensions.h"
 #import "IFURLCacheLoaderConstantsPrivate.h"
@@ -22,6 +28,140 @@ enum
     SYNC_IDLE_THRESHOLD = 5,
 };
 
+// interface IFURLFileReader -------------------------------------------------------------
+
+ at interface IFURLFileReader : NSObject
+{
+    NSData *data;
+    caddr_t mappedBytes;
+    size_t mappedLength;
+}
+
+- (id)initWithPath:(NSString *)path;
+- (NSData *)data;
+
+ at end
+
+// implementation IFURLFileReader -------------------------------------------------------------
+
+/*
+ * FIXME: This is a bad hack which really should go away.
+ * Here we're using private API to hold us over until
+ * this API is made public (which is planned).
+ */
+ at interface NSData (IFExtensions)
+- (id)initWithBytes:(void *)bytes length:(unsigned)length copy:(BOOL)copy freeWhenDone:(BOOL)freeBytes bytesAreVM:(BOOL)vm;
+ at end
+
+static NSMutableSet *notMappableFileNameSet = nil;
+static NSLock *mutex;
+static pthread_once_t cacheFileReaderControl = PTHREAD_ONCE_INIT;
+
+static void URLFileReaderInit()
+{
+    mutex = [[NSLock alloc] init];
+    notMappableFileNameSet = [[NSMutableSet alloc] init];    
+}
+
+ at implementation IFURLFileReader
+
+- (id)initWithPath:(NSString *)path
+{
+    int fd;
+    struct stat statInfo;
+    const char *fileSystemPath;
+    BOOL fileNotMappable;
+
+    pthread_once(&cacheFileReaderControl, URLFileReaderInit);
+
+    self = [super init];
+    
+    data = nil;
+    mappedBytes = NULL;
+    mappedLength = 0;
+
+    NS_DURING
+        fileSystemPath = [path fileSystemRepresentation];
+    NS_HANDLER
+        fileSystemPath = NULL;
+    NS_ENDHANDLER
+
+    [mutex lock];
+    fileNotMappable = [notMappableFileNameSet containsObject:path];
+    [mutex unlock];
+
+    if (fileNotMappable) {
+        data = [NSData dataWithContentsOfFile:path];
+    }
+    else if (fileSystemPath && (fd = open(fileSystemPath, O_RDONLY, 0)) >= 0) {
+        // File exists. Retrieve the file size.
+        if (fstat(fd, &statInfo) == 0) {
+            // Map the file into a read-only memory region.
+            mappedBytes = mmap(NULL, statInfo.st_size, PROT_READ, 0, fd, 0);
+            if (mappedBytes == MAP_FAILED) {
+                // map has failed but file exists
+                // add file to set of paths known not to be mappable
+                // then, read file from file system
+                [mutex lock];
+                [notMappableFileNameSet addObject:path];
+                [mutex unlock];
+                
+                mappedBytes = NULL;
+                data = [NSData dataWithContentsOfFile:path];
+            }
+            else {
+                // On success, create data object using mapped bytes.
+                mappedLength = statInfo.st_size;
+                data = [[NSData alloc] initWithBytes:mappedBytes length:mappedLength copy:NO freeWhenDone:YES bytesAreVM:YES];
+                // ok data creation failed but we know file exists
+                // be stubborn....try to read bytes again
+                if (!data) {
+                    munmap(mappedBytes, mappedLength);    
+                    data = [NSData dataWithContentsOfFile:path];
+                }
+            }
+        }
+        close(fd);
+    }
+    
+    if (data) {
+#ifdef WEBFOUNDATION_DEBUG
+        if (mappedBytes) {
+            WebFoundationLogAtLevel(WebFoundationLogDiskCacheActivity, @"- [WEBFOUNDATION_DEBUG] - mmaped disk cache file - %@", path);
+        }
+        else {
+            WebFoundationLogAtLevel(WebFoundationLogDiskCacheActivity, @"- [WEBFOUNDATION_DEBUG] - fs read disk cache file - %@", path);
+        }
+#endif
+        return self;
+    }
+    else {
+#ifdef WEBFOUNDATION_DEBUG
+        WebFoundationLogAtLevel(WebFoundationLogDiskCacheActivity, @"- [WEBFOUNDATION_DEBUG] - no disk cache file - %@", path);
+#endif
+        [self dealloc];
+        return nil;
+    }
+}
+
+- (NSData *)data
+{
+    return data;
+}
+
+- (void)dealloc
+{
+    if (mappedBytes) {
+        munmap(mappedBytes, mappedLength); 
+    }
+    
+    [data release];
+    
+    [super dealloc];
+}
+
+ at end
+
 // interface IFURLFileDatabaseOp -------------------------------------------------------------
 
 @interface IFURLFileDatabaseOp : NSObject
@@ -242,11 +382,13 @@ enum
     id fileKey;
     id object;
     NSString *filePath;
+    IFURLFileReader *fileReader;
     NSData *data;
     NSUnarchiver *unarchiver;
         
     result = nil;
     fileKey = nil;
+    fileReader = nil;
     data = nil;
     unarchiver = nil;
 
@@ -265,16 +407,13 @@ enum
     [mutex unlock];
 
     // go to disk
-    filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
-
+    filePath = [[NSString alloc] initWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
+    fileReader = [[IFURLFileReader alloc] initWithPath:filePath];
+    if (fileReader && (data = [fileReader data])) {
+        unarchiver = [[NSUnarchiver alloc] initForReadingWithData:data];
+    }
+    
     NS_DURING
-        data = [[NSData alloc] initWithContentsOfMappedFile:filePath];
-        if (!data) {
-            data = [[NSData alloc] initWithContentsOfFile:filePath];
-        }
-        if (data) {
-            unarchiver = [[NSUnarchiver alloc] initForReadingWithData:data];
-        }
         if (unarchiver) {
             fileKey = [unarchiver decodeObject];
             object = [unarchiver decodeObject];
@@ -292,7 +431,8 @@ enum
     NS_ENDHANDLER
 
     [unarchiver release];
-    [data release];
+    [fileReader release];
+    [filePath release];
 
     return result;
 }
@@ -341,7 +481,7 @@ enum
 
     defaultManager = [NSFileManager defaultManager];
 
-    filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
+    filePath = [[NSString alloc] initWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
 
     result = [defaultManager createFileAtPath:filePath contents:data attributes:attributes];
     if (!result) {
@@ -349,20 +489,20 @@ enum
     }
 
     [archiver release];
+    [filePath release];
 }
 
 -(void)performRemoveObjectForKey:(id)key
 {
     NSString *filePath;
 
-
 #ifdef WEBFOUNDATION_DEBUG
     WebFoundationLogAtLevel(WebFoundationLogDiskCacheActivity, @"- [WEBFOUNDATION_DEBUG] - performRemoveObjectForKey - %@", key);
 #endif
 
-    filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
-
+    filePath = [[NSString alloc] initWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
     [[NSFileManager defaultManager] removeFileAtPath:filePath handler:nil];
+    [filePath release];
 }
 
 // database management functions ---------------------------------------------------------------------------

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list