Skip to content

Commit

Permalink
Bugfix for getCachePath(URL url)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1909 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
borg-0300 committed Mar 17, 2006
1 parent 303b646 commit 5f6fdf1
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions source/de/anomic/plasma/plasmaHTCache.java
Expand Up @@ -99,13 +99,12 @@ public plasmaHTCache(File htCachePath, long maxCacheSize, int bufferkb) {

this.log = new serverLog("HTCACHE");
this.cachePath = htCachePath;
this.maxCacheSize = maxCacheSize;

// reset old HTCache ?
final String[] list = cachePath.list();
if (list != null) {
File object;
for (int i = list.length - 1; i >= 0 ; i--) {
for (int i = list.length - 1; i >= 0; i--) {
object = new File(cachePath, list[i]);
if (object.isDirectory()) {
if (!object.getName().equals("http") &&
Expand All @@ -129,7 +128,7 @@ public plasmaHTCache(File htCachePath, long maxCacheSize, int bufferkb) {
this.log.logSevere("the cache path " + htCachePath.toString() + " is not a directory or does not exists and cannot be created");
System.exit(0);
}

// open the response header database
File dbfile = new File(this.cachePath, "responseHeader.db");
try {
Expand Down Expand Up @@ -174,21 +173,21 @@ private void deleteOldHTCache(File directory) {
public int size() {
synchronized (this.cacheStack) {
return this.cacheStack.size();
}
}
}

public int dbSize() {
return this.responseHeaderDB.size();
return this.responseHeaderDB.size();
}

public int[] dbCacheChunkSize() {
return this.responseHeaderDB.cacheChunkSize();
}

public int[] dbCacheFillStatus() {
return this.responseHeaderDB.cacheFillStatus();
}

public void push(Entry entry) {
synchronized (this.cacheStack) {
this.cacheStack.add(entry);
Expand Down Expand Up @@ -254,11 +253,11 @@ public void writeFileAnnouncement(File file) {
}
}

public boolean deleteFile(URL url) {
return deleteURLfromCache(url, "FROM");
public boolean deleteFile(URL url) {
return deleteURLfromCache(url, "FROM");
}
private boolean deleteURLfromCache (URL url, String msg) {

private boolean deleteURLfromCache(URL url, String msg) {
if (deleteFileandDirs(getCachePath(url), msg)) {
try {
// As the file is gone, the entry in responseHeader.db is not needed anymore
Expand All @@ -270,8 +269,8 @@ private boolean deleteURLfromCache (URL url, String msg) {
return true;
}
return false;
}
}

private boolean deleteFile(File obj) {
if (obj.exists() && !filesInUse.contains(obj)) {
long size = obj.length();
Expand Down Expand Up @@ -375,7 +374,7 @@ public void cacheScan() {
cleanup();

log.logConfig("STARTING DNS PREFETCH");
// start to prefetch IPs from DNS
// start to prefetch IPs from DNS
String dom;
long start = System.currentTimeMillis();
String result = "";
Expand Down Expand Up @@ -520,7 +519,7 @@ public static boolean noIndexingURL(String urlString) {
* it will also be ensured, that the complete path exists; if necessary
* that path will be generated
* @return new File
*/
*/
public File getCachePath(URL url) {
// this.log.logFinest("plasmaHTCache: getCachePath: IN=" + url.toString());
String path = url.getPath();
Expand All @@ -534,14 +533,23 @@ public File getCachePath(URL url) {
path = matcher.replaceAll("/!!/");
matcher.reset(path);
}
if (path != null) {
// yes this is not reversible, but that is not needed
searchPattern = Pattern.compile("(\"|\\\\|\\*|\\?|:|<|>|\\|)");
matcher = searchPattern.matcher(path);
while (matcher.find()) {
path = matcher.replaceAll("_");
matcher.reset(path);
}
}
if (query != null) {
// yes this is not reversible, but that is not needed
searchPattern = Pattern.compile("(\"|\\\\|\\*|\\?|/|:|<|>|\\|)");
matcher = searchPattern.matcher(query);
while (matcher.find()) {
query = matcher.replaceAll("_");
matcher.reset(query);
}
}
path = path.concat("_").concat(query);
}
// only set NO default ports
Expand Down Expand Up @@ -664,6 +672,8 @@ public Entry newEntry(Date initDate, int depth, URL url, String name,

public final class Entry {

public static final int MAXLENGTH = 255;

// the class objects
public Date initDate; // the date when the request happened; will be used as a key
public int depth; // the depth of prefetching
Expand Down Expand Up @@ -696,7 +706,7 @@ protected Object clone() throws CloneNotSupportedException {
this.profile
);
}

public Entry(Date initDate, int depth, URL url, String name,
httpHeader requestHeader,
String responseStatus, httpHeader responseHeader,
Expand Down Expand Up @@ -724,7 +734,7 @@ public Entry(Date initDate, int depth, URL url, String name,
this.responseStatus = responseStatus;
this.responseHeader = responseHeader;
this.profile = profile;
this.initiator = (initiator == null) ? null : ((initiator.length() == 0) ? null: initiator);
this.initiator = (initiator == null) ? null : ((initiator.length() == 0) ? null : initiator);

// calculated:
if (responseHeader == null) {
Expand All @@ -748,10 +758,10 @@ public Entry(Date initDate, int depth, URL url, String name,
// to be defined later:
this.cacheArray = null;
}

public String name() {
return this.name;
}
}
public String initiator() {
return this.initiator;
}
Expand Down Expand Up @@ -801,7 +811,7 @@ public String shallStoreCacheForProxy() {
// we cannot match that here in the cache file path and therefore omit writing into the cache
if (this.cacheFile.getParentFile().isFile() || this.cacheFile.isDirectory()) { return "path_ambiguous"; }
if (this.cacheFile.toString().indexOf("..") >= 0) { return "path_dangerous"; }
if (this.cacheFile.getAbsolutePath().length() > 250) { return "path too long"; }
if (this.cacheFile.getAbsolutePath().length() > MAXLENGTH) { return "path too long"; }

// -CGI access in request
// CGI access makes the page very individual, and therefore not usable in caches
Expand Down Expand Up @@ -948,7 +958,7 @@ public boolean shallUseCacheForProxy() {
if (expires != null) {
// System.out.println("EXPIRES-TEST: expires=" + expires + ", NOW=" + serverDate.correctedGMTDate() + ", url=" + url);
if (expires.before(new Date(serverDate.correctedUTCTime()))) { return false; }
}
}
Date lastModified = this.responseHeader.lastModified();
cacheControl = (String) this.responseHeader.get(httpHeader.CACHE_CONTROL);
if (cacheControl == null && lastModified == null && expires == null) { return false; }
Expand Down Expand Up @@ -980,7 +990,7 @@ public boolean shallUseCacheForProxy() {
// easy case
return false;
// } else if (cacheControl.startsWith("PUBLIC")) {
// // ok, do nothing
// // ok, do nothing
} else if (cacheControl.startsWith("MAX-AGE=")) {
// we need also the load date
if (date == null) { return false; }
Expand Down

0 comments on commit 5f6fdf1

Please sign in to comment.