diff --git a/src/dialogs/copyPasteOwnership.tsx b/src/dialogs/copyPasteOwnership.tsx index 251fb047..b9b472ea 100644 --- a/src/dialogs/copyPasteOwnership.tsx +++ b/src/dialogs/copyPasteOwnership.tsx @@ -71,7 +71,7 @@ async function pasteAsOwner(clipboard: ClipboardInfo, dstPath: string, owner: st } function makeCandidatesMap(currentUser: cockpit.UserInfo, cwdInfo: FileInfo, clipboard: ClipboardInfo) { - const map: Record = {}; + const map: Map = new Map(); const candidates = get_owner_candidates(currentUser, cwdInfo); // also add current ownership if it is same for all files (shallow check) @@ -91,7 +91,7 @@ function makeCandidatesMap(currentUser: cockpit.UserInfo, cwdInfo: FileInfo, cli key = `${key} ${_("(original owner)")}`; } - map[key] = owner; + map.set(key, owner); }); return map; @@ -114,11 +114,11 @@ const CopyPasteAsOwnerModal = ({ cockpit.user().then(user => setCurrentUser(user)); }, []); - let candidatesMap: Record = {}; + let candidatesMap: Map = new Map(); if (superuser.allowed && currentUser && cwdInfo) { candidatesMap = makeCandidatesMap(currentUser, cwdInfo, clipboard); if (selectedOwner === undefined) { - setSelectedOwner(Object.keys(candidatesMap)[0]); + setSelectedOwner(candidatesMap.keys().next().value); } } @@ -126,12 +126,15 @@ const CopyPasteAsOwnerModal = ({ return; } + const selectedVal = candidatesMap.get(selectedOwner); + cockpit.assert(selectedVal !== undefined, "New file ownership undefined"); + const modalFooter = ( <>