You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jo...@apache.org on 2002/12/30 20:54:52 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader FileResourceLoader.java
jon 2002/12/30 11:54:52
Modified: src/java/org/apache/velocity/runtime/resource/loader
FileResourceLoader.java
Log:
applied patch...
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15717
Revision Changes Path
1.18 +49 -15 jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
Index: FileResourceLoader.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FileResourceLoader.java 10 Oct 2002 18:09:10 -0000 1.17
+++ FileResourceLoader.java 30 Dec 2002 19:54:52 -0000 1.18
@@ -222,27 +222,61 @@
/**
* How to keep track of all the modified times
- * across the paths.
+ * across the paths. Note that a file might have
+ * appeared in a directory which is earlier in the
+ * path; so we should search the path and see if
+ * the file we find that way is the same as the one
+ * that we have cached.
*/
public boolean isSourceModified(Resource resource)
{
- String path = (String) templatePaths.get(resource.getName());
- File file = new File( path, resource.getName() );
-
- if ( file.canRead() )
+ /*
+ * we assume that the file needs to be reloaded;
+ * if we find the original file and it's unchanged,
+ * then we'll flip this.
+ */
+ boolean modified = true;
+
+ String fileName = resource.getName();
+ String path = (String) templatePaths.get(fileName);
+ File currentFile = null;
+
+ for (int i = 0; currentFile == null && i < paths.size(); i++)
+ {
+ String testPath = (String) paths.get(i);
+ File testFile = new File(testPath, fileName);
+ if (testFile.canRead())
+ {
+ currentFile = testFile;
+ }
+ }
+ File file = new File(path, fileName);
+ if (currentFile == null || !file.exists())
+ {
+ /*
+ * noop: if the file is missing now (either the cached
+ * file is gone, or the file can no longer be found)
+ * then we leave modified alone (it's set to true); a
+ * reload attempt will be done, which will either use
+ * a new template or fail with an appropriate message
+ * about how the file couldn't be found.
+ */
+ }
+ else if (currentFile.equals(file) && file.canRead())
{
- return (file.lastModified() != resource.getLastModified());
+ /*
+ * if only if currentFile is the same as file and
+ * file.lastModified() is the same as
+ * resource.getLastModified(), then we should use the
+ * cached version.
+ */
+ modified = (file.lastModified() != resource.getLastModified());
}
-
+
/*
- * If the file is now unreadable, or it has
- * just plain disappeared then we'll just say
- * that it's modified :-) When the loader attempts
- * to load the stream it will fail and the error
- * will be reported then.
+ * rsvc.debug("isSourceModified for " + fileName + ": " + modified);
*/
-
- return true;
+ return modified;
}
public long getLastModified(Resource resource)
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>