Incorporate a hash of the resource URL into the cache directory so that

bundles from one client installation don't overwrite bundles from another.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1827 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-10-25 17:21:00 +00:00
parent beca9850aa
commit fd44620d57
@@ -1,5 +1,5 @@
// //
// $Id: ResourceManager.java,v 1.16 2002/09/30 09:36:22 shaper Exp $ // $Id: ResourceManager.java,v 1.17 2002/10/25 17:21:00 mdb Exp $
package com.threerings.resource; package com.threerings.resource;
@@ -320,31 +320,46 @@ public class ResourceManager
* @return true if the directory was successfully created (or was * @return true if the directory was successfully created (or was
* already there), false if we failed to create it. * already there), false if we failed to create it.
*/ */
protected boolean createCacheDirectory (String setName) protected boolean createCacheDirectory (URL resourceURL, String setName)
{ {
// get the path to the top-level cache directory if we don't // get the path to the top-level cache directory if we don't
// already have it // already have it
if (_cachePath == null) { if (_cachePath == null) {
try { try {
// first check for an explicitly specified cache directory // first check for an explicitly specified cache directory
String dir = System.getProperty("rsrc_cache_dir"); _cachePath = System.getProperty("rsrc_cache_dir");
// if that's null, try putting it into their home directory // if that's null, try putting it into their home directory
if (dir == null) { if (_cachePath == null) {
dir = System.getProperty("user.home") + _cachePath = System.getProperty("user.home");
File.separator + CACHE_PATH;
} }
_cachePath = (dir + File.separator); _cachePath += File.separator;
} catch (SecurityException se) { } catch (SecurityException se) {
Log.info("Can't obtain user.home system property. Probably " + Log.info("Can't obtain user.home system property. Probably " +
"won't be able to create our cache directory " + "won't be able to create our cache directory " +
"either. [error=" + se + "]."); "either. [error=" + se + "].");
_cachePath = ""; _cachePath = "";
} }
}
// make sure the main cache directory exists // create our directories one at a time: first the top-level
if (!createDirectory(_cachePath)) { // cache directory
return false; _cachePath += CACHE_PATH + File.separator;
if (!createDirectory(_cachePath)) {
return false;
}
// next incorporate the resource URL into the cache path so
// that files fetched from different resource roots do not
// overwrite one another
_cachePath +=
StringUtil.md5hex(resourceURL.toString()) + File.separator;
if (!createDirectory(_cachePath)) {
return false;
}
Log.debug("Generated cache path '" + _cachePath + "' from " +
"root '" + _rootPath + "'.");
} }
// ensure that the set-specific cache directory exists // ensure that the set-specific cache directory exists
@@ -381,7 +396,8 @@ public class ResourceManager
* Generates the name of the bundle cache file given the name of the * Generates the name of the bundle cache file given the name of the
* resource set to which it belongs and the relative path URL. * resource set to which it belongs and the relative path URL.
*/ */
protected String genCachePath (String setName, String resourcePath) protected String genCachePath (
URL resourceURL, String setName, String resourcePath)
{ {
return _cachePath + setName + File.separator + return _cachePath + setName + File.separator +
StringUtil.replace(resourcePath, "/", "-"); StringUtil.replace(resourcePath, "/", "-");
@@ -405,10 +421,10 @@ public class ResourceManager
burl = new URL(resourceURL, path); burl = new URL(resourceURL, path);
// make sure the cache directory exists for this set // make sure the cache directory exists for this set
createCacheDirectory(setName); createCacheDirectory(resourceURL, setName);
// compute the path to the cache file for this bundle // compute the path to the cache file for this bundle
File cfile = new File(genCachePath(setName, path)); File cfile = new File(genCachePath(resourceURL, setName, path));
// slap this on the list for retrieval or update by the // slap this on the list for retrieval or update by the
// download manager // download manager