mirror of
https://github.com/meganz/MEGAcmd
synced 2025-08-29 12:57:44 +00:00
Merge branch 'task/CMD-625_avoid-double-errors-on-mount-actions' into 'develop'
CMD-625 [to develop] avoid broadcasting mount errors while operating on mounts Closes CMD-625 See merge request apps/MEGAcmd!879
This commit is contained in:
commit
f359a9c31a
@ -452,6 +452,8 @@ void MegaCmdMegaListener::onRequestFinish(MegaApi *api, MegaRequest *request, Me
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::atomic<int> DisableMountErrorsBroadcastingGuard::sDisableBroadcasting = 0;
|
||||||
|
|
||||||
MegaCmdMegaListener::MegaCmdMegaListener(MegaApi *megaApi, MegaListener *parent, MegaCmdSandbox *sandboxCMD)
|
MegaCmdMegaListener::MegaCmdMegaListener(MegaApi *megaApi, MegaListener *parent, MegaCmdSandbox *sandboxCMD)
|
||||||
{
|
{
|
||||||
this->megaApi = megaApi;
|
this->megaApi = megaApi;
|
||||||
@ -587,7 +589,10 @@ void MegaCmdMegaListener::onMountEvent(std::string_view pastTense, std::string_v
|
|||||||
const std::string msg = oss.str();
|
const std::string msg = oss.str();
|
||||||
|
|
||||||
LOG_err << msg;
|
LOG_err << msg;
|
||||||
broadcastDelayedMessage(msg, true);
|
if (DisableMountErrorsBroadcastingGuard::shouldBroadcast())
|
||||||
|
{
|
||||||
|
broadcastDelayedMessage(msg, true);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +221,15 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DisableMountErrorsBroadcastingGuard
|
||||||
|
{
|
||||||
|
static std::atomic<int> sDisableBroadcasting;
|
||||||
|
public:
|
||||||
|
DisableMountErrorsBroadcastingGuard() { sDisableBroadcasting++; }
|
||||||
|
~DisableMountErrorsBroadcastingGuard() { sDisableBroadcasting--; }
|
||||||
|
|
||||||
|
static bool shouldBroadcast() { return sDisableBroadcasting == 0; }
|
||||||
|
};
|
||||||
|
|
||||||
class MegaCmdMegaListener : public mega::MegaListener
|
class MegaCmdMegaListener : public mega::MegaListener
|
||||||
{
|
{
|
||||||
|
@ -201,10 +201,13 @@ void addMount(mega::MegaApi& api, const fs::path& localPath, MegaNode& node, boo
|
|||||||
auto mount = createMount(localPath, node, disabled, transient, readOnly, name);
|
auto mount = createMount(localPath, node, disabled, transient, readOnly, name);
|
||||||
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
||||||
|
|
||||||
api.addMount(mount.get(), listener.get());
|
|
||||||
if (!checkNoErrors(listener.get(), getActionString("add", localPath, nodePath)))
|
|
||||||
{
|
{
|
||||||
return;
|
DisableMountErrorsBroadcastingGuard disableErrorBroadcasting;
|
||||||
|
api.addMount(mount.get(), listener.get());
|
||||||
|
if (!checkNoErrors(listener.get(), getActionString("add", localPath, nodePath)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string mountLocalPath = listener->getRequest()->getFile();
|
const std::string mountLocalPath = listener->getRequest()->getFile();
|
||||||
@ -233,10 +236,13 @@ void removeMount(mega::MegaApi& api, const mega::MegaMount& mount)
|
|||||||
{
|
{
|
||||||
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
||||||
|
|
||||||
api.removeMount(mount.getFlags()->getName(), listener.get());
|
|
||||||
if (!checkNoErrors(listener.get(), getActionString("remove", mount)))
|
|
||||||
{
|
{
|
||||||
return;
|
DisableMountErrorsBroadcastingGuard disableErrorBroadcasting;
|
||||||
|
api.removeMount(mount.getFlags()->getName(), listener.get());
|
||||||
|
if (!checkNoErrors(listener.get(), getActionString("remove", mount)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTSTREAM << "Removed mount " << getMountId(mount) << " on \"" << mount.getPath() << '"' << endl;
|
OUTSTREAM << "Removed mount " << getMountId(mount) << " on \"" << mount.getPath() << '"' << endl;
|
||||||
@ -247,10 +253,14 @@ void enableMount(mega::MegaApi& api, const mega::MegaMount& mount, bool temporar
|
|||||||
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
||||||
const bool remember = shouldRememberChange(mount, temporarily);
|
const bool remember = shouldRememberChange(mount, temporarily);
|
||||||
|
|
||||||
api.enableMount(mount.getFlags()->getName(), listener.get(), remember);
|
|
||||||
if (!checkNoErrors(listener.get(), getActionString("enable", mount)))
|
|
||||||
{
|
{
|
||||||
return;
|
DisableMountErrorsBroadcastingGuard disableErrorBroadcasting;
|
||||||
|
api.enableMount(mount.getFlags()->getName(), listener.get(), remember);
|
||||||
|
if (!checkNoErrors(listener.get(), getActionString("enable", mount)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTSTREAM << (temporarily ? "Temporarily enabled" : "Enabled") << " mount "
|
OUTSTREAM << (temporarily ? "Temporarily enabled" : "Enabled") << " mount "
|
||||||
@ -262,10 +272,14 @@ void disableMount(mega::MegaApi& api, const mega::MegaMount& mount, bool tempora
|
|||||||
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
||||||
const bool remember = shouldRememberChange(mount, temporarily);
|
const bool remember = shouldRememberChange(mount, temporarily);
|
||||||
|
|
||||||
api.disableMount(mount.getFlags()->getName(), listener.get(), remember);
|
|
||||||
if (!checkNoErrors(listener.get(), getActionString("disable", mount)))
|
|
||||||
{
|
{
|
||||||
return;
|
DisableMountErrorsBroadcastingGuard disableErrorBroadcasting;
|
||||||
|
api.disableMount(mount.getFlags()->getName(), listener.get(), remember);
|
||||||
|
if (!checkNoErrors(listener.get(), getActionString("disable", mount)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTSTREAM << (temporarily ? "Temporarily disabled" : "Disabled") << " mount "
|
OUTSTREAM << (temporarily ? "Temporarily disabled" : "Disabled") << " mount "
|
||||||
@ -379,10 +393,14 @@ void changeConfig(mega::MegaApi& api, const mega::MegaMount& mount, const Config
|
|||||||
|
|
||||||
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
auto listener = std::make_unique<MegaCmdListener>(nullptr);
|
||||||
|
|
||||||
api.setMountFlags(flags, currentName.c_str(), listener.get());
|
|
||||||
if (!checkNoErrors(listener.get(), getActionString("change the flags of", mount)))
|
|
||||||
{
|
{
|
||||||
return;
|
DisableMountErrorsBroadcastingGuard disableErrorBroadcasting;
|
||||||
|
api.setMountFlags(flags, currentName.c_str(), listener.get());
|
||||||
|
if (!checkNoErrors(listener.get(), getActionString("change the flags of", mount)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTSTREAM << "Mount " << getMountId(mount) << " now has the following flags\n"
|
OUTSTREAM << "Mount " << getMountId(mount) << " now has the following flags\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user