# HG changeset patch # User Nicholas R. Jankowski # Date 1544576890 28800 # Node ID b964092ad9f81bc3b303ade9d16605f888a72f3c # Parent aaa23f9845dd8d00a2fe6404893418ff6e3e86be pkg.m: Allow updating a list of supplied packages, instead of all (bug #48151). * pkg.m: Delete code emitting an error if package names are supplied for "update" command. Add code to compare list of package names to list of installed packages and only update installed packages. diff -r aaa23f9845dd -r b964092ad9f8 scripts/pkg/pkg.m --- a/scripts/pkg/pkg.m Tue Dec 11 16:00:43 2018 -0800 +++ b/scripts/pkg/pkg.m Tue Dec 11 17:08:10 2018 -0800 @@ -560,12 +560,21 @@ case "update" installed_pkgs_lst = installed_packages (local_list, global_list); + ## Explicit list of packages to update, rather than all packages if (numel (files) > 0) - ## This was option was broken during two releases and no one - ## notice so we are guessing no one actually uses it. If the - ## user knows the names of the packages to be installed, it - ## might as well call install (which is what update is doing) - error ("pkg: to update individual packages, use 'pkg install -forge'"); + update_lst = {}; + installed_names = cellfun (@(idx) idx.name, installed_pkgs_lst, + "UniformOutput", false); + for i = 1:numel (files) + idx = find (strcmp (files{i}, installed_names), 1); + if (isempty (idx)) + warning ("pkg: package %s is not installed - skipping update", + files{i}); + else + update_lst = [ update_lst, installed_pkgs_lst(idx) ]; + endif + endfor + installed_pkgs_lst = update_lst; endif for i = 1:numel (installed_pkgs_lst)