google / adb-sync

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

adb-sync seems to close standard input?

ropery opened this issue · comments

foo (containing file 1.txt) and bar (containing file 2.txt) are two directories under /sdcard on my phone.

When I run the following script test.sh on my computer:

#!/bin/sh
while read -r dir; do
    ./adb-sync -R /sdcard/"$dir" .
done <<EOF
foo
bar
EOF

The result is that only the first directory foo is synced:

$ ./test.sh
INFO:root:Sync: local b'./foo', remote b'/sdcard/foo'
INFO:root:Scanning and diffing...
INFO:root:Pull: b'./foo'
INFO:root:Pull: b'./foo/1.txt'
[100%] /sdcard/foo/1.txt
INFO:root:Total: 1 KB/s (312 bytes in 0.225s)

The problem is read -r dir fails in the second iteration, perhaps implying stdin in closed.

Interesting issue.

This is probably because adb-sync calls "adb shell", which in turn connects stdin to the phone.

I think I can fix this by making adb-sync not connect stdin to its subprocesses anymore.

I face a similar problem : the directories I want to sync are listed in a CSV file 'file.csv' (2 fields on each line : SOURCE,DEST).

When I run the bash script
#!/bin/bash
while read line; do
./adb-sync $SOURCE $DEST
done < file.csv

only the first line of file.csv is read and consequently, only the first directory is synced.

I've found a workaround. Instead of a 'while... do... done' loop, I use a 'for... do... done' loop.

#!/bin/bash
for line in $(cat file.csv); do
./adb-sync $SOURCE $DEST
done

It works fine, but I couldn't explain why !