mirror of https://github.com/zlatinb/muwire
fix browsing failures when requests return no files or folders
parent
3fa4eed3cc
commit
a3e2bc8d23
|
@ -123,10 +123,12 @@ class BrowseManager {
|
|||
JsonOutput jsonOutput = new JsonOutput()
|
||||
def baos = new ByteArrayOutputStream()
|
||||
def dos = new DataOutputStream(new GZIPOutputStream(baos))
|
||||
if (count > 0) {
|
||||
writeFiles(topLevelItems.files.values(), dos, jsonOutput)
|
||||
writeDirs(topLevelItems.dirs, dos, jsonOutput)
|
||||
dos.close()
|
||||
os.write(baos.toByteArray())
|
||||
}
|
||||
os.flush()
|
||||
|
||||
InputStream is = endpoint.getInputStream()
|
||||
|
@ -168,19 +170,21 @@ class BrowseManager {
|
|||
def cb = new PathCallback()
|
||||
tempTree.traverse(requestedPath, cb)
|
||||
filesToWrite = cb.files
|
||||
dirsToWrite = Collections.emptySet()
|
||||
dirsToWrite = cb.dirs
|
||||
}
|
||||
filesToWrite.each {it.hit(browser, System.currentTimeMillis(), "Browse Host")}
|
||||
os.write("Files:${filesToWrite.size()}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
os.write("Dirs:${dirsToWrite.size()}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
os.write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
|
||||
if (filesToWrite.size() + dirsToWrite.size() > 0) {
|
||||
baos = new ByteArrayOutputStream()
|
||||
dos = new DataOutputStream(new GZIPOutputStream(baos))
|
||||
writeFiles(filesToWrite, dos, jsonOutput)
|
||||
writeDirs(dirsToWrite, dos, jsonOutput)
|
||||
dos.close()
|
||||
os.write(baos.toByteArray())
|
||||
}
|
||||
os.flush()
|
||||
}
|
||||
}
|
||||
|
@ -239,9 +243,14 @@ class BrowseManager {
|
|||
private static class PathCallback implements PathTreeCallback<BrowsedFile, BrowsedFolder> {
|
||||
|
||||
final Set<SharedFile> files = new HashSet<>()
|
||||
final Set<Path> dirs = new HashSet<>()
|
||||
|
||||
@Override
|
||||
void onDirectoryEnter(Path path, BrowsedFolder value) {
|
||||
if (!value.sent) {
|
||||
value.sent = true
|
||||
dirs.add(value.path)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -136,6 +136,7 @@ class BrowseSession implements Runnable {
|
|||
if (!headers.containsKey("Dirs"))
|
||||
throw new Exception("Dirs header missing")
|
||||
int dirs = Integer.parseInt(headers['Dirs'])
|
||||
if (files + dirs > 0) {
|
||||
eventBus.publish(new BrowseStatusEvent(host: event.host, status: BrowseStatus.FETCHING,
|
||||
totalResults: results, currentItems: (files + dirs), uuid: uuid))
|
||||
log.info("starting to fetch ${files} files and ${dirs} dirs with uuid $uuid")
|
||||
|
@ -176,8 +177,8 @@ class BrowseSession implements Runnable {
|
|||
path: path.toArray(new String[0]))
|
||||
eventBus.publish(event)
|
||||
}
|
||||
eventBus.publish(new BrowseStatusEvent(host: event.host, status : BrowseStatus.FINISHED, uuid : uuid))
|
||||
|
||||
eventBus.publish(new BrowseStatusEvent(host: event.host, status: BrowseStatus.FINISHED, uuid: uuid))
|
||||
}
|
||||
while(true) {
|
||||
Request nextPath = fetchQueue.poll(PING_INTERVAL, TimeUnit.MILLISECONDS)
|
||||
if (nextPath == null) {
|
||||
|
|
|
@ -37,6 +37,7 @@ class ResultTreeModel extends DefaultTreeModel {
|
|||
node = elementNode
|
||||
}
|
||||
|
||||
if (node.getChildCount() == 0)
|
||||
node.addDescendant(new PlaceholderNode())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue