Skip to content

Commit

Permalink
Merge branch 'task/SDK-3990_Provide-public-method-to-export-legacy-ru…
Browse files Browse the repository at this point in the history
…les' 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
  • Loading branch information
vmgaGH committed Oct 4, 2024
2 parents 82017ec + 307575e commit 6073288
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/mega/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ struct Syncs

string exportSyncConfigs(const SyncConfigVector configs) const;
string exportSyncConfigs() const;
error createMegaignoreFromLegacyExclusions(const LocalPath& targetPath);

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

Expand Down
24 changes: 24 additions & 0 deletions include/megaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -16990,6 +16990,30 @@ class MegaApi
*/
void setLegacyExclusionUpperSizeLimit(unsigned long long limit);

/**
* @brief Create a .megaignore file using legacy exclusion rules.
*
* Absolute paths included in the legacy rules will only be included
* if they are contained in the absolute path passed to the function.
*
* Ex:
* 1. Legacy excluded path: "/home/user/someSync/folder1*"
* 2. Param absolutePath: "/home/user/someSync"
* 3. Path "folder1*" will be included in the .megaignore created at "someSync".
*
* Possible return values for this function are:
* - MegaError::API_OK if the megaignore file was successfuly written.
* - MegaError::API_EARGS if absolutePath is empty or invalid.
* - MegaError::API_EACCESS if there was a problem writing the megaignore file.
* - MegaError::API_EEXIST if the megaignore file already exists.
*
* The caller takes ownership of the returned value.
*
* @param absolutePath Absolute path where the .megaignore file is going to be created.
* @return MegaError::API_OK if the file was created, otherwise it returns an error.
*/
MegaError* exportLegacyExclusionRules(const char* absolutePath);

/**
* @brief Check if it's possible to start synchronizing a folder node.
*
Expand Down
1 change: 1 addition & 0 deletions include/megaapi_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3470,6 +3470,7 @@ class MegaApiImpl : public MegaApp
void setLegacyExcludedPaths(vector<string> *excludedPaths);
void setLegacyExclusionLowerSizeLimit(unsigned long long limit);
void setLegacyExclusionUpperSizeLimit(unsigned long long limit);
MegaError* exportLegacyExclusionRules(const char* absolutePath);
long long getNumLocalNodes();
int isNodeSyncable(MegaNode *megaNode);
MegaError *isNodeSyncableWithError(MegaNode* node);
Expand Down
5 changes: 5 additions & 0 deletions src/megaapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3896,6 +3896,11 @@ void MegaApi::setLegacyExclusionUpperSizeLimit(unsigned long long limit)
{
pImpl->setLegacyExclusionUpperSizeLimit(limit);
}

MegaError* MegaApi::exportLegacyExclusionRules(const char* absolutePath)
{
return pImpl->exportLegacyExclusionRules(absolutePath);
}
#endif


Expand Down
14 changes: 14 additions & 0 deletions src/megaapi_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9883,6 +9883,20 @@ void MegaApiImpl::setLegacyExclusionUpperSizeLimit(unsigned long long limit)
client->syncs.mLegacyUpgradeFilterChain.upperLimit(limit);
}

MegaError* MegaApiImpl::exportLegacyExclusionRules(const char* absolutePath)
{
SdkMutexGuard guard(sdkMutex);

if (!absolutePath || !*absolutePath)
{
return new MegaErrorPrivate(API_EARGS);
}

auto lp = LocalPath::fromAbsolutePath(absolutePath);
auto result = client->syncs.createMegaignoreFromLegacyExclusions(lp);
return new MegaErrorPrivate(result);
}

long long MegaApiImpl::getNumLocalNodes()
{
return client->syncs.totalLocalNodes;
Expand Down
27 changes: 27 additions & 0 deletions src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3753,6 +3753,33 @@ void Syncs::confirmOrCreateDefaultMegaignore(bool transitionToMegaignore, unique
}
}

error Syncs::createMegaignoreFromLegacyExclusions(const LocalPath& targetPath)
{
LOG_info << "Writing .megaignore with legacy exclusion rules at " << targetPath;

// Check whether the file already exists
auto targetPathWithFileName = targetPath;
targetPathWithFileName.appendWithSeparator(IGNORE_FILE_NAME, false);
if (fsaccess->fileExistsAt(targetPathWithFileName))
{
LOG_err << "Failed to write " << targetPathWithFileName
<< " because the file already exists";
return API_EEXIST;
}

// Safely copy the legacy filter chain
auto legacyFilterChain = std::make_unique<DefaultFilterChain>(mLegacyUpgradeFilterChain);

// Write the file
if (!legacyFilterChain->create(targetPath, true, *fsaccess, false))
{
LOG_err << "Failed to write " << targetPath;
return API_EACCESS;
}

return API_OK;
}

void Syncs::enableSyncByBackupId(handle backupId, bool setOriginalPath, std::function<void(error, SyncError, handle)> completion, bool completionInClient, const string& logname)
{
assert(!onSyncThread());
Expand Down

0 comments on commit 6073288

Please sign in to comment.