diff options
author | Josh Gao <jmgao@google.com> | 2015-12-02 21:56:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-12-02 21:56:04 +0000 |
commit | 1702f427b53b88d9517bb994844a9a15e02f2bba (patch) | |
tree | fedb9510d49e783ae0cb4968554651d09bf08df2 /adb/file_sync_client.cpp | |
parent | d0d87f78e55362e3792ddec5faeab247f3493858 (diff) | |
parent | b0e039f4ca1dd59a13078bb9bb4c24daac93cd84 (diff) |
Merge "adb: don't divide by zero"
Diffstat (limited to 'adb/file_sync_client.cpp')
-rw-r--r-- | adb/file_sync_client.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/adb/file_sync_client.cpp b/adb/file_sync_client.cpp index 12d428ce59..9ad7bad1eb 100644 --- a/adb/file_sync_client.cpp +++ b/adb/file_sync_client.cpp @@ -185,8 +185,15 @@ class SyncConnection { total_bytes += bytes_read; bytes_copied += bytes_read; - int percentage = static_cast<int>(bytes_copied * 100 / total_size); - Printf("%s: %d%%", rpath, percentage); + if (total_size == 0) { + // This case can happen if we're racing against something that wrote to the file + // between our stat and our read, or if we're reading a magic file that lies about + // its size. + Printf("%s: ?%%", rpath); + } else { + int percentage = static_cast<int>(bytes_copied * 100 / total_size); + Printf("%s: %d%%", rpath, percentage); + } } adb_close(lfd); @@ -472,8 +479,14 @@ static bool sync_recv(SyncConnection& sc, const char* rpath, const char* lpath) bytes_copied += msg.data.size; - int percentage = static_cast<int>(bytes_copied * 100 / size); - sc.Printf("%s: %d%%", rpath, percentage); + if (size == 0) { + // This case can happen if we're racing against something that wrote to the file between + // our stat and our read, or if we're reading a magic file that lies about its size. + sc.Printf("%s: ?%%", rpath); + } else { + int percentage = static_cast<int>(bytes_copied * 100 / size); + sc.Printf("%s: %d%%", rpath, percentage); + } } adb_close(lfd); |