mirror of
https://github.com/corda/corda.git
synced 2025-02-07 19:40:25 +00:00
Merged in mnesbit-sprint-5-tidyup (pull request #221)
Mnesbit sprint 5 tidyup
This commit is contained in:
commit
12d5f01086
@ -381,12 +381,11 @@ interface Attachment : NamedByHash {
|
|||||||
* @throws FileNotFoundException if the given path doesn't exist in the attachment.
|
* @throws FileNotFoundException if the given path doesn't exist in the attachment.
|
||||||
*/
|
*/
|
||||||
fun extractFile(path: String, outputTo: OutputStream) {
|
fun extractFile(path: String, outputTo: OutputStream) {
|
||||||
val p = path.toLowerCase()
|
val p = path.toLowerCase().split('\\','/')
|
||||||
openAsJAR().use { jar ->
|
openAsJAR().use { jar ->
|
||||||
while (true) {
|
while (true) {
|
||||||
val e = jar.nextJarEntry ?: break
|
val e = jar.nextJarEntry ?: break
|
||||||
// TODO: Normalise path separators here for more platform independence, as zip doesn't mandate a type.
|
if (e.name.toLowerCase().split('\\','/') == p) {
|
||||||
if (e.name.toLowerCase() == p) {
|
|
||||||
jar.copyTo(outputTo)
|
jar.copyTo(outputTo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,11 @@ class AttachmentsClassLoader(attachments: List<Attachment>, parent: ClassLoader
|
|||||||
// We already verified that paths are not strange/game playing when we inserted the attachment
|
// We already verified that paths are not strange/game playing when we inserted the attachment
|
||||||
// into the storage service. So we don't need to repeat it here.
|
// into the storage service. So we don't need to repeat it here.
|
||||||
//
|
//
|
||||||
// We forbid files that differ only in case to avoid issues for Windows/Mac developers where the
|
// We forbid files that differ only in case, or path separator to avoid issues for Windows/Mac developers where the
|
||||||
// filesystem tries to be case insensitive. This may break developers who attempt to use ProGuard.
|
// filesystem tries to be case insensitive. This may break developers who attempt to use ProGuard.
|
||||||
//
|
//
|
||||||
// TODO: Do we need extra overlap checks?
|
// Also convert to Unix path separators as all resource/class lookups will expect this.
|
||||||
val path = entry.name.toLowerCase()
|
val path = entry.name.toLowerCase().replace('\\', '/')
|
||||||
if (path in pathsToAttachments)
|
if (path in pathsToAttachments)
|
||||||
throw OverlappingAttachments(path)
|
throw OverlappingAttachments(path)
|
||||||
pathsToAttachments[path] = attachment
|
pathsToAttachments[path] = attachment
|
||||||
|
@ -9,6 +9,7 @@ import com.r3corda.core.serialization.*
|
|||||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||||
import com.r3corda.core.testing.MEGA_CORP
|
import com.r3corda.core.testing.MEGA_CORP
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
@ -93,6 +94,14 @@ class AttachmentClassLoaderTests {
|
|||||||
return bs.toByteArray()
|
return bs.toByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun readAttachment(attachment: Attachment, filepath: String) : ByteArray {
|
||||||
|
ByteArrayOutputStream().use {
|
||||||
|
attachment.extractFile(filepath, it)
|
||||||
|
return it.toByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test MockAttachmentStorage open as jar`() {
|
fun `test MockAttachmentStorage open as jar`() {
|
||||||
val storage = MockAttachmentStorage()
|
val storage = MockAttachmentStorage()
|
||||||
@ -130,6 +139,27 @@ class AttachmentClassLoaderTests {
|
|||||||
assertEquals("some data", txt)
|
assertEquals("some data", txt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Check platform independent path handling in attachment jars`() {
|
||||||
|
val storage = MockAttachmentStorage()
|
||||||
|
|
||||||
|
val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("/folder1/foldera/file1.txt", "some data")))
|
||||||
|
val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("\\folder1\\folderb\\file2.txt", "some other data")))
|
||||||
|
|
||||||
|
val data1a = readAttachment(storage.openAttachment(att1)!!, "/folder1/foldera/file1.txt")
|
||||||
|
Assert.assertArrayEquals("some data".toByteArray(), data1a)
|
||||||
|
|
||||||
|
val data1b = readAttachment(storage.openAttachment(att1)!!, "\\folder1\\foldera\\file1.txt")
|
||||||
|
Assert.assertArrayEquals("some data".toByteArray(), data1b)
|
||||||
|
|
||||||
|
val data2a = readAttachment(storage.openAttachment(att2)!!, "\\folder1\\folderb\\file2.txt")
|
||||||
|
Assert.assertArrayEquals("some other data".toByteArray(), data2a)
|
||||||
|
|
||||||
|
val data2b = readAttachment(storage.openAttachment(att2)!!, "/folder1/folderb/file2.txt")
|
||||||
|
Assert.assertArrayEquals("some other data".toByteArray(), data2b)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `loading class AnotherDummyContract`() {
|
fun `loading class AnotherDummyContract`() {
|
||||||
val storage = MockAttachmentStorage()
|
val storage = MockAttachmentStorage()
|
||||||
|
@ -5,8 +5,6 @@ import com.r3corda.node.services.statemachine.ProtocolStateMachineImpl
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread-safe storage of fiber checkpoints.
|
* Thread-safe storage of fiber checkpoints.
|
||||||
*
|
|
||||||
* TODO: Make internal to node again once split [ServiceHub] into a public (to contracts etc) and private (to node) view
|
|
||||||
*/
|
*/
|
||||||
interface CheckpointStorage {
|
interface CheckpointStorage {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user