diff --git a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt index 271d470..235f7e8 100644 --- a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt +++ b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt @@ -28,19 +28,10 @@ internal class LocalDirectory(private val path: Path) : Directory { override suspend fun get(filename: String): FileReader = LocalFile(child(filename)) override suspend fun create(filename: String, ignoreIfExists: Boolean) { - val parts = filename.split(File.separator) - var cdir = this - for (i in 0..(parts.size - 1)) { - cdir = cdir.createSubdir(parts[i], true) - } - try { - val nfile = cdir.child(parts.last()).createFile() - /* - nfile.toFile().setReadable(true) + child(filename).parent.createDirectories() - nfile.toFile().setWritable(true) - nfile.toFile().setExecutable(true) - */ + try { + child(filename).createFile() } catch (ex: java.nio.file.FileAlreadyExistsException) { if (!ignoreIfExists) { throw ex @@ -54,7 +45,7 @@ internal class LocalDirectory(private val path: Path) : Directory { return LocalFile(tmp) } - override suspend fun getSubdir(path: Path): Directory = LocalDirectory(child(path)) + override suspend fun getSubdir(path: Path): LocalDirectory = LocalDirectory(child(path)) override suspend fun createSubdir(dirname: String, ignoreIfExists: Boolean): LocalDirectory { val dir = child(dirname) try { diff --git a/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/local/Tests.kt b/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/local/Tests.kt index 7b69701..3fd85a4 100644 --- a/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/local/Tests.kt +++ b/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/local/Tests.kt @@ -3,6 +3,7 @@ package space.kscience.snark.storage.local import kotlinx.coroutines.runBlocking import space.kscience.snark.storage.Directory +import java.io.File import java.nio.file.Path import kotlin.io.path.* import kotlin.test.* @@ -29,7 +30,7 @@ internal class LocalDriverTests { val entries = tempDir!!.listDirectoryEntries() assertEquals(1, entries.size) assertEquals(tempDir!! / Path("tmp1"), entries.first()) - assertTrue(!entries.first().isDirectory()) + //assertTrue(!entries.first().isDirectory()) //create second file testSample!!.create("tmp2") @@ -90,10 +91,11 @@ internal class LocalDriverTests { @Test fun testGetSubdir() = runBlocking { testSample!!.createSubdir("tmp") - testSample!!.create("tmp/data") - testSample!!.put("tmp/data").write(bytes) + val pathStr = (Path("tmp") / "data.txt").toString() + testSample!!.create(pathStr) + testSample!!.put(pathStr).write(bytes) val subdir = testSample!!.getSubdir(Path("tmp")) - assertContentEquals(bytes, subdir.get("data").readAll()) + assertContentEquals(bytes, subdir.get("data.txt").readAll()) } @AfterTest diff --git a/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/unzip/Tests.kt b/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/unzip/Tests.kt index d258397..4206527 100644 --- a/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/unzip/Tests.kt +++ b/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/unzip/Tests.kt @@ -27,7 +27,7 @@ internal class UnzipTests { val writter = dir.put(filename) if (!(tempDir!! / Path("source") / Path(filename)).isRegularFile()) { - println("shit") + println("new shit") } writter.write(content) } @@ -38,6 +38,8 @@ internal class UnzipTests { ZipOutputStream(BufferedOutputStream( FileOutputStream(zipFile))).use { it.use { zipFiles(it, sourceFile, "") + it.closeEntry() + it.close() } } } @@ -47,7 +49,6 @@ internal class UnzipTests { val data = ByteArray(2048) for (f in sourceFile.listFiles()) { - if (f.isDirectory) { val entry = ZipEntry(f.name + File.separator) entry.time = f.lastModified() @@ -90,7 +91,7 @@ internal class UnzipTests { val bytes3 = byteArrayOf(3, 2, 1, 0) makeFile(source, "tmp1", bytes1) makeFile(source, "tmp2", bytes2); - makeFile(source, "tdir${File.separator}tmp3", bytes3) + makeFile(source, (Path("tdir") / "tmp3").toString(), bytes3) dir.create("archive.zip") val archive_path = (tempDir!! / Path("archive.zip")).toString() @@ -99,8 +100,19 @@ internal class UnzipTests { unzip(archive_path, target) - val entries = (tempDir!! / Path("target")).listDirectoryEntries() + val targetPath = tempDir!! / Path("target") + val entries = targetPath.listDirectoryEntries() + assertEquals(3, entries.size) + val exp_entries = listOf( + targetPath / Path("tmp1"), + targetPath / Path("tmp2"), + targetPath / Path("tdir")) + assertContentEquals(entries.sorted(), exp_entries.sorted()) + + val tdirEntries = (targetPath / Path("tdir")).listDirectoryEntries() + assertEquals(1, tdirEntries.size) + assertEquals(tdirEntries.first(), targetPath / Path("tdir") / Path("tmp3")) } @AfterTest