From 081696d27c3b3c6bc0e2b97449c1da791fa00d25 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 3 Sep 2015 11:06:00 -0700 Subject: [PATCH] Improve adb sync_send error reporting. Bug: http://b/23786900 Change-Id: I71f10de8d767eaf8bf0f5d9b8c304527e2b953ff --- adb/file_sync_client.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/adb/file_sync_client.cpp b/adb/file_sync_client.cpp index 94876eec1..9bc634c3d 100644 --- a/adb/file_sync_client.cpp +++ b/adb/file_sync_client.cpp @@ -73,6 +73,7 @@ static bool SendRequest(int fd, int id, const char* path) { size_t path_length = strlen(path); if (path_length > 1024) { fprintf(stderr, "SendRequest failed: path too long: %zu", path_length); + errno = ENAMETOOLONG; return false; } @@ -256,28 +257,41 @@ static bool sync_send(SyncConnection& sc, const char *lpath, const char *rpath, syncsendbuf* sbuf = &send_buffer; std::string path_and_mode = android::base::StringPrintf("%s,%d", rpath, mode); - if (!SendRequest(sc.fd, ID_SEND, path_and_mode.c_str())) goto fail; + if (!SendRequest(sc.fd, ID_SEND, path_and_mode.c_str())) { + fprintf(stderr, "failed to send ID_SEND message '%s': %s\n", + path_and_mode.c_str(), strerror(errno)); + return false; + } if (S_ISREG(mode)) { if (!write_data_file(sc, lpath, sbuf, show_progress)) return false; } else if (S_ISLNK(mode)) { if (!write_data_link(sc, lpath, sbuf)) return false; } else { - goto fail; + fprintf(stderr, "local file '%s' has unsupported mode: 0o%o\n", lpath, mode); + return false; } syncmsg msg; msg.data.id = ID_DONE; msg.data.size = mtime; - if (!WriteFdExactly(sc.fd, &msg.data, sizeof(msg.data))) goto fail; - - if (!ReadFdExactly(sc.fd, &msg.status, sizeof(msg.status))) goto fail; + if (!WriteFdExactly(sc.fd, &msg.data, sizeof(msg.data))) { + fprintf(stderr, "failed to send ID_DONE message for '%s': %s\n", lpath, strerror(errno)); + return false; + } + if (!ReadFdExactly(sc.fd, &msg.status, sizeof(msg.status))) { + fprintf(stderr, "failed to read ID_DONE response for '%s': %s\n", lpath, strerror(errno)); + return false; + } if (msg.status.id != ID_OKAY) { if (msg.status.id == ID_FAIL) { size_t len = msg.status.msglen; if (len > 256) len = 256; - if (!ReadFdExactly(sc.fd, sbuf->data, len)) goto fail; + if (!ReadFdExactly(sc.fd, sbuf->data, len)) { + fprintf(stderr, "failed to read failure reason (!): %s\n", strerror(errno)); + return false; + } sbuf->data[len] = 0; } else { strcpy(sbuf->data, "unknown reason"); @@ -287,10 +301,6 @@ static bool sync_send(SyncConnection& sc, const char *lpath, const char *rpath, } return true; - -fail: - fprintf(stderr, "protocol failure\n"); - return false; } static int sync_recv(SyncConnection& sc, const char* rpath, const char* lpath, bool show_progress) {