Skip to content

Commit da3d0fb

Browse files
Fixed the problem that packet id: "FAIL" was returned when UTF8 characters 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]>
1 parent b40357b commit da3d0fb

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

dadb/src/main/kotlin/dadb/AdbSync.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AdbSyncStream(
4545
@Throws(IOException::class)
4646
fun send(source: Source, remotePath: String, mode: Int, lastModifiedMs: Long) {
4747
val remote = "$remotePath,$mode"
48-
writePacket(SEND, remote.length)
48+
writePacket(SEND, remote.toByteArray().size)
4949

5050
stream.sink.apply {
5151
writeString(remote, StandardCharsets.UTF_8)
@@ -72,7 +72,7 @@ class AdbSyncStream(
7272

7373
@Throws(IOException::class)
7474
fun recv(sink: Sink, remotePath: String) {
75-
writePacket(RECV, remotePath.length)
75+
writePacket(RECV, remotePath.toByteArray().size)
7676
stream.sink.apply {
7777
writeString(remotePath, StandardCharsets.UTF_8)
7878
flush()

dadb/src/test/kotlin/dadb/DadbTest.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import org.junit.Rule
2525
import org.junit.rules.TemporaryFolder
2626
import java.io.ByteArrayInputStream
2727
import java.io.FileInputStream
28-
import java.io.FileOutputStream
2928
import java.net.Socket
3029
import java.nio.charset.StandardCharsets
3130
import java.util.*
@@ -42,6 +41,8 @@ internal abstract class DadbTest : BaseConcurrencyTest() {
4241

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

44+
private val remotePathWithCJK = "/data/local/tmp/你好こんにちは"
45+
4546
@JvmField
4647
@Rule
4748
val temporaryFolder = TemporaryFolder()
@@ -57,6 +58,7 @@ internal abstract class DadbTest : BaseConcurrencyTest() {
5758
internal fun tearDown() {
5859
localEmulator { dadb ->
5960
dadb.shell("rm -f $remotePath")
61+
dadb.shell("rm -f $remotePathWithCJK")
6062
}
6163
}
6264

@@ -169,6 +171,21 @@ internal abstract class DadbTest : BaseConcurrencyTest() {
169171
}
170172
}
171173

174+
@Test
175+
fun adbPush_pathWithCJK() {
176+
localEmulator { dadb ->
177+
val content = randomString()
178+
val localSrcFile = temporaryFolder.newFile().apply { writeText(content) }
179+
180+
dadb.push(localSrcFile, remotePathWithCJK, 439, System.currentTimeMillis())
181+
182+
val localDstFile = temporaryFolder.newFile()
183+
dadb.pull(localDstFile, remotePathWithCJK)
184+
185+
assertThat(localDstFile.readText()).isEqualTo(content)
186+
}
187+
}
188+
172189
@Test
173190
fun adbPush_file() {
174191
localEmulator { dadb ->

0 commit comments

Comments
 (0)