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;
|
package com.threerings.resource;
|
||||||
|
|
||||||
@@ -116,14 +116,24 @@ public abstract class Downloader
|
|||||||
// info on potentially partially downloaded data; if so, use a
|
// info on potentially partially downloaded data; if so, use a
|
||||||
// "Range: bytes=HAVE-" header.
|
// "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
|
// read in the file data
|
||||||
while ((read = in.read(buffer)) != -1) {
|
while ((read = in.read(buffer)) != -1) {
|
||||||
// write it out to our local copy
|
// write it out to our local copy
|
||||||
out.write(buffer, 0, read);
|
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
|
// 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
|
// update our percent completion; if we're totally done, hold
|
||||||
// off on notifying the observer until the download manager
|
// off on notifying the observer until the download manager
|
||||||
@@ -157,6 +167,9 @@ public abstract class Downloader
|
|||||||
/** The descriptor that we're downloading. */
|
/** The descriptor that we're downloading. */
|
||||||
protected DownloadDescriptor _desc;
|
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
|
/** The last-modified difference in milliseconds allowed between the
|
||||||
* source and destination file without considering the destination
|
* source and destination file without considering the destination
|
||||||
* file to be out of date. */
|
* 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;
|
package com.threerings.resource;
|
||||||
|
|
||||||
@@ -17,12 +17,12 @@ public class FileDownloader extends Downloader
|
|||||||
{
|
{
|
||||||
// read the file information directly from the file system
|
// read the file information directly from the file system
|
||||||
File tfile = new File(_desc.sourceURL.getPath());
|
File tfile = new File(_desc.sourceURL.getPath());
|
||||||
long fileSize = tfile.length();
|
_contentLength = tfile.length();
|
||||||
_desc.lastModified = tfile.lastModified();
|
_desc.lastModified = tfile.lastModified();
|
||||||
|
|
||||||
if (compareWithLocal(fileSize, _desc.lastModified)) {
|
if (compareWithLocal(_contentLength, _desc.lastModified)) {
|
||||||
// increment the total file size to be fetched
|
// increment the total file size to be fetched
|
||||||
info.totalSize += fileSize;
|
info.totalSize += _contentLength;
|
||||||
Log.debug("File deemed stale [url=" + _desc.sourceURL + "].");
|
Log.debug("File deemed stale [url=" + _desc.sourceURL + "].");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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;
|
package com.threerings.resource;
|
||||||
|
|
||||||
@@ -95,13 +95,18 @@ public class JNLPDownloader extends Downloader
|
|||||||
throw new IOException(errmsg);
|
throw new IOException(errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're versioning, we know we need an update; force the
|
// determine our content length
|
||||||
// content length to be at least 1 so that we behave marginally
|
_contentLength = ucon.getContentLength();
|
||||||
// sensibly (ticking off each file as we download it) if our
|
if (_contentLength > 0) {
|
||||||
// server doesn't provide content-length for some assinine reason
|
// and record it to the total size if it is a sane value
|
||||||
int cl = Math.max(ucon.getContentLength(), 1);
|
info.totalSize += _contentLength;
|
||||||
info.totalSize += cl;
|
} else {
|
||||||
Log.info(getResourceURL() + " requires " + cl + " byte update.");
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user