mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.8.9
This commit is contained in:
commit
a1d53df69c
@ -320,7 +320,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
|
|||||||
|
|
||||||
private def clean(path: String) = {
|
private def clean(path: String) = {
|
||||||
val result = com.google.common.io.Files.simplifyPath(path)
|
val result = com.google.common.io.Files.simplifyPath(path)
|
||||||
if (result.startsWith("../")) throw new FileNotFoundException(path)
|
if (result.startsWith("../") || result == "..") throw new FileNotFoundException(path)
|
||||||
if (result == "/" || result == ".") ""
|
if (result == "/" || result == ".") ""
|
||||||
else result
|
else result
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@ trait Buffered extends OutputStreamFileSystem {
|
|||||||
|
|
||||||
private val deletions = mutable.Map.empty[String, Long]
|
private val deletions = mutable.Map.empty[String, Long]
|
||||||
|
|
||||||
protected def isValidFilename(name: String) = true
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def delete(path: String) = {
|
override def delete(path: String) = {
|
||||||
@ -39,7 +37,7 @@ trait Buffered extends OutputStreamFileSystem {
|
|||||||
override def load(nbt: NBTTagCompound) = {
|
override def load(nbt: NBTTagCompound) = {
|
||||||
def recurse(path: String, directory: io.File) {
|
def recurse(path: String, directory: io.File) {
|
||||||
makeDirectory(path)
|
makeDirectory(path)
|
||||||
for (child <- directory.listFiles() if isValidFilename(child.getName)) {
|
for (child <- directory.listFiles() if FileSystem.isValidFilename(child.getName)) {
|
||||||
val childPath = path + child.getName
|
val childPath = path + child.getName
|
||||||
val childFile = new io.File(directory, child.getName)
|
val childFile = new io.File(directory, child.getName)
|
||||||
if (child.exists() && child.isDirectory && child.list() != null) {
|
if (child.exists() && child.isDirectory && child.list() != null) {
|
||||||
|
@ -23,18 +23,18 @@ trait FileInputStreamFileSystem extends InputStreamFileSystem {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def exists(path: String) = new io.File(root, path).exists()
|
override def exists(path: String) = new io.File(root, FileSystem.validatePath(path)).exists()
|
||||||
|
|
||||||
override def size(path: String) = new io.File(root, path) match {
|
override def size(path: String) = new io.File(root, FileSystem.validatePath(path)) match {
|
||||||
case file if file.isFile => file.length()
|
case file if file.isFile => file.length()
|
||||||
case _ => 0L
|
case _ => 0L
|
||||||
}
|
}
|
||||||
|
|
||||||
override def isDirectory(path: String) = new io.File(root, path).isDirectory
|
override def isDirectory(path: String) = new io.File(root, FileSystem.validatePath(path)).isDirectory
|
||||||
|
|
||||||
override def lastModified(path: String) = new io.File(root, path).lastModified
|
override def lastModified(path: String) = new io.File(root, FileSystem.validatePath(path)).lastModified
|
||||||
|
|
||||||
override def list(path: String) = new io.File(root, path) match {
|
override def list(path: String) = new io.File(root, FileSystem.validatePath(path)) match {
|
||||||
case file if file.exists() && file.isFile => Array(file.getName)
|
case file if file.exists() && file.isFile => Array(file.getName)
|
||||||
case directory if directory.exists() && directory.isDirectory && directory.list() != null =>
|
case directory if directory.exists() && directory.isDirectory && directory.list() != null =>
|
||||||
directory.listFiles().map(file => if (file.isDirectory) file.getName + "/" else file.getName)
|
directory.listFiles().map(file => if (file.isDirectory) file.getName + "/" else file.getName)
|
||||||
|
@ -14,15 +14,15 @@ trait FileOutputStreamFileSystem extends FileInputStreamFileSystem with OutputSt
|
|||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def delete(path: String) = {
|
override def delete(path: String) = {
|
||||||
val file = new io.File(root, path)
|
val file = new io.File(root, FileSystem.validatePath(path))
|
||||||
file == root || file.delete()
|
file == root || file.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
override def makeDirectory(path: String) = new io.File(root, path).mkdir()
|
override def makeDirectory(path: String) = new io.File(root, FileSystem.validatePath(path)).mkdir()
|
||||||
|
|
||||||
override def rename(from: String, to: String) = new io.File(root, from).renameTo(new io.File(root, to))
|
override def rename(from: String, to: String) = new io.File(root, FileSystem.validatePath(from)).renameTo(new io.File(root, FileSystem.validatePath(to)))
|
||||||
|
|
||||||
override def setLastModified(path: String, time: Long) = new io.File(root, path).setLastModified(time)
|
override def setLastModified(path: String, time: Long) = new io.File(root, FileSystem.validatePath(path)).setLastModified(time)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
@ -9,9 +9,8 @@ import java.util.UUID
|
|||||||
import li.cil.oc.OpenComputers
|
import li.cil.oc.OpenComputers
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.api.network.EnvironmentHost
|
|
||||||
import li.cil.oc.api.fs.Label
|
import li.cil.oc.api.fs.Label
|
||||||
import li.cil.oc.api.fs.Mode
|
import li.cil.oc.api.network.EnvironmentHost
|
||||||
import li.cil.oc.server.component
|
import li.cil.oc.server.component
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
@ -42,6 +41,20 @@ object FileSystem extends api.detail.FileSystemAPI {
|
|||||||
true
|
true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Worst-case: we're on Windows or using a FAT32 partition mounted in *nix.
|
||||||
|
// Note: we allow / as the path separator and expect all \s to be converted
|
||||||
|
// accordingly before the path is passed to the file system.
|
||||||
|
private val invalidChars = """\:*?"<>|""".toSet
|
||||||
|
|
||||||
|
def isValidFilename(name: String) = !name.exists(invalidChars.contains)
|
||||||
|
|
||||||
|
def validatePath(path: String) = {
|
||||||
|
if (!isValidFilename(path)) {
|
||||||
|
throw new java.io.IOException("path contains invalid characters")
|
||||||
|
}
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
override def fromClass(clazz: Class[_], domain: String, root: String): api.fs.FileSystem = {
|
override def fromClass(clazz: Class[_], domain: String, root: String): api.fs.FileSystem = {
|
||||||
val innerPath = ("/assets/" + domain + "/" + (root.trim + "/")).replace("//", "/")
|
val innerPath = ("/assets/" + domain + "/" + (root.trim + "/")).replace("//", "/")
|
||||||
|
|
||||||
@ -158,29 +171,11 @@ object FileSystem extends api.detail.FileSystemAPI {
|
|||||||
extends VirtualFileSystem
|
extends VirtualFileSystem
|
||||||
with Buffered
|
with Buffered
|
||||||
with Capacity {
|
with Capacity {
|
||||||
// Worst-case: we're on Windows or using a FAT32 partition mounted in *nix.
|
|
||||||
// Note: we allow / as the path separator and expect all \s to be converted
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
protected override def segments(path: String) = {
|
protected override def segments(path: String) = {
|
||||||
val parts = super.segments(path)
|
val parts = super.segments(path)
|
||||||
if (isCaseInsensitive) toCaseInsensitive(parts) else parts
|
if (isCaseInsensitive) toCaseInsensitive(parts) else parts
|
||||||
}
|
}
|
||||||
|
|
||||||
private def validatePath(path: String) = {
|
|
||||||
if (!isValidFilename(path)) {
|
|
||||||
throw new java.io.IOException("path contains invalid characters")
|
|
||||||
}
|
|
||||||
path
|
|
||||||
}
|
|
||||||
|
|
||||||
private def toCaseInsensitive(path: Array[String]): Array[String] = {
|
private def toCaseInsensitive(path: Array[String]): Array[String] = {
|
||||||
var node = root
|
var node = root
|
||||||
path.map(segment => {
|
path.map(segment => {
|
||||||
|
@ -30,15 +30,18 @@ trait InputStreamFileSystem extends api.fs.FileSystem {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def open(path: String, mode: Mode) = this.synchronized(if (mode == Mode.Read && exists(path) && !isDirectory(path)) {
|
override def open(path: String, mode: Mode) = {
|
||||||
val handle = Iterator.continually((Math.random() * Int.MaxValue).toInt + 1).filterNot(handles.contains).next()
|
FileSystem.validatePath(path)
|
||||||
openInputChannel(path) match {
|
this.synchronized(if (mode == Mode.Read && exists(path) && !isDirectory(path)) {
|
||||||
case Some(channel) =>
|
val handle = Iterator.continually((Math.random() * Int.MaxValue).toInt + 1).filterNot(handles.contains).next()
|
||||||
handles += handle -> new Handle(this, handle, path, channel)
|
openInputChannel(path) match {
|
||||||
handle
|
case Some(channel) =>
|
||||||
case _ => throw new FileNotFoundException(path)
|
handles += handle -> new Handle(this, handle, path, channel)
|
||||||
}
|
handle
|
||||||
} else throw new FileNotFoundException(path))
|
case _ => throw new FileNotFoundException(path)
|
||||||
|
}
|
||||||
|
} else throw new FileNotFoundException(path))
|
||||||
|
}
|
||||||
|
|
||||||
override def getHandle(handle: Int): api.fs.Handle = this.synchronized(handles.get(handle).orNull)
|
override def getHandle(handle: Int): api.fs.Handle = this.synchronized(handles.get(handle).orNull)
|
||||||
|
|
||||||
|
@ -22,15 +22,17 @@ trait OutputStreamFileSystem extends InputStreamFileSystem {
|
|||||||
|
|
||||||
override def open(path: String, mode: Mode) = this.synchronized(mode match {
|
override def open(path: String, mode: Mode) = this.synchronized(mode match {
|
||||||
case Mode.Read => super.open(path, mode)
|
case Mode.Read => super.open(path, mode)
|
||||||
case _ => if (!isDirectory(path)) {
|
case _ =>
|
||||||
val handle = Iterator.continually((Math.random() * Int.MaxValue).toInt + 1).filterNot(handles.contains).next()
|
FileSystem.validatePath(path)
|
||||||
openOutputHandle(handle, path, mode) match {
|
if (!isDirectory(path)) {
|
||||||
case Some(fileHandle) =>
|
val handle = Iterator.continually((Math.random() * Int.MaxValue).toInt + 1).filterNot(handles.contains).next()
|
||||||
handles += handle -> fileHandle
|
openOutputHandle(handle, path, mode) match {
|
||||||
handle
|
case Some(fileHandle) =>
|
||||||
case _ => throw new FileNotFoundException(path)
|
handles += handle -> fileHandle
|
||||||
}
|
handle
|
||||||
} else throw new FileNotFoundException(path)
|
case _ => throw new FileNotFoundException(path)
|
||||||
|
}
|
||||||
|
} else throw new FileNotFoundException(path)
|
||||||
})
|
})
|
||||||
|
|
||||||
override def getHandle(handle: Int): api.fs.Handle = this.synchronized(Option(super.getHandle(handle)).orElse(handles.get(handle)).orNull)
|
override def getHandle(handle: Int): api.fs.Handle = this.synchronized(Option(super.getHandle(handle)).orElse(handles.get(handle)).orNull)
|
||||||
|
@ -135,7 +135,7 @@ trait VirtualFileSystem extends OutputStreamFileSystem {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
protected def segments(path: String) = path.split("/").filter(_ != "")
|
protected def segments(path: String) = FileSystem.validatePath(path).split("/").filter(_ != "")
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user