Changeset 232

Show
Ignore:
Timestamp:
02/07/07 00:17:30 (2 years ago)
Author:
Alan Knowles
Message:

Add Directory Caching - we need this on slow filesystems, however, it would be better to have it as a configurable setting... - something like - Directory::addSlowPaths(String[] list)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/language/d/Directory.d

    r189 r232  
    4646    // lookups. 
    4747     
     48    /** 
     49     * Directory caching - this is needed for slow file systems (eg. davfs mounts) 
     50     *  
     51     * It should really be configurable! 
     52     * FIXME: // make this configurable.... 
     53     */ 
    4854      
     55    static bool[char[]] checkPaths; 
     56    static bool[char[]] checkPathsFile; 
     57    static ulong[char[]] checkPathsExpire; 
     58    static String[][char[]] directoryCache; 
     59    static ulong[char[]] directoryCacheExpire; 
    4960     
    50       
     61    static String[] listDirCached(char[] path) 
     62    { 
     63        if ((path in directoryCacheExpire) && (std.date.getUTCtime() < directoryCacheExpire[path])) { 
     64            return directoryCache[path]; 
     65        } 
     66        //writefln("DirCache %s expired", path); 
     67        directoryCache[path] = Path.listDir(path); 
     68        directoryCacheExpire[path] = std.date.getUTCtime() + (60 * 5* 1000); // 5 minutes? 
     69        return directoryCache[path]; 
     70         
     71    } 
     72     
     73    static bool checkPathIsDir(String pathS) 
     74    { 
     75        char[] path = pathS.toString(); 
     76        if ((path in checkPaths) &&  
     77            (path in checkPathsExpire) &&  
     78            (std.date.getUTCtime() < checkPathsExpire[path])) { 
     79            return checkPaths[path]; 
     80        } 
     81        if (Path.exists(new String(path)) && Path.isDir(new String(path))) { 
     82            checkPaths[path] = true; 
     83        } else { 
     84            checkPaths[path] = false; 
     85        } 
     86        writefln("checkPathIsDir %s expired %d < %d", path, std.date.getUTCtime() ,  
     87            (path in checkPathsExpire) ? checkPathsExpire[path] : 0); 
     88        checkPathsExpire[path] = std.date.getUTCtime() + (60 * 5 * 1000); // 5 minutes? 
     89        return checkPaths[path]; 
     90    } 
     91    static bool checkPathIsFile(String pathS) 
     92    { 
     93        char[] path = pathS.toString(); 
     94        if ((path in checkPathsFile) &&  
     95            (path in checkPathsExpire) &&  
     96            (std.date.getUTCtime() < checkPathsExpire[path])) { 
     97            return checkPathsFile[path]; 
     98        } 
     99        if (Path.exists(new String(path)) && !Path.isDir(new String(path))) { 
     100            checkPathsFile[path] = true; 
     101        } else { 
     102            checkPathsFile[path] = false; 
     103        } 
     104        //writefln("checkPathIsFile %s expired", path); 
     105        checkPathsExpire[path] = std.date.getUTCtime() + (60 * 5 * 1000); // 5 minutes? 
     106        return checkPathsFile[path]; 
     107    } 
    51108     
    52109 
    53110    void getAutoCompleteList(String start, inout String[] ret, bool parents = true, bool imports = true) 
    54111    { 
    55         String[] files = Path.listDir(this.name); 
     112        String[] files = listDirCached(this.name); 
    56113        foreach( file;files) { 
    57114            String check = new String(); 
     
    59116                continue; 
    60117            } 
    61             if (Path.isDir(Path.join(this.name, file))) { 
     118            if (checkPathIsDir(Path.join(this.name, file))) { 
    62119                check = file; 
    63120            } else if (Path.getExt(Path.join(this.name, file)) == "d") { 
     
    82139        String fp = Path.join(this.name, match); 
    83140         
    84         if (Path.exists(fp) && Path.isDir(fp)) { 
     141        if (checkPathIsDir(fp)) { 
    85142            writefln("Matched - returning new directory"); 
    86143            return new Directory(this, fp.toString()); 
    87144        } 
    88         if (Path.exists(fp~ ".d") && !Path.isDir(fp ~ ".d")) { 
     145        if (checkPathIsFile(fp ~ ".d")) { 
    89146            // it's a file!!! 
    90147            return new Directory(this, (fp ~ ".d").toString());