Skip to content

Commit

Permalink
Fixed the problem that packet id: "FAIL" was returned when UTF8 chara…
Browse files Browse the repository at this point in the history
…cters appeared in the "path" parameter of the "push" method. (#71)

* Fixed the problem that "java.io.IOException: Unexpected sync packet id: FAIL" was thrown when UTF8 characters appeared in the path parameter of the push method.

* Fixed "No such file or directory" issue when CJK caracters appear in filename or path. & Add related test.

---------

Co-authored-by: Bartek Pacia <[email protected]>
  • Loading branch information
flyfishxu and bartekpacia authored Sep 6, 2024
1 parent b40357b commit da3d0fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dadb/src/main/kotlin/dadb/AdbSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AdbSyncStream(
@Throws(IOException::class)
fun send(source: Source, remotePath: String, mode: Int, lastModifiedMs: Long) {
val remote = "$remotePath,$mode"
writePacket(SEND, remote.length)
writePacket(SEND, remote.toByteArray().size)

stream.sink.apply {
writeString(remote, StandardCharsets.UTF_8)
Expand All @@ -72,7 +72,7 @@ class AdbSyncStream(

@Throws(IOException::class)
fun recv(sink: Sink, remotePath: String) {
writePacket(RECV, remotePath.length)
writePacket(RECV, remotePath.toByteArray().size)
stream.sink.apply {
writeString(remotePath, StandardCharsets.UTF_8)
flush()
Expand Down
19 changes: 18 additions & 1 deletion dadb/src/test/kotlin/dadb/DadbTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.junit.Rule
import org.junit.rules.TemporaryFolder
import java.io.ByteArrayInputStream
import java.io.FileInputStream
import java.io.FileOutputStream
import java.net.Socket
import java.nio.charset.StandardCharsets
import java.util.*
Expand All @@ -42,6 +41,8 @@ internal abstract class DadbTest : BaseConcurrencyTest() {

private val remotePath = "/data/local/tmp/hello"

private val remotePathWithCJK = "/data/local/tmp/你好こんにちは"

@JvmField
@Rule
val temporaryFolder = TemporaryFolder()
Expand All @@ -57,6 +58,7 @@ internal abstract class DadbTest : BaseConcurrencyTest() {
internal fun tearDown() {
localEmulator { dadb ->
dadb.shell("rm -f $remotePath")
dadb.shell("rm -f $remotePathWithCJK")
}
}

Expand Down Expand Up @@ -169,6 +171,21 @@ internal abstract class DadbTest : BaseConcurrencyTest() {
}
}

@Test
fun adbPush_pathWithCJK() {
localEmulator { dadb ->
val content = randomString()
val localSrcFile = temporaryFolder.newFile().apply { writeText(content) }

dadb.push(localSrcFile, remotePathWithCJK, 439, System.currentTimeMillis())

val localDstFile = temporaryFolder.newFile()
dadb.pull(localDstFile, remotePathWithCJK)

assertThat(localDstFile.readText()).isEqualTo(content)
}
}

@Test
fun adbPush_file() {
localEmulator { dadb ->
Expand Down

0 comments on commit da3d0fb

Please sign in to comment.