am 44390474: Merge "adb: Don\'t unlink special files on sync failure."

* commit '443904746301e4d519e51075487ea4c8b9a860e3':
  adb: Don't unlink special files on sync failure.
This commit is contained in:
JP Abgrall 2014-03-08 01:56:37 +00:00 committed by Android Git Automerger
commit b4f1b3ca65

View file

@ -172,7 +172,7 @@ static int fail_errno(int s)
} }
static int handle_send_file(int s, char *path, uid_t uid, 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; syncmsg msg;
unsigned int timestamp = 0; unsigned int timestamp = 0;
@ -236,7 +236,7 @@ static int handle_send_file(int s, char *path, uid_t uid,
if(writex(fd, buffer, len)) { if(writex(fd, buffer, len)) {
int saved_errno = errno; int saved_errno = errno;
adb_close(fd); adb_close(fd);
adb_unlink(path); if (do_unlink) adb_unlink(path);
fd = -1; fd = -1;
errno = saved_errno; errno = saved_errno;
if(fail_errno(s)) return -1; if(fail_errno(s)) return -1;
@ -261,7 +261,7 @@ static int handle_send_file(int s, char *path, uid_t uid,
fail: fail:
if(fd >= 0) if(fd >= 0)
adb_close(fd); adb_close(fd);
adb_unlink(path); if (do_unlink) adb_unlink(path);
return -1; return -1;
} }
@ -323,6 +323,7 @@ static int do_send(int s, char *path, char *buffer)
char *tmp; char *tmp;
unsigned int mode; unsigned int mode;
int is_link, ret; int is_link, ret;
bool do_unlink;
tmp = strrchr(path,','); tmp = strrchr(path,',');
if(tmp) { if(tmp) {
@ -339,10 +340,12 @@ static int do_send(int s, char *path, char *buffer)
if(!tmp || errno) { if(!tmp || errno) {
mode = 0644; mode = 0644;
is_link = 0; is_link = 0;
do_unlink = true;
} else { } else {
struct stat st; struct stat st;
/* Don't delete files before copying if they are not "regular" */ /* 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); adb_unlink(path);
} }
} }
@ -369,7 +372,7 @@ static int do_send(int s, char *path, char *buffer)
if (is_on_system(path)) { if (is_on_system(path)) {
fs_config(tmp, 0, &uid, &gid, &mode, &cap); 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; return ret;