From 707429218467eab02090bfeea2e3d14aac020910 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Wed, 19 Jun 2019 09:59:13 +0300 Subject: [PATCH] Forbidden cloud backup for paid bookmarks --- map/bookmark_manager.cpp | 16 ++++++++++++++++ map/cloud.cpp | 16 ++++++++++++++-- map/cloud.hpp | 4 +++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 50c50d698f..331b9f7ccd 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -172,6 +172,14 @@ Cloud::ConvertionResult ConvertBeforeUploading(std::string const & filePath, if (kmlData == nullptr) return {}; + // Skip paid bookmarks. + if (kmlData->m_categoryData.m_accessRules == kml::AccessRules::Paid) + { + Cloud::ConvertionResult r; + r.m_needSkip = true; + return r; + } + if (!SaveKmlFile(*kmlData, tmpFilePath, KmlFileType::Text)) return {}; @@ -189,6 +197,14 @@ Cloud::ConvertionResult ConvertAfterDownloading(std::string const & filePath, auto kmlData = LoadKmzFile(filePath, hash); if (kmlData == nullptr) return {}; + + // Skip paid bookmarks. + if (kmlData->m_categoryData.m_accessRules == kml::AccessRules::Paid) + { + Cloud::ConvertionResult r; + r.m_needSkip = true; + return r; + } Cloud::ConvertionResult result; result.m_hash = hash; diff --git a/map/cloud.cpp b/map/cloud.cpp index 25cb872cdf..48fdf9119e 100644 --- a/map/cloud.cpp +++ b/map/cloud.cpp @@ -682,14 +682,19 @@ void Cloud::ScheduleUploadingTask(EntryPtr const & entry, uint32_t timeout) } // Prepare file to uploading. + bool needSkip; std::string hash; - auto const uploadedName = PrepareFileToUploading(entryName, hash); + auto const uploadedName = PrepareFileToUploading(entryName, hash, needSkip); auto deleteAfterUploading = [uploadedName]() { if (!uploadedName.empty()) base::DeleteFileX(uploadedName); }; SCOPE_GUARD(deleteAfterUploadingGuard, deleteAfterUploading); + // This file must be skipped by some reason. + if (needSkip) + return; + if (uploadedName.empty()) { FinishUploading(SynchronizationResult::DiskError, "File preparation error"); @@ -810,7 +815,8 @@ void Cloud::FinishUploadingOnRequestError(Cloud::RequestResult const & result) } } -std::string Cloud::PrepareFileToUploading(std::string const & fileName, std::string & hash) +std::string Cloud::PrepareFileToUploading(std::string const & fileName, std::string & hash, + bool & needSkip) { // 1. Get path to the original uploading file. std::string filePath; @@ -849,6 +855,7 @@ std::string Cloud::PrepareFileToUploading(std::string const & fileName, std::str // 5. Convert temporary file and save to output path. CHECK(m_params.m_backupConverter, ()); auto const convertionResult = m_params.m_backupConverter(tmpPath, outputPath); + needSkip = convertionResult.m_needSkip; hash = convertionResult.m_hash; if (convertionResult.m_isSuccessful) return outputPath; @@ -1478,6 +1485,11 @@ void Cloud::CompleteRestoring(std::string const & dirPath) auto const fn = f.m_fileName + ".converted"; auto const convertedFile = base::JoinPath(dirPath, fn); auto const convertionResult = m_params.m_restoreConverter(restoringFile, convertedFile); + + // This file must be skipped by some reason. + if (convertionResult.m_needSkip) + continue; + if (!convertionResult.m_isSuccessful) { FinishRestoring(SynchronizationResult::DiskError, "Restored file conversion error"); diff --git a/map/cloud.hpp b/map/cloud.hpp index a3fb2bb88b..66ba7ccfa8 100644 --- a/map/cloud.hpp +++ b/map/cloud.hpp @@ -200,6 +200,7 @@ public: { bool m_isSuccessful = false; std::string m_hash; + bool m_needSkip = false; }; using InvalidTokenHandler = std::function; @@ -325,7 +326,8 @@ private: // This function always returns path to a temporary file or the empty string // in case of a disk error. - std::string PrepareFileToUploading(std::string const & fileName, std::string & hash); + std::string PrepareFileToUploading(std::string const & fileName, std::string & hash, + bool & needSkip); RequestResult CreateSnapshot(std::vector const & files) const; RequestResult FinishSnapshot() const;