From b88eda83fe6669a0892a05f800137ad7195abcda Mon Sep 17 00:00:00 2001 From: EmelyanenkoK Date: Sat, 24 Dec 2022 13:10:09 +0300 Subject: [PATCH] A few improvements in storage-daemon-cli interface (#570) * Pause and resume upload in storage-daemon * Update help * Update LoadSpeed.cpp * Fix json output, prohibit torrents without files Co-authored-by: SpyCheese Co-authored-by: Andrey Pfau --- storage/LoadSpeed.cpp | 2 +- storage/TorrentCreator.cpp | 3 +++ storage/TorrentHeader.cpp | 3 +++ storage/storage-daemon/storage-daemon-cli.cpp | 10 ++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/storage/LoadSpeed.cpp b/storage/LoadSpeed.cpp index ddba2b85..b47f4120 100644 --- a/storage/LoadSpeed.cpp +++ b/storage/LoadSpeed.cpp @@ -22,7 +22,7 @@ #include "td/utils/format.h" namespace ton { -void LoadSpeed::add(std::size_t size, td::Timestamp now) { +void LoadSpeed::add(td::uint64 size, td::Timestamp now) { total_size_ += size; events_.push(Event{size, now}); update(now); diff --git a/storage/TorrentCreator.cpp b/storage/TorrentCreator.cpp index d9d97df7..35fb8212 100644 --- a/storage/TorrentCreator.cpp +++ b/storage/TorrentCreator.cpp @@ -98,6 +98,9 @@ TD_WARN_UNUSED_RESULT td::Status Torrent::Creator::add_file(td::Slice name, td:: } td::Result Torrent::Creator::finalize() { + if (files_.empty()) { + return td::Status::Error("No files"); + } TorrentHeader header; TRY_RESULT(files_count, td::narrow_cast_safe(files_.size())); header.files_count = files_count; diff --git a/storage/TorrentHeader.cpp b/storage/TorrentHeader.cpp index 2d7867e0..aec7c46e 100644 --- a/storage/TorrentHeader.cpp +++ b/storage/TorrentHeader.cpp @@ -100,6 +100,9 @@ td::Status TorrentHeader::validate(td::uint64 total_size, td::uint64 header_size if (serialization_size() != header_size) { return td::Status::Error("Invalid size"); } + if (files_count == 0) { + return td::Status::Error("No files"); + } for (size_t i = 0; i + 1 < files_count; ++i) { if (name_index[i] > name_index[i + 1]) { return td::Status::Error("Invalid name offset"); diff --git a/storage/storage-daemon/storage-daemon-cli.cpp b/storage/storage-daemon/storage-daemon-cli.cpp index d29f8b27..194243f6 100644 --- a/storage/storage-daemon/storage-daemon-cli.cpp +++ b/storage/storage-daemon/storage-daemon-cli.cpp @@ -774,6 +774,8 @@ class StorageDaemonCli : public td::actor::Actor { td::TerminalIO::out() << "\t--json\tOutput in json\n"; td::TerminalIO::out() << "download-pause \tPause download of \n"; td::TerminalIO::out() << "download-resume \tResume download of \n"; + td::TerminalIO::out() << "upload-pause \tPause upload of \n"; + td::TerminalIO::out() << "upload-resume \tResume upload of \n"; td::TerminalIO::out() << "priority-all

\tSet priority of all files in to

\n"; td::TerminalIO::out() << "\tPriority is in [0..255], 0 - don't download\n"; td::TerminalIO::out() << "priority-idx

\tSet priority of file # in to

\n"; @@ -856,6 +858,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } td::TerminalIO::out() << "Bag created\n"; @@ -888,6 +891,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } td::TerminalIO::out() << "Bag added\n"; @@ -921,6 +925,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } td::TerminalIO::out() << "Bag added\n"; @@ -939,6 +944,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } td::actor::send_closure(SelfId, &StorageDaemonCli::print_torrent_list, R.move_as_ok(), with_hashes); @@ -956,6 +962,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } td::actor::send_closure(SelfId, &StorageDaemonCli::print_torrent_full, R.move_as_ok()); @@ -994,6 +1001,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } auto obj = R.move_as_ok(); @@ -1260,6 +1268,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } auto params = R.move_as_ok(); @@ -1325,6 +1334,7 @@ class StorageDaemonCli : public td::actor::Actor { } if (json) { print_json(R.ok()); + td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK()); return; } auto info = R.move_as_ok();