Alas, such a simple fix isn't going to do the job. We need to be smarter
about handling resources that didn't provide a content length. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3030 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Downloader.java,v 1.3 2004/03/06 11:29:19 mdb Exp $
|
||||
// $Id: Downloader.java,v 1.4 2004/06/16 09:44:23 mdb Exp $
|
||||
|
||||
package com.threerings.resource;
|
||||
|
||||
@@ -116,14 +116,24 @@ public abstract class Downloader
|
||||
// info on potentially partially downloaded data; if so, use a
|
||||
// "Range: bytes=HAVE-" header.
|
||||
|
||||
// if we were unable to determine our content length, record a
|
||||
// single "byte" of progress to indicate that we've started to
|
||||
// download this file
|
||||
if (_contentLength <= 0) {
|
||||
pinfo.currentSize += 1;
|
||||
}
|
||||
|
||||
// read in the file data
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
// write it out to our local copy
|
||||
out.write(buffer, 0, read);
|
||||
|
||||
// report our progress to the download observer as a
|
||||
// if we know we added something to the total download size,
|
||||
// then report our progress to the download observer as a
|
||||
// percentage of the total file data to be transferred
|
||||
pinfo.currentSize += read;
|
||||
if (_contentLength > 0) {
|
||||
pinfo.currentSize += read;
|
||||
}
|
||||
|
||||
// update our percent completion; if we're totally done, hold
|
||||
// off on notifying the observer until the download manager
|
||||
@@ -157,6 +167,9 @@ public abstract class Downloader
|
||||
/** The descriptor that we're downloading. */
|
||||
protected DownloadDescriptor _desc;
|
||||
|
||||
/** We need this to cope gracefully with a missing content-length. */
|
||||
protected long _contentLength;
|
||||
|
||||
/** The last-modified difference in milliseconds allowed between the
|
||||
* source and destination file without considering the destination
|
||||
* file to be out of date. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: FileDownloader.java,v 1.1 2003/08/05 01:33:20 mdb Exp $
|
||||
// $Id: FileDownloader.java,v 1.2 2004/06/16 09:44:23 mdb Exp $
|
||||
|
||||
package com.threerings.resource;
|
||||
|
||||
@@ -17,12 +17,12 @@ public class FileDownloader extends Downloader
|
||||
{
|
||||
// read the file information directly from the file system
|
||||
File tfile = new File(_desc.sourceURL.getPath());
|
||||
long fileSize = tfile.length();
|
||||
_contentLength = tfile.length();
|
||||
_desc.lastModified = tfile.lastModified();
|
||||
|
||||
if (compareWithLocal(fileSize, _desc.lastModified)) {
|
||||
if (compareWithLocal(_contentLength, _desc.lastModified)) {
|
||||
// increment the total file size to be fetched
|
||||
info.totalSize += fileSize;
|
||||
info.totalSize += _contentLength;
|
||||
Log.debug("File deemed stale [url=" + _desc.sourceURL + "].");
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: JNLPDownloader.java,v 1.17 2004/06/16 09:25:52 mdb Exp $
|
||||
// $Id: JNLPDownloader.java,v 1.18 2004/06/16 09:44:23 mdb Exp $
|
||||
|
||||
package com.threerings.resource;
|
||||
|
||||
@@ -95,13 +95,18 @@ public class JNLPDownloader extends Downloader
|
||||
throw new IOException(errmsg);
|
||||
}
|
||||
|
||||
// if we're versioning, we know we need an update; force the
|
||||
// content length to be at least 1 so that we behave marginally
|
||||
// sensibly (ticking off each file as we download it) if our
|
||||
// server doesn't provide content-length for some assinine reason
|
||||
int cl = Math.max(ucon.getContentLength(), 1);
|
||||
info.totalSize += cl;
|
||||
Log.info(getResourceURL() + " requires " + cl + " byte update.");
|
||||
// determine our content length
|
||||
_contentLength = ucon.getContentLength();
|
||||
if (_contentLength > 0) {
|
||||
// and record it to the total size if it is a sane value
|
||||
info.totalSize += _contentLength;
|
||||
} else {
|
||||
// if it's not sane, record a single byte which we will then
|
||||
// properly interepret later during actual downloading
|
||||
info.totalSize += 1;
|
||||
}
|
||||
Log.info(getResourceURL() + " requires " + _contentLength +
|
||||
" byte update.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user