[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...
Galder Zamarreno
galder.zamarreno at jboss.com
Thu Nov 16 12:24:46 EST 2006
User: gzamarreno
Date: 06/11/16 12:24:46
Modified: src/org/jboss/cache/loader FileCacheLoader.java
Log:
[JBCACHE-644] - When creating an FCL root location, check for any non portable characters throwing a warning. Checks '*' '<' '>' '|' '"' '?'
When storing attributes, check that the Fqn tree does not contain non portable characters. Checks '*' '<' '>' '|' '"' '?' and also '\' '/' and ':'
When storing attributes as well, check for entire path that could be bigger than 255 characters throwing a warning.
Revision Changes Path
1.23 +59 -1 JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FileCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- FileCacheLoader.java 26 Oct 2006 19:30:20 -0000 1.22
+++ FileCacheLoader.java 16 Nov 2006 17:24:46 -0000 1.23
@@ -18,12 +18,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
/**
* Simple file-based CacheLoader implementation. Nodes are directories, attributes of a node is a file in the directory
*
* @author Bela Ban
- * @version $Id: FileCacheLoader.java,v 1.22 2006/10/26 19:30:20 bstansberry Exp $
+ * @version $Id: FileCacheLoader.java,v 1.23 2006/11/16 17:24:46 gzamarreno Exp $
*/
public class FileCacheLoader extends AbstractCacheLoader
{
@@ -88,6 +90,11 @@
{
log.trace("Creating cache loader location " + root);
}
+
+ /* Before creating the root, check whether the path is character portable. Anything that comes after is part
+ of the fqn which is inspected later. */
+ isCharacterPortableLocation(root.getAbsolutePath());
+
boolean created = root.mkdirs();
if (!created)
{
@@ -354,6 +361,11 @@
File child = new File(f, DATA);
if (!child.exists())
{
+ /* Check whether the entire file path (root + fqn + data file name), is lenght portable */
+ isLengthPortablePath(child.getAbsolutePath());
+ /* Check whether the fqn tree we're trying to store could contain non portable characters */
+ isCharacterPortableTree(fqn);
+
if (!child.createNewFile())
{
throw new IOException("Unable to create file: " + child);
@@ -364,4 +376,50 @@
output.writeObject(attrs);
out.close();
}
+
+ protected boolean isCharacterPortableLocation(String fileAbsolutePath)
+ {
+ /* For full path, check '*' '<' '>' '|' '"' '?' Regex: [\*<>|"?] */
+ Pattern fullPathPattern = Pattern.compile("[\\*<>|\"?]");
+ Matcher matcher = fullPathPattern.matcher(fileAbsolutePath);
+ if (matcher.find())
+ {
+ log.warn("Cache loader location ( " + fileAbsolutePath + " ) contains one of these characters: '*' '<' '>' '|' '\"' '?'");
+ log.warn("Directories containing these characters are illegal in some operative systems and could lead to portability issues");
+ return false;
+ }
+
+ return true;
+ }
+
+ protected boolean isCharacterPortableTree(Fqn fqn)
+ {
+ /* For fqn, check '*' '<' '>' '|' '"' '?' and also '\' '/' and ':' */
+ Pattern fqnPattern = Pattern.compile("[\\\\\\/:*<>|\"?]");
+
+ List<String> elements = fqn.peekElements();
+ for (String anElement : elements)
+ {
+ Matcher matcher = fqnPattern.matcher(anElement);
+ if (matcher.find())
+ {
+ log.warn("One of the Fqn ( " + fqn + " ) elements contains one of these characters: '*' '<' '>' '|' '\"' '?' '\\' '/' ':' ");
+ log.warn("Directories containing these characters are illegal in some operative systems and could lead to portability issues");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ protected boolean isLengthPortablePath(String absoluteFqnPath)
+ {
+ if (absoluteFqnPath.length() > 255)
+ {
+ log.warn("The full absolute path to the fqn that you are trying to store is bigger than 255 characters, this could lead to problems in Windows systems: " + absoluteFqnPath);
+ return false;
+ }
+
+ return true;
+ }
}
More information about the jboss-cvs-commits
mailing list