Forbidden cloud backup for paid bookmarks

This commit is contained in:
r.kuznetsov 2019-06-19 09:59:13 +03:00 committed by Daria Volvenkova
parent 9994dc2104
commit 7074292184
3 changed files with 33 additions and 3 deletions

View file

@ -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;

View file

@ -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");

View file

@ -200,6 +200,7 @@ public:
{
bool m_isSuccessful = false;
std::string m_hash;
bool m_needSkip = false;
};
using InvalidTokenHandler = std::function<void()>;
@ -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<std::string> const & files) const;
RequestResult FinishSnapshot() const;