diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 0f4414b78..4f7292618 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" #include "data/data_types.h" #include "data/data_peer.h" diff --git a/Telegram/SourceFiles/core/basic_types.h b/Telegram/SourceFiles/base/basic_types.h similarity index 92% rename from Telegram/SourceFiles/core/basic_types.h rename to Telegram/SourceFiles/base/basic_types.h index af380719a..6a12ede99 100644 --- a/Telegram/SourceFiles/core/basic_types.h +++ b/Telegram/SourceFiles/base/basic_types.h @@ -7,6 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/build_config.h" +#include "base/ordered_set.h" +#include "base/unique_function.h" +#include "base/functors.h" + +#include + #include #include #include @@ -14,11 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -#include "base/build_config.h" -#include "base/ordered_set.h" -#include "base/unique_function.h" -#include "base/functors.h" - namespace func = base::functors; using gsl::not_null; @@ -45,6 +47,3 @@ using float64 = double; using TimeMs = int64; using TimeId = int32; - -#define qsl(s) QStringLiteral(s) -#define qstr(s) QLatin1String((s), sizeof(s) - 1) diff --git a/Telegram/SourceFiles/base/binary_guard.h b/Telegram/SourceFiles/base/binary_guard.h new file mode 100644 index 000000000..d48857f60 --- /dev/null +++ b/Telegram/SourceFiles/base/binary_guard.h @@ -0,0 +1,71 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "base/algorithm.h" + +#include + +namespace base { + +class binary_guard { +public: + binary_guard() = default; + binary_guard(binary_guard &&other); + binary_guard &operator=(binary_guard &&other); + ~binary_guard(); + + bool alive() const; + +private: + void destroy(); + + std::atomic *_bothAlive = nullptr; + + friend std::pair make_binary_guard(); + +}; + +inline binary_guard::binary_guard(binary_guard &&other) +: _bothAlive(base::take(other._bothAlive)) { +} + +inline binary_guard &binary_guard::operator=(binary_guard &&other) { + if (this != &other) { + destroy(); + _bothAlive = base::take(other._bothAlive); + } + return *this; +} + +inline binary_guard::~binary_guard() { + destroy(); +} + +inline bool binary_guard::alive() const { + return _bothAlive && _bothAlive->load(); +} + +inline void binary_guard::destroy() { + if (_bothAlive) { + auto old = true; + if (!_bothAlive->compare_exchange_strong(old, false)) { + delete _bothAlive; + } + } +} + +inline std::pair make_binary_guard() { + auto result = std::pair(); + result.first._bothAlive + = result.second._bothAlive + = new std::atomic(true); + return result; +} + +} // namespace base diff --git a/Telegram/SourceFiles/base/openssl_help.h b/Telegram/SourceFiles/base/openssl_help.h index 9d776b3da..2af1ba65c 100644 --- a/Telegram/SourceFiles/base/openssl_help.h +++ b/Telegram/SourceFiles/base/openssl_help.h @@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/bytes.h" #include "base/algorithm.h" -#include "core/basic_types.h" +#include "base/basic_types.h" extern "C" { #include diff --git a/Telegram/SourceFiles/core/single_timer.h b/Telegram/SourceFiles/core/single_timer.h index c031b170d..6b72b2fee 100644 --- a/Telegram/SourceFiles/core/single_timer.h +++ b/Telegram/SourceFiles/core/single_timer.h @@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" - class SingleTimer : public QTimer { // single shot timer with check Q_OBJECT diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index a3466e38f..77740370a 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "logs.h" -#include "core/basic_types.h" +#include "base/basic_types.h" #include "base/flags.h" #include "base/algorithm.h" #include "base/assertion.h" @@ -21,6 +21,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include +#define qsl(s) QStringLiteral(s) +#define qstr(s) QLatin1String((s), sizeof(s) - 1) + // Define specializations for QByteArray for Qt 5.3.2, because // QByteArray in Qt 5.3.2 doesn't declare "pointer" subtype. #ifdef OS_MAC_OLD diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index 7361f7a23..5f2e3aa19 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "export/export_settings.h" #include "export/output/export_output_file.h" #include "core/mime_type.h" - +#include "core/utils.h" #include #include #include diff --git a/Telegram/SourceFiles/export/export_api_wrap.cpp b/Telegram/SourceFiles/export/export_api_wrap.cpp index 3cceb5064..c882ba8fe 100644 --- a/Telegram/SourceFiles/export/export_api_wrap.cpp +++ b/Telegram/SourceFiles/export/export_api_wrap.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/rpc_sender.h" #include "base/value_ordering.h" #include "base/bytes.h" - #include #include diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.h b/Telegram/SourceFiles/inline_bots/inline_bot_result.h index c6478ade0..346bc1ac4 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.h @@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" - class FileLoader; namespace InlineBots { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h index a6ece93a5..3e3ee1cd6 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" #include "history/history_location_manager.h" namespace InlineBots { diff --git a/Telegram/SourceFiles/logs.h b/Telegram/SourceFiles/logs.h index fdb6a1222..e27b8ed6a 100644 --- a/Telegram/SourceFiles/logs.h +++ b/Telegram/SourceFiles/logs.h @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" +#include "base/basic_types.h" namespace Core { class Launcher; diff --git a/Telegram/SourceFiles/mtproto/core_types.h b/Telegram/SourceFiles/mtproto/core_types.h index 1658a26dd..527b1d556 100644 --- a/Telegram/SourceFiles/mtproto/core_types.h +++ b/Telegram/SourceFiles/mtproto/core_types.h @@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include -#include "core/basic_types.h" +#include "base/basic_types.h" #include "base/match_method.h" #include "base/flags.h" #include "base/bytes.h" diff --git a/Telegram/SourceFiles/mtproto/rpc_sender.h b/Telegram/SourceFiles/mtproto/rpc_sender.h index fc8ecffaa..f92a9a019 100644 --- a/Telegram/SourceFiles/mtproto/rpc_sender.h +++ b/Telegram/SourceFiles/mtproto/rpc_sender.h @@ -7,8 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include #include "base/flat_set.h" +#include "core/utils.h" +#include class RPCError { public: diff --git a/Telegram/SourceFiles/stdafx.h b/Telegram/SourceFiles/stdafx.h index e609c3626..0a63d5110 100644 --- a/Telegram/SourceFiles/stdafx.h +++ b/Telegram/SourceFiles/stdafx.h @@ -78,7 +78,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/flat_map.h" #include "base/weak_ptr.h" -#include "core/basic_types.h" +#include "base/basic_types.h" #include "logs.h" #include "core/utils.h" #include "config.h" diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_cleaner.cpp b/Telegram/SourceFiles/storage/cache/storage_cache_cleaner.cpp new file mode 100644 index 000000000..274185754 --- /dev/null +++ b/Telegram/SourceFiles/storage/cache/storage_cache_cleaner.cpp @@ -0,0 +1,113 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "storage/cache/storage_cache_cleaner.h" + +#include +#include +#include +#include +#include + +namespace Storage { +namespace Cache { +namespace details { + +class CleanerObject { +public: + using Wrapper = Cache::Cleaner; + CleanerObject( + crl::weak_on_queue weak, + const QString &base, + base::binary_guard &&guard, + FnMut done); + +private: + void start(); + void scheduleNext(); + void cleanNext(); + void done(); + + crl::weak_on_queue _weak; + QString _base, _errorPath; + std::vector _queue; + base::binary_guard _guard; + FnMut _done; + +}; + +CleanerObject::CleanerObject( + crl::weak_on_queue weak, + const QString &base, + base::binary_guard &&guard, + FnMut done) +: _weak(std::move(weak)) +, _base(base) +, _guard(std::move(guard)) +, _done(std::move(done)) { + start(); +} + +void CleanerObject::start() { + const auto entries = QDir(_base).entryList( + QDir::Dirs | QDir::NoDotAndDotDot); + for (const auto entry : entries) { + _queue.push_back(entry); + } + if (const auto version = ReadVersionValue(_base)) { + _queue.erase( + ranges::remove(_queue, QString::number(*version)), + end(_queue)); + scheduleNext(); + } else { + _errorPath = VersionFilePath(_base); + done(); + } +} + +void CleanerObject::scheduleNext() { + if (_queue.empty()) { + done(); + return; + } + _weak.with([](CleanerObject &that) { + if (that._guard.alive()) { + that.cleanNext(); + } + }); +} + +void CleanerObject::cleanNext() { + const auto path = _base + _queue.back(); + _queue.pop_back(); + if (!QDir(path).removeRecursively()) { + _errorPath = path; + } + scheduleNext(); +} + +void CleanerObject::done() { + if (_done) { + _done(_errorPath.isEmpty() + ? Error::NoError() + : Error{ Error::Type::IO, _errorPath }); + } +} + +} // namespace details + +Cleaner::Cleaner( + const QString &base, + base::binary_guard &&guard, + FnMut done) +: _wrapped(base, std::move(guard), std::move(done)) { +} + +Cleaner::~Cleaner() = default; + +} // namespace Cache +} // namespace Storage diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_cleaner.h b/Telegram/SourceFiles/storage/cache/storage_cache_cleaner.h new file mode 100644 index 000000000..cc2d8441f --- /dev/null +++ b/Telegram/SourceFiles/storage/cache/storage_cache_cleaner.h @@ -0,0 +1,35 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "storage/cache/storage_cache_types.h" +#include "base/binary_guard.h" + +namespace Storage { +namespace Cache { +namespace details { +class CleanerObject; +} // namespace details + +class Cleaner { +public: + Cleaner( + const QString &base, + base::binary_guard &&guard, + FnMut done); + + ~Cleaner(); + +private: + using Implementation = details::CleanerObject; + crl::object_on_queue _wrapped; + +}; + +} // namespace Cache +} // namespace Storage diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp b/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp index 0368dd267..ad558cc96 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp +++ b/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "storage/cache/storage_cache_database.h" +#include "storage/cache/storage_cache_cleaner.h" #include "storage/storage_encryption.h" #include "storage/storage_encrypted_file.h" #include "base/flat_set.h" @@ -160,9 +161,11 @@ class Database { public: using Wrapper = Cache::Database; using Settings = Wrapper::Settings; - Database(const QString &path, const Settings &settings); + Database( + crl::weak_on_queue weak, + const QString &path, + const Settings &settings); - using Error = Wrapper::Error; void open(EncryptionKey key, FnMut done); void close(FnMut done); @@ -173,7 +176,6 @@ public: void clear(FnMut done); private: - using Version = int32; struct Entry { Entry() = default; Entry(PlaceId place, uint8 tag, uint32 checksum, size_type size); @@ -183,6 +185,10 @@ private: size_type size = 0; PlaceId place = { { 0 } }; }; + struct CleanerWrap { + std::unique_ptr object; + base::binary_guard guard; + }; template void invokeCallback(Callback &&callback, Args &&...args); @@ -215,6 +221,10 @@ private: QString writeKeyPlace(const Key &key, size_type size, uint32 checksum); void writeMultiRemove(); + void createCleaner(); + void cleanerDone(Error error); + + crl::weak_on_queue _weak; QString _base, _path; Settings _settings; EncryptionKey _key; @@ -222,6 +232,8 @@ private: std::unordered_map _map; std::set _removing; + CleanerWrap _cleaner; + }; Database::Entry::Entry( @@ -235,8 +247,12 @@ Database::Entry::Entry( , size(size) { } -Database::Database(const QString &path, const Settings &settings) -: _base(QDir(path).absolutePath() + '/') +Database::Database( + crl::weak_on_queue weak, + const QString &path, + const Settings &settings) +: _weak(std::move(weak)) +, _base(ComputeBasePath(path)) , _settings(settings) { } @@ -253,7 +269,7 @@ void Database::invokeCallback(Callback &&callback, Args &&...args) { } } -auto Database::ioError(const QString &path) const -> Error { +Error Database::ioError(const QString &path) const { return { Error::Type::IO, path }; } @@ -276,15 +292,15 @@ void Database::open(EncryptionKey key, FnMut done) { break; case File::Result::Failed: { const auto available = findAvailableVersion(); - const auto retry = openBinlog(available, File::Mode::Write, key); - if (retry == File::Result::Success) { - if (writeVersion(available)) { + if (writeVersion(available)) { + const auto open = openBinlog(available, File::Mode::Write, key); + if (open == File::Result::Success) { invokeCallback(done, Error::NoError()); } else { - invokeCallback(done, ioError(versionPath())); + invokeCallback(done, ioError(binlogPath(available))); } } else { - invokeCallback(done, ioError(binlogPath(available))); + invokeCallback(done, ioError(versionPath())); } } break; default: Unexpected("Result from Database::openBinlog."); @@ -296,7 +312,7 @@ QString Database::computePath(Version version) const { } QString Database::binlogFilename() const { - return qsl("binlog"); + return QStringLiteral("binlog"); } QString Database::binlogPath(Version version) const { @@ -316,6 +332,7 @@ File::Result Database::openBinlog( if (result == File::Result::Success) { _path = computePath(version); _key = std::move(key); + createCleaner(); readBinlog(); } return result; @@ -466,6 +483,7 @@ bool Database::readRecordMultiRemove(bytes::const_span data) { } void Database::close(FnMut done) { + _cleaner = CleanerWrap(); _binlog.close(); invokeCallback(done); } @@ -604,6 +622,24 @@ void Database::writeMultiRemove() { } } +void Database::createCleaner() { + auto [left, right] = base::make_binary_guard(); + _cleaner.guard = std::move(left); + auto done = [weak = _weak](Error error) { + weak.with([=](Database &that) { + that.cleanerDone(error); + }); + }; + _cleaner.object = std::make_unique( + _base, + std::move(right), + std::move(done)); +} + +void Database::cleanerDone(Error error) { + _cleaner = CleanerWrap(); +} + void Database::clear(FnMut done) { Expects(_key.empty()); @@ -631,36 +667,18 @@ auto Database::findAvailableVersion() const -> Version { } QString Database::versionPath() const { - return _base + "version"; + return VersionFilePath(_base); } bool Database::writeVersion(Version version) { - const auto bytes = QByteArray::fromRawData( - reinterpret_cast(&version), - sizeof(version)); - - if (!QDir().mkpath(_base)) { - return false; - } - QFile file(versionPath()); - if (!file.open(QIODevice::WriteOnly)) { - return false; - } else if (file.write(bytes) != bytes.size()) { - return false; - } - return file.flush(); + return WriteVersionValue(_base, version); } auto Database::readVersion() const -> Version { - QFile file(versionPath()); - if (!file.open(QIODevice::ReadOnly)) { - return Version(); + if (const auto result = ReadVersionValue(_base)) { + return *result; } - const auto bytes = file.read(sizeof(Version)); - if (bytes.size() != sizeof(Version)) { - return Version(); - } - return *reinterpret_cast(bytes.data()); + return Version(); } QString Database::placePath(PlaceId place) const { diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_database.h b/Telegram/SourceFiles/storage/cache/storage_cache_database.h index ca1e7a854..f1b76dcf9 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_database.h +++ b/Telegram/SourceFiles/storage/cache/storage_cache_database.h @@ -7,7 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" +#include "storage/cache/storage_cache_types.h" +#include "base/basic_types.h" #include #include @@ -42,20 +43,6 @@ public: }; Database(const QString &path, const Settings &settings); - struct Error { - enum class Type { - None, - IO, - WrongKey, - LockFailed, - }; - Type type = Type::None; - QString path; - - static Error NoError() { - return Error(); - } - }; void open(EncryptionKey key, FnMut done); void close(FnMut done); diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_database_tests.cpp b/Telegram/SourceFiles/storage/cache/storage_cache_database_tests.cpp index 8aa49f68e..51f2bcdbf 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_database_tests.cpp +++ b/Telegram/SourceFiles/storage/cache/storage_cache_database_tests.cpp @@ -9,8 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/cache/storage_cache_database.h" #include "storage/storage_encryption.h" - #include +#include using namespace Storage::Cache; @@ -29,8 +29,8 @@ const auto TestValue2 = QByteArray("bytetestbytetestb"); crl::semaphore Semaphore; -auto Result = Database::Error(); -const auto GetResult = [](Database::Error error) { +auto Result = Error(); +const auto GetResult = [](Error error) { Result = error; Semaphore.release(); }; @@ -49,15 +49,15 @@ TEST_CASE("encrypted cache db", "[storage_cache_database]") { db.clear(GetResult); Semaphore.acquire(); - REQUIRE(Result.type == Database::Error::Type::None); + REQUIRE(Result.type == Error::Type::None); db.open(key, GetResult); Semaphore.acquire(); - REQUIRE(Result.type == Database::Error::Type::None); + REQUIRE(Result.type == Error::Type::None); db.put(Key{ 0, 1 }, TestValue1, GetResult); Semaphore.acquire(); - REQUIRE(Result.type == Database::Error::Type::None); + REQUIRE(Result.type == Error::Type::None); db.close([&] { Semaphore.release(); }); Semaphore.acquire(); @@ -67,7 +67,7 @@ TEST_CASE("encrypted cache db", "[storage_cache_database]") { db.open(key, GetResult); Semaphore.acquire(); - REQUIRE(Result.type == Database::Error::Type::None); + REQUIRE(Result.type == Error::Type::None); db.get(Key{ 0, 1 }, GetValue); Semaphore.acquire(); @@ -75,7 +75,7 @@ TEST_CASE("encrypted cache db", "[storage_cache_database]") { db.put(Key{ 1, 0 }, TestValue2, GetResult); Semaphore.acquire(); - REQUIRE(Result.type == Database::Error::Type::None); + REQUIRE(Result.type == Error::Type::None); db.get(Key{ 1, 0 }, GetValue); Semaphore.acquire(); @@ -93,7 +93,7 @@ TEST_CASE("encrypted cache db", "[storage_cache_database]") { db.open(key, GetResult); Semaphore.acquire(); - REQUIRE(Result.type == Database::Error::Type::None); + REQUIRE(Result.type == Error::Type::None); db.get(Key{ 0, 1 }, GetValue); Semaphore.acquire(); diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_types.cpp b/Telegram/SourceFiles/storage/cache/storage_cache_types.cpp new file mode 100644 index 000000000..d4f06a37d --- /dev/null +++ b/Telegram/SourceFiles/storage/cache/storage_cache_types.cpp @@ -0,0 +1,55 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "storage/cache/storage_cache_types.h" + +#include + +namespace Storage { +namespace Cache { + +QString ComputeBasePath(const QString &original) { + const auto result = QDir(original).absolutePath(); + return result.endsWith('/') ? result : (result + '/'); +} + +QString VersionFilePath(const QString &base) { + Expects(base.endsWith('/')); + + return base + QStringLiteral("version"); +} + +base::optional ReadVersionValue(const QString &base) { + QFile file(VersionFilePath(base)); + if (!file.open(QIODevice::ReadOnly)) { + return base::none; + } + const auto bytes = file.read(sizeof(Version)); + if (bytes.size() != sizeof(Version)) { + return base::none; + } + return *reinterpret_cast(bytes.data()); +} + +bool WriteVersionValue(const QString &base, Version value) { + if (!QDir().mkpath(base)) { + return false; + } + const auto bytes = QByteArray::fromRawData( + reinterpret_cast(&value), + sizeof(value)); + QFile file(VersionFilePath(base)); + if (!file.open(QIODevice::WriteOnly)) { + return false; + } else if (file.write(bytes) != bytes.size()) { + return false; + } + return file.flush(); +} + +} // namespace Cache +} // namespace Storage diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_types.h b/Telegram/SourceFiles/storage/cache/storage_cache_types.h new file mode 100644 index 000000000..6e7acebe9 --- /dev/null +++ b/Telegram/SourceFiles/storage/cache/storage_cache_types.h @@ -0,0 +1,41 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "base/basic_types.h" +#include "base/optional.h" + +namespace Storage { +namespace Cache { + +using Version = int32; + +QString ComputeBasePath(const QString &original); +QString VersionFilePath(const QString &base); +base::optional ReadVersionValue(const QString &base); +bool WriteVersionValue(const QString &base, Version value); + +struct Error { + enum class Type { + None, + IO, + WrongKey, + LockFailed, + }; + Type type = Type::None; + QString path; + + static Error NoError(); +}; + +inline Error Error::NoError() { + return Error(); +} + +} // namespace Cache +} // namespace Storage diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index 9523dce68..f6a10f9b9 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" #include "storage/file_download.h" #include "auth_session.h" diff --git a/Telegram/SourceFiles/storage/storage_file_lock.h b/Telegram/SourceFiles/storage/storage_file_lock.h index 3bc216cef..181b5bc06 100644 --- a/Telegram/SourceFiles/storage/storage_file_lock.h +++ b/Telegram/SourceFiles/storage/storage_file_lock.h @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" +#include "base/basic_types.h" #include namespace Storage { diff --git a/Telegram/SourceFiles/ui/animation.h b/Telegram/SourceFiles/ui/animation.h index d3ec514d2..fb2e0be23 100644 --- a/Telegram/SourceFiles/ui/animation.h +++ b/Telegram/SourceFiles/ui/animation.h @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/basic_types.h" #include #include diff --git a/Telegram/gyp/lib_storage.gyp b/Telegram/gyp/lib_storage.gyp index 3de805d0c..a86f0ef63 100644 --- a/Telegram/gyp/lib_storage.gyp +++ b/Telegram/gyp/lib_storage.gyp @@ -52,8 +52,12 @@ '<(src_loc)/storage/storage_file_lock_posix.cpp', '<(src_loc)/storage/storage_file_lock_win.cpp', '<(src_loc)/storage/storage_file_lock.h', + '<(src_loc)/storage/cache/storage_cache_cleaner.cpp', + '<(src_loc)/storage/cache/storage_cache_cleaner.h', '<(src_loc)/storage/cache/storage_cache_database.cpp', '<(src_loc)/storage/cache/storage_cache_database.h', + '<(src_loc)/storage/cache/storage_cache_types.cpp', + '<(src_loc)/storage/cache/storage_cache_types.h', ], 'conditions': [[ 'build_macold', { 'xcode_settings': { diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 61dda8609..b7ed26ab0 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -1,5 +1,7 @@ <(src_loc)/base/algorithm.h <(src_loc)/base/assertion.h +<(src_loc)/base/basic_types.h +<(src_loc)/base/binary_guard.h <(src_loc)/base/build_config.h <(src_loc)/base/bytes.h <(src_loc)/base/flags.h @@ -136,7 +138,6 @@ <(src_loc)/chat_helpers/tabbed_section.h <(src_loc)/chat_helpers/tabbed_selector.cpp <(src_loc)/chat_helpers/tabbed_selector.h -<(src_loc)/core/basic_types.h <(src_loc)/core/changelogs.cpp <(src_loc)/core/changelogs.h <(src_loc)/core/click_handler.cpp