@@ -528,6 +528,36 @@ def _restore_site(cmd, state):
528528 LOGGER .verbose ("TRACEBACK" , exc_info = True )
529529
530530
531+ def _sanitise_install (cmd , install ):
532+ """Prepares install metadata for storing locally.
533+
534+ This includes:
535+ * filtering out disabled shortcuts
536+ * preserving original shortcuts
537+ * sanitising URLs
538+ """
539+
540+ if "shortcuts" in install :
541+ # This saves our original set of shortcuts, so a later repair operation
542+ # can enable those that were originally disabled.
543+ shortcuts = install .setdefault ("__original-shortcuts" , install ["shortcuts" ])
544+ if cmd .enable_shortcut_kinds or cmd .disable_shortcut_kinds :
545+ orig_shortcuts = shortcuts
546+ shortcuts = []
547+ for s in orig_shortcuts :
548+ if cmd .enable_shortcut_kinds and s ["kind" ] not in cmd .enable_shortcut_kinds :
549+ continue
550+ if cmd .disable_shortcut_kinds and s ["kind" ] in cmd .disable_shortcut_kinds :
551+ continue
552+ shortcuts .append (s )
553+ install ["shortcuts" ] = shortcuts
554+
555+ install ["url" ] = sanitise_url (install ["url" ])
556+ # If there's a non-empty and non-default source, sanitise it
557+ if install .get ("source" ) and install ["source" ] != cmd .fallback_source :
558+ install ["source" ] = sanitise_url (install ["source" ])
559+
560+
531561def _install_one (cmd , source , install , * , target = None ):
532562 if cmd .repair :
533563 LOGGER .info ("Repairing %s." , install ['display-name' ])
@@ -596,21 +626,7 @@ def _install_one(cmd, source, install, *, target=None):
596626 )
597627 raise
598628
599- if "shortcuts" in install :
600- # This saves our original set of shortcuts, so a later repair operation
601- # can enable those that were originally disabled.
602- shortcuts = install .setdefault ("__original-shortcuts" , install ["shortcuts" ])
603- if cmd .enable_shortcut_kinds :
604- shortcuts = [s for s in shortcuts
605- if s ["kind" ] in cmd .enable_shortcut_kinds ]
606- if cmd .disable_shortcut_kinds :
607- shortcuts = [s for s in shortcuts
608- if s ["kind" ] not in cmd .disable_shortcut_kinds ]
609- install ["shortcuts" ] = shortcuts
610-
611- install ["url" ] = sanitise_url (install ["url" ])
612- if source != cmd .fallback_source :
613- install ["source" ] = sanitise_url (source )
629+ _sanitise_install (cmd , install )
614630
615631 LOGGER .debug ("Write __install__.json to %s" , dest )
616632 with open (dest / "__install__.json" , "w" , encoding = "utf-8" ) as f :
@@ -850,10 +866,12 @@ def execute(cmd):
850866 if cmd .download :
851867 LOGGER .info ("Downloading %s" , install ["display-name" ])
852868 package = _download_one (cmd , source , install , cmd .download , must_copy = True )
853- download_index [ "versions" ]. append ( {
869+ install_idx = {
854870 ** install ,
855871 "url" : package .name ,
856- })
872+ }
873+ install_idx .pop ("source" , None )
874+ download_index ["versions" ].append (install_idx )
857875 else :
858876 _install_one (cmd , source , install )
859877 except ArgumentError :
0 commit comments