1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 // Return a matrix that list the changes caused by the uninstallation of one or
15 // -->A = atomsRemoveList('toolbox_2',%F)
18 // !- U toolbox_2 1.5 !
20 // !- U toolbox_2 1.3 !
22 // !- B toolbox_3 1.6 !
24 // !- B toolbox_5 1.0 !
26 // !- B toolbox_4 1.0 !
28 // - : The package will be removed
29 // ~ : The package will be keeped
31 // U : The package is intentionnaly removed
32 // P : The package is a parent of one package
33 // C : The package is a child of one package
34 // B : The package will be broken (It's a parent but cannot be uninstall)
36 function remList = atomsRemoveList(packages,allusers)
40 // Save the initial path
41 // =========================================================================
44 // Check input parameters
45 // =========================================================================
50 error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"atomsRemoveList",1,2))
53 if type(packages) <> 10 then
54 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsRemoveList",1));
57 // Apply changes for all users or just for me ?
58 // =========================================================================
61 // By default, uninstall the package (if we have write access
63 if atomsAUWriteAccess() then
70 // Just check if it's a boolean
71 if type(allusers) <> 4 then
73 error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsRemoveList",2));
76 // Check if we have the write access
77 if allusers & ~ atomsAUWriteAccess() then
79 error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsRemoveList",2,pathconvert(SCI+"/.atoms")));
83 // Loop on packages and to build the list of package to uninstall
84 // =========================================================================
86 packages = stripblanks(packages);
88 // First step : List the packages wanted by the user
90 for i=1:size(packages,"*")
92 package = packages(i);
94 if size(regexp(package,"/\s/") ,"*" ) > 1 then
95 error(msprintf(gettext("%s: Wrong value for input argument #%d: it must contain at most one space.\n"),"atomsInstall",1));
98 if size(regexp(package,"/\s/") ,"*" ) == 0 then
99 // Just the toolbox name is specified
100 package_names(i) = package;
101 package_versions(i) = "";
103 // A version is specified
104 space = regexp(package,"/\s/");
105 package_names(i) = part(package,[1:space-1]);
106 package_versions(i) = part(package,[space+1:length(package)]);
109 // Ok, The syntax is correct, Now check if the package is really installed
110 if ~ atomsIsInstalled(package_names(i),package_versions(i)) then
114 // get the list of the versions of this package to uninstall
116 if isempty(package_versions(i)) then
117 // uninstall all version of this toolbox
118 this_package_versions = atomsGetInstalledVers(package_names(i));
120 // Just uninstall the specified version
121 this_package_versions = package_versions(i);
124 for j=1:size(this_package_versions,"*")
125 remList = [ remList ; "-" "U" package_names(i) this_package_versions(j) ];
130 // Second Step : List the packages that depends of the uninstalled packages
131 // =========================================================================
134 for i=1:size(packages(:,1),"*")
136 this_package_name = packages(i,3);
137 this_package_version = packages(i,4);
139 // Get the parents of this toolbox
140 // (inevitably removed, unless we have not the right)
141 // ----------------------------------------------------
143 this_package_parents = atomsGetDepParents(this_package_name,this_package_version);
145 for j=1:size(this_package_parents(:,1),"*")
147 this_parent_name = this_package_parents(j,1);
148 this_parent_version = this_package_parents(j,2);
150 // Check if we have the right to remove this package
151 // If not, tag it as Broken (for later)
153 details = atomsGetInstalledDetails(this_parent_name,this_parent_version);
154 if details(3) == "allusers" then
155 remList = [ remList ; "~" "B" this_parent_name this_parent_version ]; // B stands for "Broken"
160 // Add this parent to the list
161 if find(remList(:,3)+" - "+remList(:,4) == this_parent_name+" - "+this_parent_version) == [] then
162 remList = [ remList ; "-" "P" this_parent_name this_parent_version ]; // P stands for "Parent"
167 // Get the childs of this toolbox
168 // ----------------------------------------------
170 this_package_childs = atomsGetDepChilds(this_package_name,this_package_version);
172 for j=1:size(this_package_childs(:,1),"*")
174 this_child_name = this_package_childs(j,1);
175 this_child_version = this_package_childs(j,2);
177 // Check if we have the right to remove this package
178 // If not, Do not add it to the list
180 details = atomsGetInstalledDetails(this_child_name,this_child_version);
181 if details(3) == "allusers" then
186 if find(remList(:,3)+" - "+remList(:,4) == this_child_name+" - "+this_child_version) == [] then
187 remList = [ remList ; "-" "C" this_child_name this_child_version ]; // C stands for "Child"
194 // Third Step : Loop on childs check if we uninstall it or not
195 // =========================================================================
197 packages = remList(find(remList(:,2)=="C"),:);
199 for i=1:size(remList(:,1),"*")
201 // This is not a Child package :
203 // ----------------------------------------------
205 if remList(i,2) <> "C" then
209 this_package_name = remList(i,3);
210 this_package_version = remList(i,4);
212 // The package has been intentionnaly installed :
213 // => Do not install it
214 // ----------------------------------------------
216 if atomsGetInstalledStatus(this_package_name,this_package_version) == "I" then
220 // Get the parents of this toolbox
221 // ----------------------------------------------
223 this_package_parents = atomsGetDepParents(this_package_name,this_package_version);
225 for j=1:size(this_package_parents(:,1),"*")
227 if find(remList(:,3)+" - "+remList(:,4) == this_package_parents(j,1)+" - "+this_package_parents(j,2)) == [] then
228 // One of the parent is not the remove list
229 // => do not install it