From 4ce2f838e78592d0b93776b73ca4de855a423dde Mon Sep 17 00:00:00 2001 From: JP Abgrall Date: Tue, 3 Dec 2013 14:52:39 -0800 Subject: [PATCH] adb: Don't clobber block devices during push In the past, an adb push would ALWAYS unlink the target path. Now, we only links and regular files (and links). This allows the following to work: adb shell ls -l /dev/block/mmcblk0p8 # brw------- root root 179, 8 2013-11-28 07:43 mmcblk0p8 adb push n7.jpa.mda.post_jb_encryption.raw /dev/block/mmcblk0p8 Bug: 11984121 Change-Id: I982c7a1cd87986621f2bebdcb41c4e281f67f772 --- adb/file_sync_service.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/adb/file_sync_service.c b/adb/file_sync_service.c index e981c2a50..25bfdc983 100644 --- a/adb/file_sync_service.c +++ b/adb/file_sync_service.c @@ -339,11 +339,14 @@ static int do_send(int s, char *path, char *buffer) if(!tmp || errno) { mode = 0644; is_link = 0; + } else { + struct stat st; + /* Don't delete files before copying if they are not "regular" */ + if(lstat(path, &st) || S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { + adb_unlink(path); + } } - adb_unlink(path); - - #ifdef HAVE_SYMLINKS if(is_link) ret = handle_send_link(s, path, buffer);