mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Recent updates in storage (#667)
* Fix error handling in Torrent.cpp, improve choosing peers for upload * Various improvements in storage daemon "get-pieces-info" Store "added at" Improve calculating up/down speed Improve TL protocol for future compatibility Remove empty directories on "--remove-files" Better windows support Debug logs in PeerActor More restrictions on TorrentInfo Bugfixes * Global speed limits for download and upload +bugfix * Reset download/upload speed on changing settings or completion * Exclude some system files in TorrentCreator
This commit is contained in:
parent
e3af63e6c0
commit
bb21f732fd
21 changed files with 974 additions and 213 deletions
|
@ -29,18 +29,22 @@
|
|||
#include "TorrentHeader.hpp"
|
||||
|
||||
namespace ton {
|
||||
static bool is_dir_slash(char c) {
|
||||
return (c == TD_DIR_SLASH) | (c == '/');
|
||||
}
|
||||
|
||||
td::Result<Torrent> Torrent::Creator::create_from_path(Options options, td::CSlice raw_path) {
|
||||
TRY_RESULT(path, td::realpath(raw_path));
|
||||
TRY_RESULT(stat, td::stat(path));
|
||||
std::string root_dir = path;
|
||||
while (!root_dir.empty() && root_dir.back() == TD_DIR_SLASH) {
|
||||
while (!root_dir.empty() && is_dir_slash(root_dir.back())) {
|
||||
root_dir.pop_back();
|
||||
}
|
||||
while (!root_dir.empty() && root_dir.back() != TD_DIR_SLASH) {
|
||||
while (!root_dir.empty() && !is_dir_slash(root_dir.back())) {
|
||||
root_dir.pop_back();
|
||||
}
|
||||
if (stat.is_dir_) {
|
||||
if (!path.empty() && path.back() != TD_DIR_SLASH) {
|
||||
if (!path.empty() && !is_dir_slash(path.back())) {
|
||||
path += TD_DIR_SLASH;
|
||||
}
|
||||
if (!options.dir_name) {
|
||||
|
@ -50,7 +54,20 @@ td::Result<Torrent> Torrent::Creator::create_from_path(Options options, td::CSli
|
|||
td::Status status;
|
||||
auto walk_status = td::WalkPath::run(path, [&](td::CSlice name, td::WalkPath::Type type) {
|
||||
if (type == td::WalkPath::Type::NotDir) {
|
||||
status = creator.add_file(td::PathView::relative(name, path), name);
|
||||
std::string rel_name = td::PathView::relative(name, path).str();
|
||||
td::Slice file_name = rel_name;
|
||||
for (size_t i = 0; i < rel_name.size(); ++i) {
|
||||
if (is_dir_slash(rel_name[i])) {
|
||||
rel_name[i] = '/';
|
||||
file_name = td::Slice(rel_name.c_str() + i + 1, rel_name.c_str() + rel_name.size());
|
||||
}
|
||||
}
|
||||
// Exclude OS-created files that can be modified automatically and thus break some torrent pieces
|
||||
if (file_name == ".DS_Store" || td::to_lower(file_name) == "desktop.ini" ||
|
||||
td::to_lower(file_name) == "thumbs.db") {
|
||||
return td::WalkPath::Action::Continue;
|
||||
}
|
||||
status = creator.add_file(rel_name, name);
|
||||
if (status.is_error()) {
|
||||
return td::WalkPath::Action::Abort;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue