r69 - in trunk/diswork-fs: . src/main/java/org/nuiton/diswork/fs src/main/java/org/nuiton/diswork/fs/storage
Author: bleny Date: 2010-06-08 16:35:06 +0200 (Tue, 08 Jun 2010) New Revision: 69 Url: http://nuiton.org/repositories/revision/diswork/69 Log: fs : syntax check on paths Modified: trunk/diswork-fs/run_demo.sh trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/DisworkFileSystem.java trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/storage/Storage.java Modified: trunk/diswork-fs/run_demo.sh =================================================================== --- trunk/diswork-fs/run_demo.sh 2010-06-08 13:16:35 UTC (rev 68) +++ trunk/diswork-fs/run_demo.sh 2010-06-08 14:35:06 UTC (rev 69) @@ -1,2 +1,2 @@ -mvn -e exec:java -Dexec.mainClass=org.nuiton.disworkfs.Demo -Dexec.args="consumer 9001" -Dexec.classpathScope=test -mvn -e exec:java -Dexec.mainClass=org.nuiton.disworkfs.Demo -Dexec.args="producer 9002 127.0.0.1 9001" -Dexec.classpathScope=test +mvn -e exec:java -Dexec.mainClass=org.nuiton.diswork.fs.Demo -Dexec.args="consumer 9001" -Dexec.classpathScope=test +mvn -e exec:java -Dexec.mainClass=org.nuiton.diswork.fs.Demo -Dexec.args="producer 9002 127.0.0.1 9001" -Dexec.classpathScope=test Modified: trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/DisworkFileSystem.java =================================================================== --- trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/DisworkFileSystem.java 2010-06-08 13:16:35 UTC (rev 68) +++ trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/DisworkFileSystem.java 2010-06-08 14:35:06 UTC (rev 69) @@ -89,6 +89,7 @@ * @throws IOException */ public boolean exists(String path) throws IOException { + checkPathSyntax(path); String entry = walk(path); boolean result = entry != null; return result; @@ -104,6 +105,7 @@ */ public InputStream read(String path) throws FileNotFoundException, IOException { + checkPathSyntax(path); String entry = walk(path); if (entry == null) { @@ -141,8 +143,9 @@ public void write(String path, InputStream source) throws IOException, ConcurrentModificationException { + checkPathSyntax(path); if (source == null) { - throw new IOException("source is not readable (null stream)"); + throw new NullPointerException("source stream is null"); } String parent = EntryUtil.getParentFromPath(path); String name = EntryUtil.getNameFromPath(path); @@ -224,6 +227,7 @@ public void createDirectory(String path) throws IOException, ConcurrentModificationException { + checkPathSyntax(path); String parent = EntryUtil.getParentFromPath(path); String dirName = EntryUtil.getNameFromPath(path); createDirectory(parent, dirName); @@ -309,6 +313,7 @@ public void createSymbolicLink(String path, String target) throws IOException, ConcurrentModificationException { + checkPathSyntax(path); String parent = EntryUtil.getParentFromPath(path); String name = EntryUtil.getNameFromPath(path); createSymbolicLink(parent, name, target); @@ -411,6 +416,7 @@ */ public void delete(String path) throws IOException, ConcurrentModificationException { + checkPathSyntax(path); String parent = EntryUtil.getParentFromPath(path); String name = EntryUtil.getNameFromPath(path); log.info("trying to remove " + path); @@ -510,6 +516,7 @@ * @throws IOException if path doesn't point to a directory */ public List<String> readDirectory(String path) throws IOException { + checkPathSyntax(path); String entry = walk(path); List<String> result = null; @@ -660,11 +667,29 @@ @Override public void close() throws IOException { - storage.close(); + storage.close(); } protected void setMap(DisworkMap map) { storage.setMap(map); } -} + /** + * check a path is absolute and syntactically correct, throw exception if + * that's not the case. + */ + protected void checkPathSyntax(String path) throws IOException { + if (!path.startsWith(EntryUtil.ROOT_DIRECTORY)) { + throw new IOException("\" + path + \" is not correct, all pathes " + + "have to be absolute (thus, starts with)" + + EntryUtil.ROOT_DIRECTORY); + } + + String doubleSeparator = EntryUtil.PATH_SEPARATOR + + EntryUtil.PATH_SEPARATOR; + if (path.contains(doubleSeparator)) { + throw new IOException("\" + path + \" is not correct, it contains " + + doubleSeparator); + } + } +} \ No newline at end of file Modified: trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/storage/Storage.java =================================================================== --- trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/storage/Storage.java 2010-06-08 13:16:35 UTC (rev 68) +++ trunk/diswork-fs/src/main/java/org/nuiton/diswork/fs/storage/Storage.java 2010-06-08 14:35:06 UTC (rev 69) @@ -51,12 +51,16 @@ protected static final long LOCK_VALID_TIME = 60 * 60 * 1000; + /** this id will be used to sign locks */ protected String ownerId = EntryUtil.generateId(); + /** a key where the lock for key should be put at the returned value */ protected static String keyToLockKey(String key) { return key + "_lock"; } - + + /** when using copy-on-write new data for the value of key should be stored + * to the returned value */ protected static String keyToNewDataKey(String key) { return key + "_new_data"; }
participants (1)
-
bleny@users.nuiton.org