Commits

JP Abgrall  committed 55b6c84

adb: Don't unlink special files on sync failure.

adb push some_disk_image /dev/block/mmcblk0p9
should not unlink the dev just because adb was ctrl-c'd.

Change-Id: I1b6669e8dba1f80fc1438b8deb618180b7e9a1b2
Signed-off-by: JP Abgrall <jpa@google.com>

  • Participants
  • Parent commits 4ce2f83

Comments (0)

Files changed (1)

File adb/file_sync_service.c

 }
 
 static int handle_send_file(int s, char *path, uid_t uid,
-        gid_t gid, mode_t mode, char *buffer)
+        gid_t gid, mode_t mode, char *buffer, bool do_unlink)
 {
     syncmsg msg;
     unsigned int timestamp = 0;
         if(writex(fd, buffer, len)) {
             int saved_errno = errno;
             adb_close(fd);
-            adb_unlink(path);
+            if (do_unlink) adb_unlink(path);
             fd = -1;
             errno = saved_errno;
             if(fail_errno(s)) return -1;
 fail:
     if(fd >= 0)
         adb_close(fd);
-    adb_unlink(path);
+    if (do_unlink) adb_unlink(path);
     return -1;
 }
 
     char *tmp;
     unsigned int mode;
     int is_link, ret;
+    bool do_unlink;
 
     tmp = strrchr(path,',');
     if(tmp) {
     if(!tmp || errno) {
         mode = 0644;
         is_link = 0;
+        do_unlink = true;
     } 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)) {
+        do_unlink = lstat(path, &st) || S_ISREG(st.st_mode) || S_ISLNK(st.st_mode);
+        if (do_unlink) {
             adb_unlink(path);
         }
     }
         if (is_on_system(path)) {
             fs_config(tmp, 0, &uid, &gid, &mode, &cap);
         }
-        ret = handle_send_file(s, path, uid, gid, mode, buffer);
+        ret = handle_send_file(s, path, uid, gid, mode, buffer, do_unlink);
     }
 
     return ret;