More precautions when removing a package
Pierre MARECHAL [Mon, 29 Jun 2009 15:48:37 +0000 (17:48 +0200)]
scilab/modules/atoms/macros/atomsInstall.sci
scilab/modules/atoms/macros/atomsRemove.sci
scilab/modules/atoms/macros/atomsUpdate.sci
scilab/modules/atoms/macros/atoms_internals/atomsGetDepChilds.sci
scilab/modules/atoms/macros/atoms_internals/atomsGetDepParents.sci
scilab/modules/atoms/macros/atoms_internals/atomsRemoveList.sci

index 7bc1b78..ac64c51 100644 (file)
@@ -322,13 +322,13 @@ function result = atomsInstall(packages,allusers)
        // that have been installed
        // =========================================================================
        
-       for i=1:size( result(:,1) )
+       for i=1:size( result(:,1) , "*" )
                
-               packages_out = atomsUpdateDeps(result(:,1),result(:,2),allusers);
+               packages_out = atomsUpdateDeps(result(i,1),result(i,2),allusers);
                
                if VERBOSE then
                        for j=1:size(packages_out(:,1),"*")
-                               mprintf("\t%s (%s) will now use the version %s of the package %s\n",packages_out(:,1),packages_out(:,2),result(:,1),result(:,2));
+                               mprintf("\t%s (%s) will now use the version %s of the package %s\n",packages_out(j,1),packages_out(j,2),result(i,1),result(i,2));
                        end
                end
                
@@ -337,8 +337,8 @@ function result = atomsInstall(packages,allusers)
        // Remove orphan packages
        // =========================================================================
        
-       orphan_list = atomsOrphanList(alluser);
-       for i=1:size( orphan_list(:,1) )
+       orphan_list = atomsOrphanList(allusers);
+       for i=1:size( orphan_list(:,1) , "*" )
                atomsRemove( orphan_list(i,1) + " " + orphan_list(i,2) );
        end
        
index 1475b18..41806ed 100644 (file)
@@ -90,7 +90,66 @@ function result = atomsRemove(packages,allusers)
                        chdir(initialpath);
                        error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsRemove",2,pathconvert(SCI+"/.atoms")));
                end
-       end 
+       end
+       
+       // Some checking on packages variable
+       // =========================================================================
+       
+       for i=1:size(packages,"*")
+               
+               package = packages(i);
+               
+               if size(regexp(package,"/\s/") ,"*" ) > 1 then
+                       error(msprintf(gettext("%s: Wrong value for input argument #%d: package name must contain at most one space (to split name and version).\n"),"atomsRemove",1));
+               end
+               
+               if size(regexp(package,"/\s/") ,"*" ) == 0 then
+                       // Just the toolbox name is specified
+                       package_names(i)    = package;
+                       package_versions(i) = "";
+               else
+                       // A version is specified
+                       space               = regexp(package,"/\s/");
+                       package_names(i)    = part(package,[1:space-1]);
+                       package_versions(i) = part(package,[space+1:length(package)]);
+               end
+               
+               // Check if this package is installed
+               
+               if ~ atomsIsInstalled(package_names(i),package_versions(i),%T) then
+                       
+                       // Print a warning if the package isn't installed
+                       
+                       if VERBOSE
+                               if isempty(package_versions(i)) then
+                                       mprintf("\t%s isn''t installed\n",package_names(i));
+                               else
+                                       mprintf("\t%s (%s) isn''t installed\n",package_names(i),package_versions(i));
+                               end
+                       end
+               
+               elseif (~ allusers) & (~ isempty(package_versions(i)) ) then
+                       
+                       // The package is installed, now check if we have the right to
+                       // uninstall it
+                       
+                       installed_details = atomsGetInstalledDetails(package_names(i),package_versions(i));
+                       
+                       if installed_details(3) == "allusers" then
+                               error(msprintf(gettext("%s: You have not enought rights to remove the package %s (%s).\n"),"atomsRemove",package_names(i),package_versions(i)));
+                       end
+               
+               elseif (~ allusers) & isempty(package_versions(i)) then
+                       
+                       // Check if we have the right to remove at least one of the version
+                       // of the package
+                       if isempty(atomsGetInstalledVers(package_names(i),allusers)) then
+                               error(msprintf(gettext("%s: You have not enought rights to remove any version of the package %s.\n"),"atomsRemove",package_names(i)));
+                       end
+                       
+               end
+               
+       end
        
        // Build the list of package to Uninstall
        // =========================================================================
@@ -138,16 +197,20 @@ function result = atomsRemove(packages,allusers)
                        error(msprintf(gettext("%s: The directory of this package (%s-%s) is located neither in SCI nor in SCIHOME. For security reason, ATOMS refuses to delete this directory.\n"),"atomsRemove",this_package_name,this_package_version));
                end
                
-               uninstall_status = rmdir(this_package_directory,"s");
-               
-               if uninstall_status<>1 then
-                       chdir(initialpath);
-                       error(msprintf( ..
-                               gettext("%s: The directory of this package (%s-%s) cannot been deleted, please check if you have write access on this directory : %s.\n"),..
-                               "atomsRemove", ..
-                               this_package_name, ..
-                               this_package_version, ..
-                               this_package_directory));
+               if isdir(this_package_directory) then
+                       
+                       uninstall_status = rmdir(this_package_directory,"s");
+                       
+                       if uninstall_status<>1 then
+                               chdir(initialpath);
+                               error(msprintf( ..
+                                       gettext("%s: The directory of this package (%s-%s) cannot been deleted, please check if you have write access on this directory : %s.\n"),..
+                                       "atomsRemove", ..
+                                       this_package_name, ..
+                                       this_package_version, ..
+                                       this_package_directory));
+                       end
+                       
                end
                
                // Check if the parent directory (directory name == toolbox name ) is empty 
@@ -170,7 +233,8 @@ function result = atomsRemove(packages,allusers)
                
                // Remove this toolbox from the list of installed packages
                // =====================================================================
-               atomsInstallUnregister(this_package_name,this_package_version,allusers);
+               this_package_allusers = (this_package_insdet(3) == "allusers");
+               atomsInstallUnregister(this_package_name,this_package_version,this_package_allusers);
                
                // Remove this toolbox from the list of autoloaded packages
                // =====================================================================
index 7dbbe25..4b0198b 100644 (file)
@@ -106,7 +106,6 @@ function result = atomsUpdate(name,allusers)
                end
        end
        
-       
        // Loop on name
        // =========================================================================
        
index 9b79e89..07ede84 100644 (file)
@@ -76,6 +76,12 @@ function packages = atomsGetDepChilds(name,version,allusers)
        // Return the matrix associated with the wanted package (name - version)
        // =========================================================================
        
-       packages = installed_deps(name+" - "+version);
+       packages_list = installed_deps(name+" - "+version);
+       
+       for i=1:size(packages_list,"*")
+               this_package_name    = part(packages_list(i),1:regexp(packages_list(i),"/\s-\s/","o")-1);
+               this_package_version = part(packages_list(i),length(this_package_name)+4:length(packages_list(i)));
+               packages = [ packages ; this_package_name this_package_version ];
+       end
        
 endfunction
index 3d74c53..bc138fa 100644 (file)
@@ -76,6 +76,12 @@ function packages = atomsGetDepParents(name,version,allusers)
        // Return the matrix associated with the wanted package (name - version)
        // =========================================================================
        
-       packages = parent_deps(name+" - "+version);
+       packages_list = parent_deps(name+" - "+version);
+       
+       for i=1:size(packages_list,"*")
+               this_package_name    = part(packages_list(i),1:regexp(packages_list(i),"/\s-\s/","o")-1);
+               this_package_version = part(packages_list(i),length(this_package_name)+4:length(packages_list(i)));
+               packages = [ packages ; this_package_name this_package_version ];
+       end
        
 endfunction
index f955bc2..72af367 100644 (file)
@@ -46,38 +46,16 @@ function remList = atomsRemoveList(packages,allusers)
        
        rhs = argn(2);
        
-       if rhs > 2 then
-               error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"atomsRemoveList",1,2))
+       if rhs <> 2 then
+               error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"atomsRemoveList",2))
        end
        
        if type(packages) <> 10 then
                error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsRemoveList",1));
        end
        
-       // Apply changes for all users or just for me ?
-       // =========================================================================
-       
-       if rhs == 1 then
-               // By default, uninstall the package (if we have write access
-               // of course !)
-               if atomsAUWriteAccess() then
-                       allusers = %T; 
-               else
-                       allusers = %F;
-               end
-       
-       else
-               // Just check if it's a boolean
-               if type(allusers) <> 4 then
-                       chdir(initialpath);
-                       error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsRemoveList",2));
-               end
-               
-               // Check if we have the write access
-               if allusers & ~ atomsAUWriteAccess() then
-                       chdir(initialpath);
-                       error(msprintf(gettext("%s: You haven''t write access on this directory : %s.\n"),"atomsRemoveList",2,pathconvert(SCI+"/.atoms")));
-               end
+       if type(allusers) <> 4 then
+               error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsRemoveList",2));
        end
        
        // Loop on packages and to build the list of package to uninstall
@@ -91,10 +69,6 @@ function remList = atomsRemoveList(packages,allusers)
                
                package = packages(i);
                
-               if size(regexp(package,"/\s/") ,"*" ) > 1 then
-                       error(msprintf(gettext("%s: Wrong value for input argument #%d: it must contain at most one space.\n"),"atomsInstall",1));
-               end
-               
                if size(regexp(package,"/\s/") ,"*" ) == 0 then
                        // Just the toolbox name is specified
                        package_names(i)    = package;
@@ -106,16 +80,12 @@ function remList = atomsRemoveList(packages,allusers)
                        package_versions(i) = part(package,[space+1:length(package)]);
                end
                
-               // Ok, The syntax is correct, Now check if the package is really installed
-               if ~ atomsIsInstalled(package_names(i),package_versions(i)) then
-                       continue;
-               end
-               
                // get the list of the versions of this package to uninstall
                
                if isempty(package_versions(i)) then
-                       // uninstall all version of this toolbox
-                       this_package_versions = atomsGetInstalledVers(package_names(i));
+                       // uninstall all version of this toolbox (if we have the right, of
+                       // course)
+                       this_package_versions = atomsGetInstalledVers(package_names(i),allusers);
                else
                        // Just uninstall the specified version
                        this_package_versions = package_versions(i);