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.
This commit is contained in:
Nick Craig-Wood
2026-07-20 17:37:16 +01:00
parent 4d6cc0ba1f
commit 74be61735c
+4 -1
View File
@@ -272,7 +272,6 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't login: %w", err) return nil, fmt.Errorf("couldn't login: %w", err)
} }
megaCache[opt.User] = srv
m.Set(sessionIDConfigKey, srv.GetSessionID()) m.Set(sessionIDConfigKey, srv.GetSessionID())
encodedMasterKey := base64.StdEncoding.EncodeToString(srv.GetMasterKey()) encodedMasterKey := base64.StdEncoding.EncodeToString(srv.GetMasterKey())
m.Set(masterKeyConfigKey, encodedMasterKey) 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) 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 f.srv = srv