diff options
-rw-r--r-- | client/adb_install.cpp | 2 | ||||
-rw-r--r-- | client/commandline.cpp | 43 | ||||
-rw-r--r-- | client/fastdeploy.cpp | 2 | ||||
-rw-r--r-- | client/file_sync_client.cpp | 13 | ||||
-rw-r--r-- | client/file_sync_client.h | 6 | ||||
-rw-r--r-- | client/line_printer.cpp | 4 | ||||
-rw-r--r-- | client/line_printer.h | 2 |
7 files changed, 48 insertions, 24 deletions
diff --git a/client/adb_install.cpp b/client/adb_install.cpp index b861ce22..5a1e1b09 100644 --- a/client/adb_install.cpp +++ b/client/adb_install.cpp @@ -287,7 +287,7 @@ static int install_app_legacy(int argc, const char** argv, bool use_fastdeploy) } } - if (do_sync_push(apk_file, apk_dest.c_str(), false, CompressionType::Any, false)) { + if (do_sync_push(apk_file, apk_dest.c_str(), false, CompressionType::Any, false, false)) { result = pm_command(argc, argv); delete_device_file(apk_dest); } diff --git a/client/commandline.cpp b/client/commandline.cpp index c07be210..8efc9918 100644 --- a/client/commandline.cpp +++ b/client/commandline.cpp @@ -139,21 +139,24 @@ static void help() { "file transfer:\n" " push [--sync] [-z ALGORITHM] [-Z] LOCAL... REMOTE\n" " copy local files/directories to device\n" - " --sync: only push files that have different timestamps on the host than the device\n" " -n: dry run: push files to device without storing to the filesystem\n" - " -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)\n" + " -q: suppress progress messages\n" " -Z: disable compression\n" + " -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)\n" + " --sync: only push files that have different timestamps on the host than the device\n" " pull [-a] [-z ALGORITHM] [-Z] REMOTE... LOCAL\n" " copy files/dirs from device\n" " -a: preserve file timestamp and mode\n" - " -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)\n" + " -q: suppress progress messages\n" " -Z: disable compression\n" + " -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)\n" " sync [-l] [-z ALGORITHM] [-Z] [all|data|odm|oem|product|system|system_ext|vendor]\n" " sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)\n" - " -n: dry run: push files to device without storing to the filesystem\n" " -l: list files that would be copied, but don't copy them\n" - " -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)\n" + " -n: dry run: push files to device without storing to the filesystem\n" + " -q: suppress progress messages\n" " -Z: disable compression\n" + " -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)\n" "\n" "shell:\n" " shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]\n" @@ -1302,7 +1305,7 @@ static CompressionType parse_compression_type(const std::string& str, bool allow } static void parse_push_pull_args(const char** arg, int narg, std::vector<const char*>* srcs, - const char** dst, bool* copy_attrs, bool* sync, + const char** dst, bool* copy_attrs, bool* sync, bool* quiet, CompressionType* compression, bool* dry_run) { *copy_attrs = false; if (const char* adb_compression = getenv("ADB_COMPRESSION")) { @@ -1333,6 +1336,8 @@ static void parse_push_pull_args(const char** arg, int narg, std::vector<const c if (sync != nullptr) { *sync = true; } + } else if (!strcmp(*arg, "-q")) { + *quiet = true; } else if (!strcmp(*arg, "--")) { ignore_flags = true; } else { @@ -1942,27 +1947,29 @@ int adb_commandline(int argc, const char** argv) { bool copy_attrs = false; bool sync = false; bool dry_run = false; + bool quiet = false; CompressionType compression = CompressionType::Any; std::vector<const char*> srcs; const char* dst = nullptr; - parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, ©_attrs, &sync, &compression, - &dry_run); + parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, ©_attrs, &sync, &quiet, + &compression, &dry_run); if (srcs.empty() || !dst) { error_exit("push requires <source> and <destination> arguments"); } - return do_sync_push(srcs, dst, sync, compression, dry_run) ? 0 : 1; + return do_sync_push(srcs, dst, sync, compression, dry_run, quiet) ? 0 : 1; } else if (!strcmp(argv[0], "pull")) { bool copy_attrs = false; + bool quiet = false; CompressionType compression = CompressionType::None; std::vector<const char*> srcs; const char* dst = "."; - parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, ©_attrs, nullptr, &compression, - nullptr); + parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, ©_attrs, nullptr, &quiet, + &compression, nullptr); if (srcs.empty()) error_exit("pull requires an argument"); - return do_sync_pull(srcs, dst, copy_attrs, compression) ? 0 : 1; + return do_sync_pull(srcs, dst, copy_attrs, compression, nullptr, quiet) ? 0 : 1; } else if (!strcmp(argv[0], "install")) { if (argc < 2) error_exit("install requires an argument"); return install_app(argc, argv); @@ -1979,6 +1986,7 @@ int adb_commandline(int argc, const char** argv) { std::string src; bool list_only = false; bool dry_run = false; + bool quiet = false; CompressionType compression = CompressionType::Any; if (const char* adb_compression = getenv("ADB_COMPRESSION"); adb_compression) { @@ -1986,7 +1994,7 @@ int adb_commandline(int argc, const char** argv) { } int opt; - while ((opt = getopt(argc, const_cast<char**>(argv), "lnz:Z")) != -1) { + while ((opt = getopt(argc, const_cast<char**>(argv), "lnz:Zq")) != -1) { switch (opt) { case 'l': list_only = true; @@ -2000,8 +2008,11 @@ int adb_commandline(int argc, const char** argv) { case 'Z': compression = CompressionType::None; break; + case 'q': + quiet = true; + break; default: - error_exit("usage: adb sync [-l] [-n] [-z ALGORITHM] [-Z] [PARTITION]"); + error_exit("usage: adb sync [-l] [-n] [-z ALGORITHM] [-Z] [-q] [PARTITION]"); } } @@ -2010,7 +2021,7 @@ int adb_commandline(int argc, const char** argv) { } else if (optind + 1 == argc) { src = argv[optind]; } else { - error_exit("usage: adb sync [-l] [-n] [-z ALGORITHM] [-Z] [PARTITION]"); + error_exit("usage: adb sync [-l] [-n] [-z ALGORITHM] [-Z] [-q] [PARTITION]"); } std::vector<std::string> partitions{"data", "odm", "oem", "product", @@ -2021,7 +2032,7 @@ int adb_commandline(int argc, const char** argv) { std::string src_dir{product_file(partition)}; if (!directory_exists(src_dir)) continue; found = true; - if (!do_sync_sync(src_dir, "/" + partition, list_only, compression, dry_run)) { + if (!do_sync_sync(src_dir, "/" + partition, list_only, compression, dry_run, quiet)) { return 1; } } diff --git a/client/fastdeploy.cpp b/client/fastdeploy.cpp index bc4b91bb..adf31554 100644 --- a/client/fastdeploy.cpp +++ b/client/fastdeploy.cpp @@ -112,7 +112,7 @@ static void push_to_device(const void* data, size_t byte_count, const char* dst, // but can't be removed until after the push. unix_close(tf.release()); - if (!do_sync_push(srcs, dst, sync, CompressionType::Any, false)) { + if (!do_sync_push(srcs, dst, sync, CompressionType::Any, false, false)) { error_exit("Failed to push fastdeploy agent to device."); } } diff --git a/client/file_sync_client.cpp b/client/file_sync_client.cpp index 4c8fd042..410f4128 100644 --- a/client/file_sync_client.cpp +++ b/client/file_sync_client.cpp @@ -292,6 +292,10 @@ class SyncConnection { bool IsValid() { return fd >= 0; } + void SetQuiet(bool quiet) { + line_printer_.quiet_ = quiet; + } + void NewTransfer() { current_ledger_.Reset(); } @@ -1442,9 +1446,10 @@ static bool copy_local_dir_remote(SyncConnection& sc, std::string lpath, std::st } bool do_sync_push(const std::vector<const char*>& srcs, const char* dst, bool sync, - CompressionType compression, bool dry_run) { + CompressionType compression, bool dry_run, bool quiet) { SyncConnection sc; if (!sc.IsValid()) return false; + sc.SetQuiet(quiet); bool success = true; bool dst_exists; @@ -1664,9 +1669,10 @@ static bool copy_remote_dir_local(SyncConnection& sc, std::string rpath, std::st } bool do_sync_pull(const std::vector<const char*>& srcs, const char* dst, bool copy_attrs, - CompressionType compression, const char* name) { + CompressionType compression, const char* name, bool quiet) { SyncConnection sc; if (!sc.IsValid()) return false; + sc.SetQuiet(quiet); bool success = true; struct stat st; @@ -1774,9 +1780,10 @@ bool do_sync_pull(const std::vector<const char*>& srcs, const char* dst, bool co } bool do_sync_sync(const std::string& lpath, const std::string& rpath, bool list_only, - CompressionType compression, bool dry_run) { + CompressionType compression, bool dry_run, bool quiet) { SyncConnection sc; if (!sc.IsValid()) return false; + sc.SetQuiet(quiet); bool success = copy_local_dir_remote(sc, lpath, rpath, true, list_only, compression, dry_run); if (!list_only) { diff --git a/client/file_sync_client.h b/client/file_sync_client.h index cb8ca932..200a9ae8 100644 --- a/client/file_sync_client.h +++ b/client/file_sync_client.h @@ -23,9 +23,9 @@ bool do_sync_ls(const char* path); bool do_sync_push(const std::vector<const char*>& srcs, const char* dst, bool sync, - CompressionType compression, bool dry_run); + CompressionType compression, bool dry_run, bool quiet); bool do_sync_pull(const std::vector<const char*>& srcs, const char* dst, bool copy_attrs, - CompressionType compression, const char* name = nullptr); + CompressionType compression, const char* name = nullptr, bool quiet = false); bool do_sync_sync(const std::string& lpath, const std::string& rpath, bool list_only, - CompressionType compression, bool dry_run); + CompressionType compression, bool dry_run, bool quiet); diff --git a/client/line_printer.cpp b/client/line_printer.cpp index 50c03e81..ce6a6985 100644 --- a/client/line_printer.cpp +++ b/client/line_printer.cpp @@ -68,6 +68,10 @@ static void Out(const std::string& s) { } void LinePrinter::Print(string to_print, LineType type) { + if (quiet_ && type == LineType::INFO) { + return; + } + if (!smart_terminal_) { if (type == LineType::INFO) { info_line_ = to_print + "\n"; diff --git a/client/line_printer.h b/client/line_printer.h index 4c4c7c6f..34f5c54d 100644 --- a/client/line_printer.h +++ b/client/line_printer.h @@ -26,6 +26,8 @@ struct LinePrinter { bool is_smart_terminal() const { return smart_terminal_; } void set_smart_terminal(bool smart) { smart_terminal_ = smart; } + bool quiet_ = false; + enum LineType { INFO, WARNING, ERROR }; /// Outputs the given line. INFO output will be overwritten. |