summaryrefslogtreecommitdiff
path: root/adb/daemon/file_sync_service.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2019-08-07 14:23:17 -0700
committerJosh Gao <jmgao@google.com>2019-08-12 13:46:34 -0700
commit34a478f572e83cde57b5ce4418c0c980e14d2e66 (patch)
tree4a79b15fc1015c4dfa12fa0fff6b5252d3a417fa /adb/daemon/file_sync_service.cpp
parent51fcf3222bf6057eb59467956dab5a97c9ec70b4 (diff)
adb: add ls_v2.
Add a 64-bit size/time variant of `adb ls`. Bug: http://b/122955521 Test: adb shell dd if=/dev/zero bs=1m count=8192 of=/data/local/tmp/big Test: adb pull /data/local/tmp/big Test: adb ls /data/local/tmp Change-Id: I6ff857239995bc7b5c5f8dfd65a36fad41e67d85
Diffstat (limited to 'adb/daemon/file_sync_service.cpp')
-rw-r--r--adb/daemon/file_sync_service.cpp80
1 files changed, 59 insertions, 21 deletions
diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp
index c6e156352..d6af7087d 100644
--- a/adb/daemon/file_sync_service.cpp
+++ b/adb/daemon/file_sync_service.cpp
@@ -174,40 +174,73 @@ static bool do_stat_v2(int s, uint32_t id, const char* path) {
return WriteFdExactly(s, &msg.stat_v2, sizeof(msg.stat_v2));
}
+template <bool v2>
static bool do_list(int s, const char* path) {
dirent* de;
- syncmsg msg;
- msg.dent.id = ID_DENT;
+ using MessageType =
+ std::conditional_t<v2, decltype(syncmsg::dent_v2), decltype(syncmsg::dent_v1)>;
+ MessageType msg;
+ uint32_t msg_id;
+ if constexpr (v2) {
+ msg_id = ID_DENT_V2;
+ } else {
+ msg_id = ID_DENT_V1;
+ }
std::unique_ptr<DIR, int(*)(DIR*)> d(opendir(path), closedir);
if (!d) goto done;
while ((de = readdir(d.get()))) {
+ memset(&msg, 0, sizeof(msg));
+ msg.id = msg_id;
+
std::string filename(StringPrintf("%s/%s", path, de->d_name));
struct stat st;
if (lstat(filename.c_str(), &st) == 0) {
- size_t d_name_length = strlen(de->d_name);
- msg.dent.mode = st.st_mode;
- msg.dent.size = st.st_size;
- msg.dent.mtime = st.st_mtime;
- msg.dent.namelen = d_name_length;
-
- if (!WriteFdExactly(s, &msg.dent, sizeof(msg.dent)) ||
- !WriteFdExactly(s, de->d_name, d_name_length)) {
- return false;
+ msg.mode = st.st_mode;
+ msg.size = st.st_size;
+ msg.mtime = st.st_mtime;
+
+ if constexpr (v2) {
+ msg.dev = st.st_dev;
+ msg.ino = st.st_ino;
+ msg.nlink = st.st_nlink;
+ msg.uid = st.st_uid;
+ msg.gid = st.st_gid;
+ msg.atime = st.st_atime;
+ msg.ctime = st.st_ctime;
+ }
+ } else {
+ if constexpr (v2) {
+ msg.error = errno;
+ } else {
+ continue;
}
}
+
+ size_t d_name_length = strlen(de->d_name);
+ msg.namelen = d_name_length;
+
+ if (!WriteFdExactly(s, &msg, sizeof(msg)) ||
+ !WriteFdExactly(s, de->d_name, d_name_length)) {
+ return false;
+ }
}
done:
- msg.dent.id = ID_DONE;
- msg.dent.mode = 0;
- msg.dent.size = 0;
- msg.dent.mtime = 0;
- msg.dent.namelen = 0;
- return WriteFdExactly(s, &msg.dent, sizeof(msg.dent));
+ memset(&msg, 0, sizeof(msg));
+ msg.id = ID_DONE;
+ return WriteFdExactly(s, &msg, sizeof(msg));
+}
+
+static bool do_list_v1(int s, const char* path) {
+ return do_list<false>(s, path);
+}
+
+static bool do_list_v2(int s, const char* path) {
+ return do_list<true>(s, path);
}
// Make sure that SendFail from adb_io.cpp isn't accidentally used in this file.
@@ -499,8 +532,10 @@ static const char* sync_id_to_name(uint32_t id) {
return "lstat_v2";
case ID_STAT_V2:
return "stat_v2";
- case ID_LIST:
- return "list";
+ case ID_LIST_V1:
+ return "list_v1";
+ case ID_LIST_V2:
+ return "list_v2";
case ID_SEND:
return "send";
case ID_RECV:
@@ -546,8 +581,11 @@ static bool handle_sync_command(int fd, std::vector<char>& buffer) {
case ID_STAT_V2:
if (!do_stat_v2(fd, request.id, name)) return false;
break;
- case ID_LIST:
- if (!do_list(fd, name)) return false;
+ case ID_LIST_V1:
+ if (!do_list_v1(fd, name)) return false;
+ break;
+ case ID_LIST_V2:
+ if (!do_list_v2(fd, name)) return false;
break;
case ID_SEND:
if (!do_send(fd, name, buffer)) return false;