The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dan Albert | 7664901 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 17 | #include <dirent.h> |
| 18 | #include <errno.h> |
Spencer Low | 6001c87 | 2015-05-13 00:02:55 -0700 | [diff] [blame] | 19 | #include <inttypes.h> |
Dan Albert | 7664901 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 20 | #include <limits.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 24 | #include <sys/stat.h> |
| 25 | #include <sys/time.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 26 | #include <sys/types.h> |
Dan Albert | 7664901 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 27 | #include <time.h> |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 28 | #include <unistd.h> |
Greg Hackmann | 7a5e2bd | 2014-05-06 08:48:18 -0700 | [diff] [blame] | 29 | #include <utime.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 30 | |
Elliott Hughes | a925dba | 2015-08-24 14:49:43 -0700 | [diff] [blame] | 31 | #include <memory> |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 32 | #include <vector> |
Elliott Hughes | a925dba | 2015-08-24 14:49:43 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 34 | #include "sysdeps.h" |
Dan Albert | 7664901 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 35 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 36 | #include "adb.h" |
| 37 | #include "adb_client.h" |
Dan Albert | cc731cc | 2015-02-24 21:26:58 -0800 | [diff] [blame] | 38 | #include "adb_io.h" |
Alex Vallée | 1421614 | 2015-05-06 17:22:25 -0400 | [diff] [blame] | 39 | #include "adb_utils.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 40 | #include "file_sync_service.h" |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 41 | #include "line_printer.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 42 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 43 | #include <base/file.h> |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 44 | #include <base/strings.h> |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 45 | #include <base/stringprintf.h> |
| 46 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 47 | struct syncsendbuf { |
| 48 | unsigned id; |
| 49 | unsigned size; |
| 50 | char data[SYNC_DATA_MAX]; |
| 51 | }; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 52 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 53 | class SyncConnection { |
| 54 | public: |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 55 | SyncConnection() : total_bytes(0), start_time_ms_(CurrentTimeMs()) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 56 | max = SYNC_DATA_MAX; // TODO: decide at runtime. |
| 57 | |
| 58 | std::string error; |
| 59 | fd = adb_connect("sync:", &error); |
| 60 | if (fd < 0) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 61 | Error("connect failed: %s", error.c_str()); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | ~SyncConnection() { |
| 66 | if (!IsValid()) return; |
| 67 | |
Spencer Low | 351ecd1 | 2015-10-14 17:32:44 -0700 | [diff] [blame^] | 68 | if (SendQuit()) { |
| 69 | // We sent a quit command, so the server should be doing orderly |
| 70 | // shutdown soon. But if we encountered an error while we were using |
| 71 | // the connection, the server might still be sending data (before |
| 72 | // doing orderly shutdown), in which case we won't wait for all of |
| 73 | // the data nor the coming orderly shutdown. In the common success |
| 74 | // case, this will wait for the server to do orderly shutdown. |
| 75 | ReadOrderlyShutdown(fd); |
| 76 | } |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 77 | adb_close(fd); |
| 78 | } |
| 79 | |
| 80 | bool IsValid() { return fd >= 0; } |
| 81 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 82 | bool SendRequest(int id, const char* path_and_mode) { |
| 83 | size_t path_length = strlen(path_and_mode); |
| 84 | if (path_length > 1024) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 85 | Error("SendRequest failed: path too long: %zu", path_length); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 86 | errno = ENAMETOOLONG; |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | // Sending header and payload in a single write makes a noticeable |
| 91 | // difference to "adb sync" performance. |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 92 | std::vector<char> buf(sizeof(SyncRequest) + path_length); |
| 93 | SyncRequest* req = reinterpret_cast<SyncRequest*>(&buf[0]); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 94 | req->id = id; |
| 95 | req->path_length = path_length; |
| 96 | char* data = reinterpret_cast<char*>(req + 1); |
| 97 | memcpy(data, path_and_mode, path_length); |
| 98 | |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 99 | return WriteFdExactly(fd, &buf[0], buf.size()); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | // Sending header, payload, and footer in a single write makes a huge |
| 103 | // difference to "adb sync" performance. |
| 104 | bool SendSmallFile(const char* path_and_mode, |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 105 | const char* rpath, |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 106 | const char* data, size_t data_length, |
| 107 | unsigned mtime) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 108 | Print(rpath); |
| 109 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 110 | size_t path_length = strlen(path_and_mode); |
| 111 | if (path_length > 1024) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 112 | Error("SendSmallFile failed: path too long: %zu", path_length); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 113 | errno = ENAMETOOLONG; |
| 114 | return false; |
| 115 | } |
| 116 | |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 117 | std::vector<char> buf(sizeof(SyncRequest) + path_length + |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 118 | sizeof(SyncRequest) + data_length + |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 119 | sizeof(SyncRequest)); |
| 120 | char* p = &buf[0]; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 121 | |
| 122 | SyncRequest* req_send = reinterpret_cast<SyncRequest*>(p); |
| 123 | req_send->id = ID_SEND; |
| 124 | req_send->path_length = path_length; |
| 125 | p += sizeof(SyncRequest); |
| 126 | memcpy(p, path_and_mode, path_length); |
| 127 | p += path_length; |
| 128 | |
| 129 | SyncRequest* req_data = reinterpret_cast<SyncRequest*>(p); |
| 130 | req_data->id = ID_DATA; |
| 131 | req_data->path_length = data_length; |
| 132 | p += sizeof(SyncRequest); |
| 133 | memcpy(p, data, data_length); |
| 134 | p += data_length; |
| 135 | |
| 136 | SyncRequest* req_done = reinterpret_cast<SyncRequest*>(p); |
| 137 | req_done->id = ID_DONE; |
| 138 | req_done->path_length = mtime; |
| 139 | p += sizeof(SyncRequest); |
| 140 | |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 141 | if (!WriteFdExactly(fd, &buf[0], (p - &buf[0]))) return false; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 142 | |
| 143 | total_bytes += data_length; |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | bool CopyDone(const char* from, const char* to) { |
| 148 | syncmsg msg; |
| 149 | if (!ReadFdExactly(fd, &msg.status, sizeof(msg.status))) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 150 | Error("failed to copy '%s' to '%s': no ID_DONE: %s", from, to, strerror(errno)); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 151 | return false; |
| 152 | } |
| 153 | if (msg.status.id == ID_OKAY) { |
| 154 | return true; |
| 155 | } |
| 156 | if (msg.status.id != ID_FAIL) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 157 | Error("failed to copy '%s' to '%s': unknown reason %d", from, to, msg.status.id); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 158 | return false; |
| 159 | } |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 160 | return ReportCopyFailure(from, to, msg); |
| 161 | } |
| 162 | |
| 163 | bool ReportCopyFailure(const char* from, const char* to, const syncmsg& msg) { |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 164 | std::vector<char> buf(msg.status.msglen + 1); |
| 165 | if (!ReadFdExactly(fd, &buf[0], msg.status.msglen)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 166 | Error("failed to copy '%s' to '%s'; failed to read reason (!): %s", |
| 167 | from, to, strerror(errno)); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 168 | return false; |
| 169 | } |
Elliott Hughes | 6d92997 | 2015-10-27 13:40:35 -0700 | [diff] [blame] | 170 | buf[msg.status.msglen] = 0; |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 171 | Error("failed to copy '%s' to '%s': %s", from, to, &buf[0]); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 172 | return false; |
| 173 | } |
| 174 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 175 | std::string TransferRate() { |
| 176 | uint64_t ms = CurrentTimeMs() - start_time_ms_; |
| 177 | if (total_bytes == 0 || ms == 0) return ""; |
| 178 | |
| 179 | double s = static_cast<double>(ms) / 1000LL; |
| 180 | double rate = (static_cast<double>(total_bytes) / s) / (1024*1024); |
| 181 | return android::base::StringPrintf(" %.1f MB/s (%" PRId64 " bytes in %.3fs)", |
| 182 | rate, total_bytes, s); |
| 183 | } |
| 184 | |
| 185 | void Print(const std::string& s) { |
| 186 | // TODO: we actually don't want ELIDE; we want "ELIDE if smart, FULL if dumb". |
| 187 | line_printer_.Print(s, LinePrinter::ELIDE); |
| 188 | } |
| 189 | |
| 190 | void Error(const char* fmt, ...) __attribute__((__format__(ADB_FORMAT_ARCHETYPE, 2, 3))) { |
| 191 | std::string s = "adb: error: "; |
| 192 | |
| 193 | va_list ap; |
| 194 | va_start(ap, fmt); |
| 195 | android::base::StringAppendV(&s, fmt, ap); |
| 196 | va_end(ap); |
| 197 | |
| 198 | line_printer_.Print(s, LinePrinter::FULL); |
| 199 | } |
| 200 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 201 | uint64_t total_bytes; |
| 202 | |
| 203 | // TODO: add a char[max] buffer here, to replace syncsendbuf... |
| 204 | int fd; |
| 205 | size_t max; |
| 206 | |
| 207 | private: |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 208 | uint64_t start_time_ms_; |
| 209 | |
| 210 | LinePrinter line_printer_; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 211 | |
Spencer Low | 351ecd1 | 2015-10-14 17:32:44 -0700 | [diff] [blame^] | 212 | bool SendQuit() { |
| 213 | return SendRequest(ID_QUIT, ""); // TODO: add a SendResponse? |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 216 | static uint64_t CurrentTimeMs() { |
| 217 | struct timeval tv; |
| 218 | gettimeofday(&tv, 0); // (Not clock_gettime because of Mac/Windows.) |
| 219 | return static_cast<uint64_t>(tv.tv_sec) * 1000 + tv.tv_usec / 1000; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 220 | } |
| 221 | }; |
| 222 | |
| 223 | typedef void (*sync_ls_cb)(unsigned mode, unsigned size, unsigned time, const char* name, void* cookie); |
| 224 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 225 | static bool sync_ls(SyncConnection& sc, const char* path, sync_ls_cb func, void* cookie) { |
| 226 | if (!sc.SendRequest(ID_LIST, path)) return false; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 227 | |
| 228 | while (true) { |
| 229 | syncmsg msg; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 230 | if (!ReadFdExactly(sc.fd, &msg.dent, sizeof(msg.dent))) return false; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 231 | |
| 232 | if (msg.dent.id == ID_DONE) return true; |
| 233 | if (msg.dent.id != ID_DENT) return false; |
| 234 | |
Elliott Hughes | f446520 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 235 | size_t len = msg.dent.namelen; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 236 | if (len > 256) return false; // TODO: resize buffer? continue? |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 237 | |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 238 | char buf[257]; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 239 | if (!ReadFdExactly(sc.fd, buf, len)) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 240 | buf[len] = 0; |
| 241 | |
Elliott Hughes | f446520 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 242 | func(msg.dent.mode, msg.dent.size, msg.dent.time, buf, cookie); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 243 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 246 | static bool sync_finish_stat(SyncConnection& sc, unsigned int* timestamp, |
| 247 | unsigned int* mode, unsigned int* size) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 248 | syncmsg msg; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 249 | if (!ReadFdExactly(sc.fd, &msg.stat, sizeof(msg.stat)) || msg.stat.id != ID_STAT) { |
| 250 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Elliott Hughes | f446520 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 253 | if (timestamp) *timestamp = msg.stat.time; |
| 254 | if (mode) *mode = msg.stat.mode; |
| 255 | if (size) *size = msg.stat.size; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 256 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 257 | return true; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 260 | static bool sync_stat(SyncConnection& sc, const char* path, |
| 261 | unsigned int* timestamp, unsigned int* mode, unsigned int* size) { |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 262 | return sc.SendRequest(ID_STAT, path) && sync_finish_stat(sc, timestamp, mode, size); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 265 | static bool SendLargeFile(SyncConnection& sc, const char* path_and_mode, |
| 266 | const char* lpath, const char* rpath, |
| 267 | unsigned mtime) { |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 268 | if (!sc.SendRequest(ID_SEND, path_and_mode)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 269 | sc.Error("failed to send ID_SEND message '%s': %s", path_and_mode, strerror(errno)); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 270 | return false; |
| 271 | } |
| 272 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 273 | struct stat st; |
| 274 | if (stat(lpath, &st) == -1) { |
| 275 | sc.Error("cannot stat '%s': %s", lpath, strerror(errno)); |
| 276 | return false; |
Spencer Low | d8cce18 | 2015-08-28 01:07:30 -0700 | [diff] [blame] | 277 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 278 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 279 | uint64_t total_size = st.st_size; |
| 280 | uint64_t bytes_copied = 0; |
| 281 | |
| 282 | int lfd = adb_open(lpath, O_RDONLY); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 283 | if (lfd < 0) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 284 | sc.Error("cannot open '%s': %s", lpath, strerror(errno)); |
Spencer Low | d8cce18 | 2015-08-28 01:07:30 -0700 | [diff] [blame] | 285 | return false; |
Mark Lindner | 76f2a93 | 2014-03-11 17:55:59 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 288 | syncsendbuf sbuf; |
| 289 | sbuf.id = ID_DATA; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 290 | while (true) { |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 291 | int ret = adb_read(lfd, sbuf.data, sc.max); |
Elliott Hughes | 8fcd8bc | 2015-08-25 10:59:45 -0700 | [diff] [blame] | 292 | if (ret <= 0) { |
Spencer Low | d8cce18 | 2015-08-28 01:07:30 -0700 | [diff] [blame] | 293 | if (ret < 0) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 294 | sc.Error("cannot read '%s': %s", lpath, strerror(errno)); |
Spencer Low | d8cce18 | 2015-08-28 01:07:30 -0700 | [diff] [blame] | 295 | adb_close(lfd); |
| 296 | return false; |
| 297 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 298 | break; |
| 299 | } |
| 300 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 301 | sbuf.size = ret; |
| 302 | if (!WriteFdExactly(sc.fd, &sbuf, sizeof(unsigned) * 2 + ret)) { |
Spencer Low | d8cce18 | 2015-08-28 01:07:30 -0700 | [diff] [blame] | 303 | adb_close(lfd); |
| 304 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 305 | } |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 306 | sc.total_bytes += ret; |
Mark Lindner | 76f2a93 | 2014-03-11 17:55:59 -0700 | [diff] [blame] | 307 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 308 | bytes_copied += ret; |
| 309 | |
| 310 | int percentage = static_cast<int>(bytes_copied * 100 / total_size); |
| 311 | sc.Print(android::base::StringPrintf("%s: %d%%", rpath, percentage)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | adb_close(lfd); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 315 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 316 | syncmsg msg; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 317 | msg.data.id = ID_DONE; |
Elliott Hughes | f446520 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 318 | msg.data.size = mtime; |
Elliott Hughes | 081696d | 2015-09-03 11:06:00 -0700 | [diff] [blame] | 319 | if (!WriteFdExactly(sc.fd, &msg.data, sizeof(msg.data))) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 320 | sc.Error("failed to send ID_DONE message for '%s': %s", rpath, strerror(errno)); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 321 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 324 | return true; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 327 | static bool sync_send(SyncConnection& sc, const char* lpath, const char* rpath, |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 328 | unsigned mtime, mode_t mode) |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 329 | { |
| 330 | std::string path_and_mode = android::base::StringPrintf("%s,%d", rpath, mode); |
| 331 | |
| 332 | if (S_ISLNK(mode)) { |
| 333 | #if !defined(_WIN32) |
| 334 | char buf[PATH_MAX]; |
| 335 | ssize_t data_length = readlink(lpath, buf, PATH_MAX - 1); |
| 336 | if (data_length == -1) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 337 | sc.Error("readlink '%s' failed: %s", lpath, strerror(errno)); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 338 | return false; |
| 339 | } |
| 340 | buf[data_length++] = '\0'; |
| 341 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 342 | if (!sc.SendSmallFile(path_and_mode.c_str(), rpath, buf, data_length, mtime)) return false; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 343 | return sc.CopyDone(lpath, rpath); |
| 344 | #endif |
| 345 | } |
| 346 | |
| 347 | if (!S_ISREG(mode)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 348 | sc.Error("local file '%s' has unsupported mode: 0o%o", lpath, mode); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 349 | return false; |
| 350 | } |
| 351 | |
| 352 | struct stat st; |
| 353 | if (stat(lpath, &st) == -1) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 354 | sc.Error("failed to stat local file '%s': %s", lpath, strerror(errno)); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 355 | return false; |
| 356 | } |
| 357 | if (st.st_size < SYNC_DATA_MAX) { |
| 358 | std::string data; |
| 359 | if (!android::base::ReadFileToString(lpath, &data)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 360 | sc.Error("failed to read all of '%s': %s", lpath, strerror(errno)); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 361 | return false; |
| 362 | } |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 363 | if (!sc.SendSmallFile(path_and_mode.c_str(), rpath, data.data(), data.size(), mtime)) { |
| 364 | return false; |
| 365 | } |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 366 | } else { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 367 | if (!SendLargeFile(sc, path_and_mode.c_str(), lpath, rpath, mtime)) { |
| 368 | return false; |
| 369 | } |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 370 | } |
| 371 | return sc.CopyDone(lpath, rpath); |
| 372 | } |
| 373 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 374 | static bool sync_recv(SyncConnection& sc, const char* rpath, const char* lpath) { |
| 375 | sc.Print(rpath); |
| 376 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 377 | unsigned size = 0; |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 378 | if (!sync_stat(sc, rpath, nullptr, nullptr, &size)) return false; |
Mark Lindner | 76f2a93 | 2014-03-11 17:55:59 -0700 | [diff] [blame] | 379 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 380 | if (!sc.SendRequest(ID_RECV, rpath)) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 381 | |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 382 | adb_unlink(lpath); |
| 383 | mkdirs(lpath); |
| 384 | int lfd = adb_creat(lpath, 0644); |
| 385 | if (lfd < 0) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 386 | sc.Error("cannot create '%s': %s", lpath, strerror(errno)); |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 387 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 390 | uint64_t bytes_copied = 0; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 391 | while (true) { |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 392 | syncmsg msg; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 393 | if (!ReadFdExactly(sc.fd, &msg.data, sizeof(msg.data))) { |
Spencer Low | d8cce18 | 2015-08-28 01:07:30 -0700 | [diff] [blame] | 394 | adb_close(lfd); |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 395 | adb_unlink(lpath); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 396 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 397 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 398 | |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 399 | if (msg.data.id == ID_DONE) break; |
| 400 | |
| 401 | if (msg.data.id != ID_DATA) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 402 | adb_close(lfd); |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 403 | adb_unlink(lpath); |
| 404 | sc.ReportCopyFailure(rpath, lpath, msg); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 405 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 408 | if (msg.data.size > sc.max) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 409 | sc.Error("msg.data.size too large: %u (max %zu)", msg.data.size, sc.max); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 410 | adb_close(lfd); |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 411 | adb_unlink(lpath); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 412 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 415 | char buffer[SYNC_DATA_MAX]; |
| 416 | if (!ReadFdExactly(sc.fd, buffer, msg.data.size)) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 417 | adb_close(lfd); |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 418 | adb_unlink(lpath); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 419 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 422 | if (!WriteFdExactly(lfd, buffer, msg.data.size)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 423 | sc.Error("cannot write '%s': %s", lpath, strerror(errno)); |
Elliott Hughes | 8b43c3e | 2015-10-23 21:06:11 -0700 | [diff] [blame] | 424 | adb_close(lfd); |
| 425 | adb_unlink(lpath); |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | sc.total_bytes += msg.data.size; |
Mark Lindner | 76f2a93 | 2014-03-11 17:55:59 -0700 | [diff] [blame] | 430 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 431 | bytes_copied += msg.data.size; |
| 432 | |
| 433 | int percentage = static_cast<int>(bytes_copied * 100 / size); |
| 434 | sc.Print(android::base::StringPrintf("%s: %d%%", rpath, percentage)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | adb_close(lfd); |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 438 | return true; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 439 | } |
| 440 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 441 | static void do_sync_ls_cb(unsigned mode, unsigned size, unsigned time, |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 442 | const char* name, void* /*cookie*/) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 443 | printf("%08x %08x %08x %s\n", mode, size, time, name); |
| 444 | } |
| 445 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 446 | bool do_sync_ls(const char* path) { |
| 447 | SyncConnection sc; |
| 448 | if (!sc.IsValid()) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 449 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 450 | return sync_ls(sc, path, do_sync_ls_cb, 0); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 451 | } |
| 452 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 453 | struct copyinfo |
| 454 | { |
| 455 | copyinfo *next; |
| 456 | const char *src; |
| 457 | const char *dst; |
| 458 | unsigned int time; |
| 459 | unsigned int mode; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 460 | uint64_t size; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 461 | int flag; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 462 | }; |
| 463 | |
Elliott Hughes | 3edd54b | 2015-05-05 18:26:10 -0700 | [diff] [blame] | 464 | static copyinfo* mkcopyinfo(const char* spath, const char* dpath, const char* name, int isdir) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 465 | int slen = strlen(spath); |
| 466 | int dlen = strlen(dpath); |
| 467 | int nlen = strlen(name); |
| 468 | int ssize = slen + nlen + 2; |
| 469 | int dsize = dlen + nlen + 2; |
| 470 | |
Elliott Hughes | 3edd54b | 2015-05-05 18:26:10 -0700 | [diff] [blame] | 471 | copyinfo *ci = reinterpret_cast<copyinfo*>(malloc(sizeof(copyinfo) + ssize + dsize)); |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 472 | if (ci == 0) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 473 | fprintf(stderr, "out of memory\n"); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 474 | abort(); |
| 475 | } |
| 476 | |
| 477 | ci->next = 0; |
| 478 | ci->time = 0; |
| 479 | ci->mode = 0; |
| 480 | ci->size = 0; |
| 481 | ci->flag = 0; |
| 482 | ci->src = (const char*)(ci + 1); |
| 483 | ci->dst = ci->src + ssize; |
| 484 | snprintf((char*) ci->src, ssize, isdir ? "%s%s/" : "%s%s", spath, name); |
| 485 | snprintf((char*) ci->dst, dsize, isdir ? "%s%s/" : "%s%s", dpath, name); |
| 486 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 487 | return ci; |
| 488 | } |
| 489 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 490 | static bool IsDotOrDotDot(const char* name) { |
| 491 | return name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')); |
| 492 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 493 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 494 | static int local_build_list(SyncConnection& sc, |
| 495 | copyinfo** filelist, const char* lpath, const char* rpath) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 496 | copyinfo *dirlist = 0; |
| 497 | copyinfo *ci, *next; |
| 498 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 499 | std::unique_ptr<DIR, int(*)(DIR*)> dir(opendir(lpath), closedir); |
| 500 | if (!dir) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 501 | sc.Error("cannot open '%s': %s", lpath, strerror(errno)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 502 | return -1; |
| 503 | } |
| 504 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 505 | dirent* de; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 506 | while ((de = readdir(dir.get()))) { |
| 507 | if (IsDotOrDotDot(de->d_name)) continue; |
| 508 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 509 | char stat_path[PATH_MAX]; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 510 | if (strlen(lpath) + strlen(de->d_name) + 1 > sizeof(stat_path)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 511 | sc.Error("skipping long path '%s%s'", lpath, de->d_name); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 512 | continue; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 513 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 514 | strcpy(stat_path, lpath); |
| 515 | strcat(stat_path, de->d_name); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 516 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 517 | struct stat st; |
| 518 | if (!lstat(stat_path, &st)) { |
Daniel Rosenberg | 686bce6 | 2014-06-30 20:29:40 -0700 | [diff] [blame] | 519 | if (S_ISDIR(st.st_mode)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 520 | ci = mkcopyinfo(lpath, rpath, de->d_name, 1); |
Daniel Rosenberg | 686bce6 | 2014-06-30 20:29:40 -0700 | [diff] [blame] | 521 | ci->next = dirlist; |
| 522 | dirlist = ci; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 523 | } else { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 524 | ci = mkcopyinfo(lpath, rpath, de->d_name, 0); |
| 525 | if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 526 | sc.Error("skipping special file '%s'", ci->src); |
Daniel Rosenberg | 686bce6 | 2014-06-30 20:29:40 -0700 | [diff] [blame] | 527 | free(ci); |
| 528 | } else { |
| 529 | ci->time = st.st_mtime; |
| 530 | ci->mode = st.st_mode; |
| 531 | ci->size = st.st_size; |
| 532 | ci->next = *filelist; |
| 533 | *filelist = ci; |
| 534 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 535 | } |
Daniel Rosenberg | 686bce6 | 2014-06-30 20:29:40 -0700 | [diff] [blame] | 536 | } else { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 537 | sc.Error("cannot lstat '%s': %s",stat_path , strerror(errno)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 541 | // Close this directory and recurse. |
| 542 | dir.reset(); |
| 543 | for (ci = dirlist; ci != 0; ci = next) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 544 | next = ci->next; |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 545 | local_build_list(sc, filelist, ci->src, ci->dst); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 546 | free(ci); |
| 547 | } |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 552 | static bool copy_local_dir_remote(SyncConnection& sc, const char* lpath, const char* rpath, |
| 553 | bool check_timestamps, bool list_only) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 554 | copyinfo *filelist = 0; |
| 555 | copyinfo *ci, *next; |
| 556 | int pushed = 0; |
| 557 | int skipped = 0; |
| 558 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 559 | if ((lpath[0] == 0) || (rpath[0] == 0)) return false; |
| 560 | if (lpath[strlen(lpath) - 1] != '/') { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 561 | int tmplen = strlen(lpath)+2; |
Dan Albert | bac3474 | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 562 | char *tmp = reinterpret_cast<char*>(malloc(tmplen)); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 563 | if(tmp == 0) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 564 | snprintf(tmp, tmplen, "%s/",lpath); |
| 565 | lpath = tmp; |
| 566 | } |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 567 | if (rpath[strlen(rpath) - 1] != '/') { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 568 | int tmplen = strlen(rpath)+2; |
Dan Albert | bac3474 | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 569 | char *tmp = reinterpret_cast<char*>(malloc(tmplen)); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 570 | if(tmp == 0) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 571 | snprintf(tmp, tmplen, "%s/",rpath); |
| 572 | rpath = tmp; |
| 573 | } |
| 574 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 575 | if (local_build_list(sc, &filelist, lpath, rpath)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 576 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 579 | if (check_timestamps) { |
| 580 | for (ci = filelist; ci != 0; ci = ci->next) { |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 581 | if (!sc.SendRequest(ID_STAT, ci->dst)) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 582 | } |
| 583 | for(ci = filelist; ci != 0; ci = ci->next) { |
| 584 | unsigned int timestamp, mode, size; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 585 | if (!sync_finish_stat(sc, ×tamp, &mode, &size)) return false; |
| 586 | if (size == ci->size) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 587 | /* for links, we cannot update the atime/mtime */ |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 588 | if ((S_ISREG(ci->mode & mode) && timestamp == ci->time) || |
| 589 | (S_ISLNK(ci->mode & mode) && timestamp >= ci->time)) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 590 | ci->flag = 1; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 591 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | } |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 595 | for (ci = filelist; ci != 0; ci = next) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 596 | next = ci->next; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 597 | if (ci->flag == 0) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 598 | if (list_only) { |
| 599 | fprintf(stderr, "would push: %s -> %s\n", ci->src, ci->dst); |
| 600 | } else { |
| 601 | if (!sync_send(sc, ci->src, ci->dst, ci->time, ci->mode)) { |
| 602 | return false; |
| 603 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 604 | } |
| 605 | pushed++; |
| 606 | } else { |
| 607 | skipped++; |
| 608 | } |
| 609 | free(ci); |
| 610 | } |
| 611 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 612 | sc.Print(android::base::StringPrintf("%s: %d file%s pushed. %d file%s skipped.%s\n", |
| 613 | rpath, |
| 614 | pushed, (pushed == 1) ? "" : "s", |
| 615 | skipped, (skipped == 1) ? "" : "s", |
| 616 | sc.TransferRate().c_str())); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 617 | return true; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 620 | bool do_sync_push(const char* lpath, const char* rpath) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 621 | SyncConnection sc; |
| 622 | if (!sc.IsValid()) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 623 | |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 624 | struct stat st; |
| 625 | if (stat(lpath, &st)) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 626 | sc.Error("cannot stat '%s': %s", lpath, strerror(errno)); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 627 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 630 | if (S_ISDIR(st.st_mode)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 631 | return copy_local_dir_remote(sc, lpath, rpath, false, false); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 632 | } |
| 633 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 634 | unsigned mode; |
| 635 | if (!sync_stat(sc, rpath, nullptr, &mode, nullptr)) return false; |
| 636 | std::string path_holder; |
| 637 | if (mode != 0 && S_ISDIR(mode)) { |
| 638 | // If we're copying a local file to a remote directory, |
| 639 | // we really want to copy to remote_dir + "/" + local_filename. |
| 640 | path_holder = android::base::StringPrintf("%s/%s", rpath, adb_basename(lpath).c_str()); |
| 641 | rpath = path_holder.c_str(); |
| 642 | } |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 643 | bool result = sync_send(sc, lpath, rpath, st.st_mtime, st.st_mode); |
| 644 | sc.Print("\n"); |
| 645 | return result; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 646 | } |
| 647 | |
Elliott Hughes | 2d4121c | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 648 | struct sync_ls_build_list_cb_args { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 649 | SyncConnection* sc; |
| 650 | copyinfo** filelist; |
| 651 | copyinfo** dirlist; |
| 652 | const char* rpath; |
| 653 | const char* lpath; |
Elliott Hughes | 2d4121c | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 654 | }; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 655 | |
Elliott Hughes | 3edd54b | 2015-05-05 18:26:10 -0700 | [diff] [blame] | 656 | static void sync_ls_build_list_cb(unsigned mode, unsigned size, unsigned time, |
| 657 | const char* name, void* cookie) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 658 | { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 659 | sync_ls_build_list_cb_args* args = static_cast<sync_ls_build_list_cb_args*>(cookie); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 660 | copyinfo *ci; |
| 661 | |
| 662 | if (S_ISDIR(mode)) { |
| 663 | copyinfo **dirlist = args->dirlist; |
| 664 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 665 | // Don't try recursing down "." or "..". |
| 666 | if (IsDotOrDotDot(name)) return; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 667 | |
| 668 | ci = mkcopyinfo(args->rpath, args->lpath, name, 1); |
| 669 | ci->next = *dirlist; |
| 670 | *dirlist = ci; |
| 671 | } else if (S_ISREG(mode) || S_ISLNK(mode)) { |
| 672 | copyinfo **filelist = args->filelist; |
| 673 | |
| 674 | ci = mkcopyinfo(args->rpath, args->lpath, name, 0); |
| 675 | ci->time = time; |
| 676 | ci->mode = mode; |
| 677 | ci->size = size; |
| 678 | ci->next = *filelist; |
| 679 | *filelist = ci; |
| 680 | } else { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 681 | args->sc->Print(android::base::StringPrintf("skipping special file '%s'\n", name)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 685 | static bool remote_build_list(SyncConnection& sc, copyinfo **filelist, |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 686 | const char *rpath, const char *lpath) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 687 | copyinfo* dirlist = nullptr; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 688 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 689 | sync_ls_build_list_cb_args args; |
| 690 | args.sc = ≻ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 691 | args.filelist = filelist; |
| 692 | args.dirlist = &dirlist; |
| 693 | args.rpath = rpath; |
| 694 | args.lpath = lpath; |
| 695 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 696 | // Put the files/dirs in rpath on the lists. |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 697 | if (!sync_ls(sc, rpath, sync_ls_build_list_cb, &args)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 698 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 699 | } |
| 700 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 701 | // Recurse into each directory we found. |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 702 | while (dirlist != NULL) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 703 | copyinfo* next = dirlist->next; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 704 | if (!remote_build_list(sc, filelist, dirlist->src, dirlist->dst)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 705 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 706 | } |
| 707 | free(dirlist); |
| 708 | dirlist = next; |
| 709 | } |
| 710 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 711 | return true; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Dan Albert | bac3474 | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 714 | static int set_time_and_mode(const char *lpath, time_t time, unsigned int mode) |
Lajos Molnar | de8ff4a | 2013-04-19 12:41:09 -0700 | [diff] [blame] | 715 | { |
Greg Hackmann | 7a5e2bd | 2014-05-06 08:48:18 -0700 | [diff] [blame] | 716 | struct utimbuf times = { time, time }; |
| 717 | int r1 = utime(lpath, ×); |
Lajos Molnar | de8ff4a | 2013-04-19 12:41:09 -0700 | [diff] [blame] | 718 | |
| 719 | /* use umask for permissions */ |
| 720 | mode_t mask=umask(0000); |
| 721 | umask(mask); |
| 722 | int r2 = chmod(lpath, mode & ~mask); |
| 723 | |
| 724 | return r1 ? : r2; |
| 725 | } |
| 726 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 727 | static bool copy_remote_dir_local(SyncConnection& sc, const char* rpath, const char* lpath, |
| 728 | int copy_attrs) { |
| 729 | // Make sure that both directory paths end in a slash. |
| 730 | std::string rpath_clean(rpath); |
| 731 | std::string lpath_clean(lpath); |
| 732 | if (rpath_clean.empty() || lpath_clean.empty()) return false; |
| 733 | if (rpath_clean.back() != '/') rpath_clean.push_back('/'); |
| 734 | if (lpath_clean.back() != '/') lpath_clean.push_back('/'); |
Riley Andrews | 4d04d24 | 2014-12-12 13:12:36 -0800 | [diff] [blame] | 735 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 736 | // Recursively build the list of files to copy. |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 737 | sc.Print("pull: building file list..."); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 738 | copyinfo* filelist = nullptr; |
Elliott Hughes | ae5a6c0 | 2015-09-27 12:55:37 -0700 | [diff] [blame] | 739 | if (!remote_build_list(sc, &filelist, rpath_clean.c_str(), lpath_clean.c_str())) return false; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 740 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 741 | int pulled = 0; |
| 742 | int skipped = 0; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 743 | copyinfo* ci = filelist; |
| 744 | while (ci) { |
| 745 | copyinfo* next = ci->next; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 746 | if (ci->flag == 0) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 747 | sc.Print(android::base::StringPrintf("pull: %s -> %s", ci->src, ci->dst)); |
| 748 | if (!sync_recv(sc, ci->src, ci->dst)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 749 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 750 | } |
Lajos Molnar | de8ff4a | 2013-04-19 12:41:09 -0700 | [diff] [blame] | 751 | |
| 752 | if (copy_attrs && set_time_and_mode(ci->dst, ci->time, ci->mode)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 753 | return false; |
Lajos Molnar | de8ff4a | 2013-04-19 12:41:09 -0700 | [diff] [blame] | 754 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 755 | pulled++; |
| 756 | } else { |
| 757 | skipped++; |
| 758 | } |
| 759 | free(ci); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 760 | ci = next; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 761 | } |
| 762 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 763 | sc.Print(android::base::StringPrintf("%s: %d file%s pulled. %d file%s skipped.%s\n", |
| 764 | rpath, |
| 765 | pulled, (pulled == 1) ? "" : "s", |
| 766 | skipped, (skipped == 1) ? "" : "s", |
| 767 | sc.TransferRate().c_str())); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 768 | return true; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 769 | } |
| 770 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 771 | bool do_sync_pull(const char* rpath, const char* lpath, int copy_attrs) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 772 | SyncConnection sc; |
| 773 | if (!sc.IsValid()) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 774 | |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 775 | unsigned mode, time; |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 776 | if (!sync_stat(sc, rpath, &time, &mode, nullptr)) return false; |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 777 | if (mode == 0) { |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 778 | sc.Error("remote object '%s' does not exist", rpath); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 779 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 782 | if (S_ISREG(mode) || S_ISLNK(mode) || S_ISCHR(mode) || S_ISBLK(mode)) { |
| 783 | std::string path_holder; |
| 784 | struct stat st; |
| 785 | if (stat(lpath, &st) == 0) { |
| 786 | if (S_ISDIR(st.st_mode)) { |
| 787 | // If we're copying a remote file to a local directory, |
| 788 | // we really want to copy to local_dir + "/" + basename(remote). |
| 789 | path_holder = android::base::StringPrintf("%s/%s", lpath, adb_basename(rpath).c_str()); |
| 790 | lpath = path_holder.c_str(); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 791 | } |
| 792 | } |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 793 | if (!sync_recv(sc, rpath, lpath)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 794 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 795 | } else { |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 796 | if (copy_attrs && set_time_and_mode(lpath, time, mode)) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 797 | return false; |
Elliott Hughes | 5c74270 | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 798 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 799 | } |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 800 | sc.Print("\n"); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 801 | return true; |
| 802 | } else if (S_ISDIR(mode)) { |
| 803 | return copy_remote_dir_local(sc, rpath, lpath, copy_attrs); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 804 | } |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 805 | |
Elliott Hughes | b708d16 | 2015-10-27 16:03:15 -0700 | [diff] [blame] | 806 | sc.Error("remote object '%s' not a file or directory", rpath); |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 807 | return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 808 | } |
| 809 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 810 | bool do_sync_sync(const std::string& lpath, const std::string& rpath, bool list_only) { |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 811 | SyncConnection sc; |
| 812 | if (!sc.IsValid()) return false; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 813 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 814 | return copy_local_dir_remote(sc, lpath.c_str(), rpath.c_str(), true, list_only); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 815 | } |