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))
|
||||
writeFiles(topLevelItems.files.values(), dos, jsonOutput)
|
||||
writeDirs(topLevelItems.dirs, dos, jsonOutput)
|
||||
dos.close()
|
||||
os.write(baos.toByteArray())
|
||||
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))
|
||||
|
||||
baos = new ByteArrayOutputStream()
|
||||
dos = new DataOutputStream(new GZIPOutputStream(baos))
|
||||
writeFiles(filesToWrite, dos, jsonOutput)
|
||||
writeDirs(dirsToWrite, dos, jsonOutput)
|
||||
dos.close()
|
||||
os.write(baos.toByteArray())
|
||||
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,48 +136,49 @@ class BrowseSession implements Runnable {
|
|||
if (!headers.containsKey("Dirs"))
|
||||
throw new Exception("Dirs header missing")
|
||||
int dirs = Integer.parseInt(headers['Dirs'])
|
||||
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")
|
||||
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")
|
||||
|
||||
JsonSlurper slurper = new JsonSlurper()
|
||||
DataInputStream dis = new DataInputStream(new GZIPInputStream(is))
|
||||
UIResultEvent[] batch = new UIResultEvent[Math.min(BATCH_SIZE, files)]
|
||||
int j = 0
|
||||
for (int i = 0; i < files; i++) {
|
||||
if (closed)
|
||||
return
|
||||
log.fine("parsing result $i at batch position $j")
|
||||
JsonSlurper slurper = new JsonSlurper()
|
||||
DataInputStream dis = new DataInputStream(new GZIPInputStream(is))
|
||||
UIResultEvent[] batch = new UIResultEvent[Math.min(BATCH_SIZE, files)]
|
||||
int j = 0
|
||||
for (int i = 0; i < files; i++) {
|
||||
if (closed)
|
||||
return
|
||||
log.fine("parsing result $i at batch position $j")
|
||||
|
||||
def json = readJson(slurper, dis)
|
||||
UIResultEvent result = ResultsParser.parse(event.host, uuid, json)
|
||||
result.chat = chat
|
||||
result.profileHeader = profileHeader
|
||||
batch[j++] = result
|
||||
def json = readJson(slurper, dis)
|
||||
UIResultEvent result = ResultsParser.parse(event.host, uuid, json)
|
||||
result.chat = chat
|
||||
result.profileHeader = profileHeader
|
||||
batch[j++] = result
|
||||
|
||||
|
||||
// publish piecemally
|
||||
if (j == batch.length) {
|
||||
eventBus.publish(new UIResultBatchEvent(results: batch, uuid: uuid))
|
||||
j = 0
|
||||
batch = new UIResultEvent[Math.min(files - i - 1, BATCH_SIZE)]
|
||||
log.fine("publishing batch, next batch size ${batch.length}")
|
||||
// publish piecemally
|
||||
if (j == batch.length) {
|
||||
eventBus.publish(new UIResultBatchEvent(results: batch, uuid: uuid))
|
||||
j = 0
|
||||
batch = new UIResultEvent[Math.min(files - i - 1, BATCH_SIZE)]
|
||||
log.fine("publishing batch, next batch size ${batch.length}")
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < dirs; i++) {
|
||||
if (closed)
|
||||
return
|
||||
for (int i = 0; i < dirs; i++) {
|
||||
if (closed)
|
||||
return
|
||||
|
||||
def json = readJson(slurper, dis)
|
||||
if (!json.directory || json.path == null)
|
||||
throw new Exception("Invalid dir json")
|
||||
List<String> path = json.path.collect { DataUtil.readi18nString(Base64.decode(it)) }
|
||||
def event = new UIBrowseDirEvent(uuid: uuid,
|
||||
path: path.toArray(new String[0]))
|
||||
eventBus.publish(event)
|
||||
def json = readJson(slurper, dis)
|
||||
if (!json.directory || json.path == null)
|
||||
throw new Exception("Invalid dir json")
|
||||
List<String> path = json.path.collect { DataUtil.readi18nString(Base64.decode(it)) }
|
||||
def event = new UIBrowseDirEvent(uuid: uuid,
|
||||
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,7 +37,8 @@ class ResultTreeModel extends DefaultTreeModel {
|
|||
node = elementNode
|
||||
}
|
||||
|
||||
node.addDescendant(new PlaceholderNode())
|
||||
if (node.getChildCount() == 0)
|
||||
node.addDescendant(new PlaceholderNode())
|
||||
}
|
||||
|
||||
void addToTree(UIResultEvent event) {
|
||||
|
|
Loading…
Reference in New Issue