From 74be61735cbd7cc52075ffde98f55f09e2d5d82d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 20 Jul 2026 17:37:16 +0100 Subject: [PATCH] mega: fix moved files disappearing from listings between remotes The session cache was only populated on a fresh username and password login, so once a session ID was stored in the config every Fs instance created its own Mega session with its own copy of the account's node tree. The server side move code relies on all Fs instances of a user sharing one session, and with separate sessions a move between two rclone remotes grafted a node from one tree into another, where the asynchronous event replays of the two sessions raced and could detach the moved file from the destination directory so it disappeared from listings. Cache the session however the login was done. This also stops every extra Fs instance re-downloading the whole account node tree. --- backend/mega/mega.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/mega/mega.go b/backend/mega/mega.go index 297f62436..aabd559b1 100644 --- a/backend/mega/mega.go +++ b/backend/mega/mega.go @@ -272,7 +272,6 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e if err != nil { return nil, fmt.Errorf("couldn't login: %w", err) } - megaCache[opt.User] = srv m.Set(sessionIDConfigKey, srv.GetSessionID()) encodedMasterKey := base64.StdEncoding.EncodeToString(srv.GetMasterKey()) m.Set(masterKeyConfigKey, encodedMasterKey) @@ -287,6 +286,10 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e return nil, fmt.Errorf("login with previous auth keys failed: %w", err) } } + // Cache the session so all Fs instances of this user share + // it - the move code relies on all objects being in the same + // in-memory tree. + megaCache[opt.User] = srv } f.srv = srv