Skip to content

Commit 6073288

Browse files
committed
Merge branch 'task/SDK-3990_Provide-public-method-to-export-legacy-rules' into 'release/v7.12.0'
SDK-3990. Provide public method to export legacy exclusion rules [MR for release v7.12.0] See merge request sdk/sdk!5883
2 parents 82017ec + 307575e commit 6073288

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed

include/mega/sync.h

+1
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ struct Syncs
12331233

12341234
string exportSyncConfigs(const SyncConfigVector configs) const;
12351235
string exportSyncConfigs() const;
1236+
error createMegaignoreFromLegacyExclusions(const LocalPath& targetPath);
12361237

12371238
void importSyncConfigs(const char* data, std::function<void(error)> completion);
12381239

include/megaapi.h

+24
Original file line numberDiff line numberDiff line change
@@ -16990,6 +16990,30 @@ class MegaApi
1699016990
*/
1699116991
void setLegacyExclusionUpperSizeLimit(unsigned long long limit);
1699216992

16993+
/**
16994+
* @brief Create a .megaignore file using legacy exclusion rules.
16995+
*
16996+
* Absolute paths included in the legacy rules will only be included
16997+
* if they are contained in the absolute path passed to the function.
16998+
*
16999+
* Ex:
17000+
* 1. Legacy excluded path: "/home/user/someSync/folder1*"
17001+
* 2. Param absolutePath: "/home/user/someSync"
17002+
* 3. Path "folder1*" will be included in the .megaignore created at "someSync".
17003+
*
17004+
* Possible return values for this function are:
17005+
* - MegaError::API_OK if the megaignore file was successfuly written.
17006+
* - MegaError::API_EARGS if absolutePath is empty or invalid.
17007+
* - MegaError::API_EACCESS if there was a problem writing the megaignore file.
17008+
* - MegaError::API_EEXIST if the megaignore file already exists.
17009+
*
17010+
* The caller takes ownership of the returned value.
17011+
*
17012+
* @param absolutePath Absolute path where the .megaignore file is going to be created.
17013+
* @return MegaError::API_OK if the file was created, otherwise it returns an error.
17014+
*/
17015+
MegaError* exportLegacyExclusionRules(const char* absolutePath);
17016+
1699317017
/**
1699417018
* @brief Check if it's possible to start synchronizing a folder node.
1699517019
*

include/megaapi_impl.h

+1
Original file line numberDiff line numberDiff line change
@@ -3470,6 +3470,7 @@ class MegaApiImpl : public MegaApp
34703470
void setLegacyExcludedPaths(vector<string> *excludedPaths);
34713471
void setLegacyExclusionLowerSizeLimit(unsigned long long limit);
34723472
void setLegacyExclusionUpperSizeLimit(unsigned long long limit);
3473+
MegaError* exportLegacyExclusionRules(const char* absolutePath);
34733474
long long getNumLocalNodes();
34743475
int isNodeSyncable(MegaNode *megaNode);
34753476
MegaError *isNodeSyncableWithError(MegaNode* node);

src/megaapi.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3896,6 +3896,11 @@ void MegaApi::setLegacyExclusionUpperSizeLimit(unsigned long long limit)
38963896
{
38973897
pImpl->setLegacyExclusionUpperSizeLimit(limit);
38983898
}
3899+
3900+
MegaError* MegaApi::exportLegacyExclusionRules(const char* absolutePath)
3901+
{
3902+
return pImpl->exportLegacyExclusionRules(absolutePath);
3903+
}
38993904
#endif
39003905

39013906

src/megaapi_impl.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -9883,6 +9883,20 @@ void MegaApiImpl::setLegacyExclusionUpperSizeLimit(unsigned long long limit)
98839883
client->syncs.mLegacyUpgradeFilterChain.upperLimit(limit);
98849884
}
98859885

9886+
MegaError* MegaApiImpl::exportLegacyExclusionRules(const char* absolutePath)
9887+
{
9888+
SdkMutexGuard guard(sdkMutex);
9889+
9890+
if (!absolutePath || !*absolutePath)
9891+
{
9892+
return new MegaErrorPrivate(API_EARGS);
9893+
}
9894+
9895+
auto lp = LocalPath::fromAbsolutePath(absolutePath);
9896+
auto result = client->syncs.createMegaignoreFromLegacyExclusions(lp);
9897+
return new MegaErrorPrivate(result);
9898+
}
9899+
98869900
long long MegaApiImpl::getNumLocalNodes()
98879901
{
98889902
return client->syncs.totalLocalNodes;

src/sync.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -3753,6 +3753,33 @@ void Syncs::confirmOrCreateDefaultMegaignore(bool transitionToMegaignore, unique
37533753
}
37543754
}
37553755

3756+
error Syncs::createMegaignoreFromLegacyExclusions(const LocalPath& targetPath)
3757+
{
3758+
LOG_info << "Writing .megaignore with legacy exclusion rules at " << targetPath;
3759+
3760+
// Check whether the file already exists
3761+
auto targetPathWithFileName = targetPath;
3762+
targetPathWithFileName.appendWithSeparator(IGNORE_FILE_NAME, false);
3763+
if (fsaccess->fileExistsAt(targetPathWithFileName))
3764+
{
3765+
LOG_err << "Failed to write " << targetPathWithFileName
3766+
<< " because the file already exists";
3767+
return API_EEXIST;
3768+
}
3769+
3770+
// Safely copy the legacy filter chain
3771+
auto legacyFilterChain = std::make_unique<DefaultFilterChain>(mLegacyUpgradeFilterChain);
3772+
3773+
// Write the file
3774+
if (!legacyFilterChain->create(targetPath, true, *fsaccess, false))
3775+
{
3776+
LOG_err << "Failed to write " << targetPath;
3777+
return API_EACCESS;
3778+
}
3779+
3780+
return API_OK;
3781+
}
3782+
37563783
void Syncs::enableSyncByBackupId(handle backupId, bool setOriginalPath, std::function<void(error, SyncError, handle)> completion, bool completionInClient, const string& logname)
37573784
{
37583785
assert(!onSyncThread());

0 commit comments

Comments
 (0)