mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
synchronized functions in zip filesystem and moved try-catch in factory method, hopefully prevents issues in mcpc+; allowing any type of value as os env var for more flexibility where needed
This commit is contained in:
parent
5a162c8058
commit
1845ba0e17
@ -17,7 +17,7 @@ class ZipFileInputStreamFileSystem(private val archive: ArchiveDirectory) extend
|
|||||||
|
|
||||||
def spaceUsed = spaceUsed_
|
def spaceUsed = spaceUsed_
|
||||||
|
|
||||||
private lazy val spaceUsed_ = {
|
private lazy val spaceUsed_ = ZipFileInputStreamFileSystem.synchronized {
|
||||||
def recurse(d: ArchiveDirectory): Long = d.children.foldLeft(0L)((acc, c) => acc + (c match {
|
def recurse(d: ArchiveDirectory): Long = d.children.foldLeft(0L)((acc, c) => acc + (c match {
|
||||||
case directory: ArchiveDirectory => recurse(directory)
|
case directory: ArchiveDirectory => recurse(directory)
|
||||||
case file: ArchiveFile => file.size
|
case file: ArchiveFile => file.size
|
||||||
@ -27,28 +27,40 @@ class ZipFileInputStreamFileSystem(private val archive: ArchiveDirectory) extend
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def exists(path: String) = entry(path).isDefined
|
override def exists(path: String) = ZipFileInputStreamFileSystem.synchronized {
|
||||||
|
entry(path).isDefined
|
||||||
|
}
|
||||||
|
|
||||||
override def size(path: String) = entry(path) match {
|
override def size(path: String) = ZipFileInputStreamFileSystem.synchronized {
|
||||||
|
entry(path) match {
|
||||||
case Some(file) if !file.isDirectory => file.size
|
case Some(file) if !file.isDirectory => file.size
|
||||||
case _ => 0L
|
case _ => 0L
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override def isDirectory(path: String) = entry(path).exists(_.isDirectory)
|
override def isDirectory(path: String) = ZipFileInputStreamFileSystem.synchronized {
|
||||||
|
entry(path).exists(_.isDirectory)
|
||||||
|
}
|
||||||
|
|
||||||
def lastModified(path: String) = entry(path) match {
|
def lastModified(path: String) = ZipFileInputStreamFileSystem.synchronized {
|
||||||
|
entry(path) match {
|
||||||
case Some(file) => file.lastModified
|
case Some(file) => file.lastModified
|
||||||
case _ => 0L
|
case _ => 0L
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override def list(path: String) = entry(path) match {
|
override def list(path: String) = ZipFileInputStreamFileSystem.synchronized {
|
||||||
|
entry(path) match {
|
||||||
case Some(entry) if entry.isDirectory => entry.list()
|
case Some(entry) if entry.isDirectory => entry.list()
|
||||||
case _ => null
|
case _ => null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override protected def openInputStream(path: String) = entry(path).map(_.openStream())
|
override protected def openInputStream(path: String) = ZipFileInputStreamFileSystem.synchronized {
|
||||||
|
entry(path).map(_.openStream())
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
@ -65,9 +77,10 @@ object ZipFileInputStreamFileSystem {
|
|||||||
asInstanceOf[CacheBuilder[String, ArchiveDirectory]].
|
asInstanceOf[CacheBuilder[String, ArchiveDirectory]].
|
||||||
build[String, ArchiveDirectory]()
|
build[String, ArchiveDirectory]()
|
||||||
|
|
||||||
def fromFile(file: io.File, innerPath: String) = this.synchronized {
|
def fromFile(file: io.File, innerPath: String) = ZipFileInputStreamFileSystem.synchronized {
|
||||||
|
try {
|
||||||
Option(cache.get(file.getPath + ":" + innerPath, new Callable[ArchiveDirectory] {
|
Option(cache.get(file.getPath + ":" + innerPath, new Callable[ArchiveDirectory] {
|
||||||
def call = try {
|
def call = {
|
||||||
val zip = new ZipFile(file.getPath)
|
val zip = new ZipFile(file.getPath)
|
||||||
val cleanedPath = innerPath.stripPrefix("/").stripSuffix("/") + "/"
|
val cleanedPath = innerPath.stripPrefix("/").stripSuffix("/") + "/"
|
||||||
val rootEntry = zip.getEntry(cleanedPath)
|
val rootEntry = zip.getEntry(cleanedPath)
|
||||||
@ -102,15 +115,16 @@ object ZipFileInputStreamFileSystem {
|
|||||||
zip.close()
|
zip.close()
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
})) match {
|
||||||
|
case Some(archive) => new ZipFileInputStreamFileSystem(archive)
|
||||||
|
case _ => null
|
||||||
|
}
|
||||||
|
}
|
||||||
catch {
|
catch {
|
||||||
case e: Throwable =>
|
case e: Throwable =>
|
||||||
OpenComputers.log.log(Level.WARNING, "Failed creating ZIP file system.", e)
|
OpenComputers.log.log(Level.WARNING, "Failed creating ZIP file system.", e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
})) match {
|
|
||||||
case Some(archive) => new ZipFileInputStreamFileSystem(archive)
|
|
||||||
case _ => null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Archive(entry: ZipEntry, root: String) {
|
abstract class Archive(entry: ZipEntry, root: String) {
|
||||||
|
@ -29,7 +29,6 @@ end
|
|||||||
|
|
||||||
function os.setenv(varname, value)
|
function os.setenv(varname, value)
|
||||||
checkArg(1, varname, "string")
|
checkArg(1, varname, "string")
|
||||||
checkArg(2, value, "string", "nil")
|
|
||||||
env[varname] = value
|
env[varname] = value
|
||||||
return env[varname]
|
return env[varname]
|
||||||
end
|
end
|
||||||
|
@ -511,7 +511,7 @@ function shell.load(path, env, init, name)
|
|||||||
return thread
|
return thread
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.register(thread)
|
function shell.register(thread) -- called from coroutine.create
|
||||||
checkArg(1, thread, "thread")
|
checkArg(1, thread, "thread")
|
||||||
if findProcess(thread) then
|
if findProcess(thread) then
|
||||||
return false -- already attached somewhere
|
return false -- already attached somewhere
|
||||||
|
Loading…
x
Reference in New Issue
Block a user