Ignoring files in real file system when generating buffered filesystem with invalid chars in their names, should fix #758.

This commit is contained in:
Florian Nücke 2015-01-03 16:44:20 +01:00
parent 177617a176
commit 6c63956b2f
2 changed files with 6 additions and 2 deletions

View File

@ -14,6 +14,8 @@ trait Buffered extends OutputStreamFileSystem {
private val deletions = mutable.Map.empty[String, Long]
protected def isValidFilename(name: String) = true
// ----------------------------------------------------------------------- //
override def delete(path: String) = {
@ -37,7 +39,7 @@ trait Buffered extends OutputStreamFileSystem {
override def load(nbt: NBTTagCompound) = {
def recurse(path: String, directory: io.File) {
makeDirectory(path)
for (child <- directory.listFiles()) {
for (child <- directory.listFiles() if isValidFilename(child.getName)) {
val childPath = path + child.getName
val childFile = new io.File(directory, child.getName)
if (child.isDirectory) {

View File

@ -158,6 +158,8 @@ object FileSystem extends api.detail.FileSystemAPI {
// accordingly before the path is passed to the file system.
private val invalidChars = """\:*?"<>|""".toSet
override protected def isValidFilename(name: String) = !name.exists(invalidChars.contains)
override def makeDirectory(path: String) = super.makeDirectory(validatePath(path))
override protected def openOutputHandle(id: Int, path: String, mode: Mode) = super.openOutputHandle(id, validatePath(path), mode)
@ -168,7 +170,7 @@ object FileSystem extends api.detail.FileSystemAPI {
}
private def validatePath(path: String) = {
if (path.exists(invalidChars.contains)) {
if (!isValidFilename(path)) {
throw new java.io.IOException("path contains invalid characters")
}
path