comparison scripts/pkg/private/uninstall.m @ 14466:cfb0173fe1ca

maint: Refactor pkg.m and move subfunctions to private/ directory. * pkg.m: move all sub-functions to private/ * pkg/private/absolute_pathname.m * pkg/private/build.m * pkg/private/configure_make.m * pkg/private/copy_files.m * pkg/private/create_pkgadddel.m * pkg/private/describe.m * pkg/private/dirempty.m * pkg/private/extract_pkg.m * pkg/private/finish_installation.m * pkg/private/fix_depends.m * pkg/private/fix_version.m * pkg/private/generate_lookfor_cache.m * pkg/private/get_description.m * pkg/private/get_forge_download.m * pkg/private/get_forge_pkg.m * pkg/private/getarch.m * pkg/private/getarchdir.m * pkg/private/getarchprefix.m * pkg/private/get_unsatisfied_deps.m * pkg/private/install.m * pkg/private/installed_packages.m * pkg/private/is_architecture_dependent.m * pkg/private/isautoload.m * pkg/private/issuperuser.m * pkg/private/list_forge_packages.m * pkg/private/load_package_dirs.m * pkg/private/load_packages.m * pkg/private/load_packages_and_dependencies.m * pkg/private/packinfo_copy_file.m * pkg/private/parse_pkg_idx.m * pkg/private/prepare_installation.m * pkg/private/print_package_description.m * pkg/private/rebuild.m * pkg/private/repackage.m * pkg/private/rm_rf.m * pkg/private/rstrip.m * pkg/private/save_order.m * pkg/private/shell.m * pkg/private/split_by.m * pkg/private/strip.m * pkg/private/uninstall.m * pkg/private/unload_packages.m * pkg/private/verify_directory.m * pkg/private/write_index.m
author Carlo de Falco <kingcrimson@tiscali.it>
date Thu, 15 Mar 2012 19:41:24 +0100
parents
children d2c095e45196
comparison
equal deleted inserted replaced
14465:16164cb3b713 14466:cfb0173fe1ca
1 ## Copyright (C) 2005-2012 S�ren Hauberg
2 ## Copyright (C) 2010 VZLU Prague, a.s.
3 ##
4 ## This file is part of Octave.
5 ##
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
10 ##
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
19
20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} uninstall (@var{pkgnames}, @var{handle_deps},
22 ## @var{verbose}, @var{local_list}, @var{global_list}, @var{global_install})
23 ## Undocumented internal function.
24 ## @end deftypefn
25
26 function uninstall (pkgnames, handle_deps, verbose, local_list,
27 global_list, global_install)
28 ## Get the list of installed packages.
29 [local_packages, global_packages] = installed_packages(local_list,
30 global_list);
31 if (global_install)
32 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
33 else
34 installed_pkgs_lst = local_packages;
35 endif
36
37 num_packages = length (installed_pkgs_lst);
38 delete_idx = [];
39 for i = 1:num_packages
40 cur_name = installed_pkgs_lst{i}.name;
41 if (any (strcmp (cur_name, pkgnames)))
42 delete_idx(end+1) = i;
43 endif
44 endfor
45
46 ## Are all the packages that should be uninstalled already installed?
47 if (length (delete_idx) != length (pkgnames))
48 if (global_install)
49 ## Try again for a locally installed package.
50 installed_pkgs_lst = local_packages;
51
52 num_packages = length (installed_pkgs_lst);
53 delete_idx = [];
54 for i = 1:num_packages
55 cur_name = installed_pkgs_lst{i}.name;
56 if (any (strcmp (cur_name, pkgnames)))
57 delete_idx(end+1) = i;
58 endif
59 endfor
60 if (length (delete_idx) != length (pkgnames))
61 ## FIXME: We should have a better error message.
62 warning ("some of the packages you want to uninstall are not installed");
63 endif
64 else
65 ## FIXME: We should have a better error message.
66 warning ("some of the packages you want to uninstall are not installed");
67 endif
68 endif
69
70 ## Compute the packages that will remain installed.
71 idx = setdiff (1:num_packages, delete_idx);
72 remaining_packages = {installed_pkgs_lst{idx}};
73
74 ## Check dependencies.
75 if (handle_deps)
76 error_text = "";
77 for i = 1:length (remaining_packages)
78 desc = remaining_packages{i};
79 bad_deps = get_unsatisfied_deps (desc, remaining_packages);
80
81 ## Will the uninstallation break any dependencies?
82 if (! isempty (bad_deps))
83 for i = 1:length (bad_deps)
84 dep = bad_deps{i};
85 error_text = cstrcat (error_text, " ", desc.name, " needs ",
86 dep.package, " ", dep.operator, " ",
87 dep.version, "\n");
88 endfor
89 endif
90 endfor
91
92 if (! isempty (error_text))
93 error ("the following dependencies where unsatisfied:\n %s", error_text);
94 endif
95 endif
96
97 ## Delete the directories containing the packages.
98 for i = delete_idx
99 desc = installed_pkgs_lst{i};
100 ## If an 'on_uninstall.m' exist, call it!
101 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file"))
102 wd = pwd ();
103 cd (fullfile (desc.dir, "packinfo"));
104 on_uninstall (desc);
105 cd (wd);
106 endif
107 ## Do the actual deletion.
108 if (desc.loaded)
109 rmpath (desc.dir);
110 if (exist (getarchdir (desc)))
111 rmpath (getarchdir (desc));
112 endif
113 endif
114 if (exist (desc.dir, "dir"))
115 [status, msg] = rm_rf (desc.dir);
116 if (status != 1)
117 error ("couldn't delete directory %s: %s", desc.dir, msg);
118 endif
119 [status, msg] = rm_rf (getarchdir (desc));
120 if (status != 1)
121 error ("couldn't delete directory %s: %s", getarchdir (desc), msg);
122 endif
123 if (dirempty (desc.archprefix))
124 rm_rf (desc.archprefix);
125 endif
126 else
127 warning ("directory %s previously lost", desc.dir);
128 endif
129 endfor
130
131 ## Write a new ~/.octave_packages.
132 if (global_install)
133 if (length (remaining_packages) == 0)
134 unlink (global_list);
135 else
136 global_packages = save_order (remaining_packages);
137 save (global_list, "global_packages");
138 endif
139 else
140 if (length (remaining_packages) == 0)
141 unlink (local_list);
142 else
143 local_packages = save_order (remaining_packages);
144 save (local_list, "local_packages");
145 endif
146 endif
147
148 endfunction