Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

modified dir servlet to cooperate with intranet indexing from the own HTDOCS repository: - removed md5 file generation (spoils the won repository) - removed comments in file share (was never used) - moved dir list comparator to other place (maybe solves problem, lets see)

orbiterff5969901c12
diff --git a/htroot/htdocsdefault/dir.html b/htroot/htdocsdefault/dir.html
index 2cdeeb1fb..2f5b1b67f 100644
--- a/htroot/htdocsdefault/dir.html
+++ b/htroot/htdocsdefault/dir.html
@@ -107,7 +107,6 @@
Resource = 
<input type="hidden" name="action" value="upload">
<input type="file" name="file" size="10" class="small"><br>
- Description&nbsp;=&nbsp;<input type="text" name="description" size="30" class="small"><br>
Indexing&nbsp;:&nbsp;<input type="checkbox" name="indexing" checked><br>
<input type="submit" value="Transfer" class="small">
</form>
diff --git a/htroot/htdocsdefault/dir.java b/htroot/htdocsdefault/dir.java
index 8af7defa9..b03c92dae 100644
--- a/htroot/htdocsdefault/dir.java
+++ b/htroot/htdocsdefault/dir.java
@@ -31,7 +31,6 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
@@ -53,6 +52,7 @@ import de.anomic.server.serverMemory;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.logging.serverLog;
+import de.anomic.server.serverFileUtils.dirlistComparator;
import de.anomic.tools.md5DirFileFilter;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed;
@@ -146,23 +146,20 @@ public class dir {
switchboard.setConfig("uploadAccountBase64MD5", (post.get("password", "").length() == 0) ? "" : serverCodings.encodeMD5Hex(kelondroBase64Order.standardCoder.encodeString("upload:" + post.get("password", ""))));
} else if (action.equals("upload") && (uploadAuthorization || adminAuthorization)) {
String filename = new File(post.get("file", "dummy")).getName();
- String description = post.get("description", "");
pos = filename.lastIndexOf("\\");
if (pos >= 0) { filename = filename.substring(pos + 1); }
final File newfile = new File(dir, filename);
- final File newfilemd5 = new File(dir, filename + ".md5");
final byte[] binary = (byte[]) post.get("file$file", new byte[0]);
try {
serverFileUtils.write(binary, newfile);
byte[] md5 = serverCodings.encodeMD5Raw(newfile);
String md5s = serverCodings.encodeHex(md5);
- serverFileUtils.write((md5s + "\n" + description).getBytes("UTF-8"), newfilemd5); // generate md5
-
+
// index file info
if (post.get("indexing", "").equals("on")) {
final String urlstring = yacyhURL(yacyCore.seedDB.mySeed(), filename, md5s);
final String phrase = filename.replace('.', ' ').replace('_', ' ').replace('-', ' ');
- indexPhrase(switchboard, urlstring, phrase, description, md5);
+ indexPhrase(switchboard, urlstring, phrase, "", md5);
}
} catch (IOException e) {}
} else if (action.equals("newdir") && (uploadAuthorization || adminAuthorization)) {
@@ -175,18 +172,6 @@ public class dir {
String filename = post.get("file", "foo");
final File file = new File(dir, filename);
if (file.exists()) {
- final File filemd5 = new File(dir, post.get("file", "foo") + ".md5");
- // read md5 and phrase
- String md5s = "";
- String description = "";
- if (filemd5.exists()) try {
- md5s = new String(serverFileUtils.read(filemd5));
- pos = md5s.indexOf('\n');
- if (pos >= 0) {
- description = md5s.substring(pos + 1);
- md5s = md5s.substring(0, pos);
- }
- } catch (IOException e) {}
// delete file(s)
if (file.isDirectory()) {
final String[] content = file.list();
@@ -194,12 +179,11 @@ public class dir {
file.delete();
} else if (file.isFile()) {
file.delete();
- if (filemd5.exists()) filemd5.delete();
}
// delete index
- final String urlstring = yacyhURL(yacyCore.seedDB.mySeed(), filename, md5s);
+ final String urlstring = yacyhURL(yacyCore.seedDB.mySeed(), filename, "");
final String phrase = filename.replace('.', ' ').replace('_', ' ').replace('-', ' ');
- deletePhrase(switchboard, urlstring, phrase, description);
+ deletePhrase(switchboard, urlstring, phrase, "");
}
}
@@ -207,13 +191,13 @@ public class dir {
if ((adminAuthorization) || (uploadAuthorization) || (downloadAuthorization)) {
// generate dir listing
md5DirFileFilter fileFilter = new md5DirFileFilter();
- final File[] list = dir.listFiles(fileFilter);
+ File[] list = dir.listFiles(fileFilter);
+ if (list == null) list = new File[0];
// sorting the dir list
dirlistComparator comparator = new dirlistComparator();
Arrays.sort(list, comparator);
- String md5s, description;
// tree += "<span class=\"tt\">path&nbsp;=&nbsp;" + path + "</span><br><br>";
if (list != null) {
int filecount = 0, fileIdx = 0;
@@ -231,31 +215,6 @@ public class dir {
dark = !dark;
- // reading the content of the md5 file that belongs
- // to the file
- File fmd5 = new File(dir, fileName + ".md5");
- try {
- if (fmd5.exists()) {
- md5s = new String(serverFileUtils.read(fmd5));
- pos = md5s.indexOf('\n');
- if (pos >= 0) {
- // the second line contains an optional description
- description = md5s.substring(pos + 1);
- // the first line contains the md5 sum of the file
- md5s = md5s.substring(0, pos);
- } else {
- description = "";
- }
- } else {
- // generate md5 on-the-fly
- md5s = serverCodings.encodeMD5Hex(f);
- description = "";
- serverFileUtils.write((md5s + "\n" + description).getBytes("UTF-8"), fmd5);
- }
- } catch (IOException e) {
- md5s = "";
- description = "";
- }
// last modification date if the entry
prop.put("dirlist_" + fileIdx + "_dir_date" , dateString(new Date(f.lastModified())));
@@ -273,6 +232,8 @@ public class dir {
boolean showImage = /* (description.length() == 0) && */ (fileName.endsWith(".jpg") || fileName.endsWith(".gif") || fileName.endsWith(".png") || fileName.endsWith(".ico") || fileName.endsWith(".bmp"));
// the entry is a file
+ String md5s = serverCodings.encodeMD5Hex(f);
+
prop.put("dirlist_" + fileIdx + "_dir" , "0");
// the file size
prop.put("dirlist_" + fileIdx + "_dir_size" , serverMemory.bytesToString(f.length()));
@@ -288,7 +249,7 @@ public class dir {
prop.putHTML("dirlist_" + fileIdx + "_dir_descriptionMode_image",fileName);
}
// always set the description tag (needed by rss and xml)
- prop.putHTML("dirlist_" + fileIdx + "_dir_descriptionMode_text",description);
+ prop.putHTML("dirlist_" + fileIdx + "_dir_descriptionMode_text", "");
}
prop.put("dirlist_" + fileIdx + "_adminAuthorization",adminAuthorization ? "1" : "0");
@@ -389,17 +350,4 @@ public class dir {
}
}
- public static class dirlistComparator implements Comparator<File> {
-
- public int compare(File file1, File file2) {
- if (file1.isDirectory() && !file2.isDirectory()) {
- return -1;
- } else if (!file1.isDirectory() && file2.isDirectory()) {
- return 1;
- } else {
- return file1.getName().compareToIgnoreCase(file2.getName());
- }
- }
-
- }
}
diff --git a/htroot/htdocsdefault/dir.rss b/htroot/htdocsdefault/dir.rss
index 25e226085..93fdb8b6d 100644
--- a/htroot/htdocsdefault/dir.rss
+++ b/htroot/htdocsdefault/dir.rss
@@ -14,7 +14,6 @@
<link>#(dir)##[URL]#::#[URL]##(/dir)#</link>
<pubDate>#(dir)##[rfc822date]#::#[rfc822date]##(/dir)#</pubDate>
#(dir)#<guid>#[md5s]#</guid>::#(/dir)#
- #(dir)#<description><![CDATA[#(descriptionMode)##[text]#::#[text]##(/descriptionMode)#]]></description>::#(/dir)#
<category><![CDATA[#(dir)#File::Directory#(/dir)#]]></category>
</item>#{/dirlist}#
</channel>
diff --git a/htroot/htdocsdefault/dir.xml b/htroot/htdocsdefault/dir.xml
index 4615afd84..d22cf64f4 100644
--- a/htroot/htdocsdefault/dir.xml
+++ b/htroot/htdocsdefault/dir.xml
@@ -7,7 +7,6 @@
<date timestamp="#[timestamp]#">#[date]#</date>
<size bytes="#[sizeBytes]#">#[size]#</size>
<md5>#[md5s]#</md5>
- <comment>#(descriptionMode)##[text]#::#[text]##(/descriptionMode)#</comment>
<yacyURL>#[yacyhURL]#</yacyURL>
</file>
::
diff --git a/source/de/anomic/plasma/plasmaCrawlBalancer.java b/source/de/anomic/plasma/plasmaCrawlBalancer.java
index c64af7c18..960765c53 100644
--- a/source/de/anomic/plasma/plasmaCrawlBalancer.java
+++ b/source/de/anomic/plasma/plasmaCrawlBalancer.java
@@ -155,7 +155,8 @@ public class plasmaCrawlBalancer {
}
public synchronized plasmaCrawlEntry get(String urlhash) throws IOException {
- kelondroRow.Entry entry = urlFileIndex.get(urlhash.getBytes());
+ assert urlhash != null;
+ kelondroRow.Entry entry = urlFileIndex.get(urlhash.getBytes());
if (entry == null) return null;
return new plasmaCrawlEntry(entry);
}
diff --git a/source/de/anomic/server/serverCodings.java b/source/de/anomic/server/serverCodings.java
index f4ae5f629..28bb54900 100644
--- a/source/de/anomic/server/serverCodings.java
+++ b/source/de/anomic/server/serverCodings.java
@@ -138,6 +138,7 @@ public final class serverCodings {
System.out.println("Internal Error at md5:" + e.getMessage());
} catch (java.io.FileNotFoundException e) {
System.out.println("file not found:" + file.toString());
+ e.printStackTrace();
} catch (java.io.IOException e) {
System.out.println("file error with " + file.toString() + ": " + e.getMessage());
}
diff --git a/source/de/anomic/server/serverFileUtils.java b/source/de/anomic/server/serverFileUtils.java
index b14fe4c59..bf1ff0fe6 100644
--- a/source/de/anomic/server/serverFileUtils.java
+++ b/source/de/anomic/server/serverFileUtils.java
@@ -54,6 +54,7 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -483,6 +484,20 @@ public final class serverFileUtils {
String[] list = from_dir.list();
for (int i = 0; i < list.length; i++) (new File(from_dir, list[i])).renameTo(new File(to_dir, list[i]));
}
+
+
+ public static class dirlistComparator implements Comparator<File> {
+
+ public int compare(File file1, File file2) {
+ if (file1.isDirectory() && !file2.isDirectory()) {
+ return -1;
+ } else if (!file1.isDirectory() && file2.isDirectory()) {
+ return 1;
+ } else {
+ return file1.getName().compareToIgnoreCase(file2.getName());
+ }
+ }
+ }
public static void main(String[] args) {
try {
diff --git a/source/de/anomic/ymage/ymageOSM.java b/source/de/anomic/ymage/ymageOSM.java
index 4eaa575ad..80bd1a3d2 100644
--- a/source/de/anomic/ymage/ymageOSM.java
+++ b/source/de/anomic/ymage/ymageOSM.java
@@ -28,6 +28,7 @@ package de.anomic.ymage;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -83,6 +84,8 @@ public class ymageOSM {
}
try {
return ImageIO.read(tileStream);
+ } catch (EOFException e) {
+ return null;
} catch (IOException e) {
return null;
}