Ignore:
Timestamp:
2010-10-26T15:12:23+13:00 (14 years ago)
Author:
sjm84
Message:

The uninstaller has been modified so that it no longer will delete files or folders in the top-level directory that do not belong to Greenstone

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/release-kits/shared/core/uninstaller/Uninstaller.java

    r20648 r23210  
    4444    public static final ResourceBundle bundle = ResourceBundle.getBundle("resources.LanguagePack");
    4545
    46     public static final File gs2InstallProps = new File("etc/installation.properties");
    47     public static final File gs3InstallProps = new File("installation.properties");
     46    public static final File gs2InstallProps = new File("../etc/installation.properties");
     47    public static final File gs3InstallProps = new File("../installation.properties");
    4848
    4949    boolean keepCollections = true;
     
    335335
    336336            //never delete the things we are currently running
    337             exceptions.add( new File("bin/search4j.exe") );
    338             exceptions.add( new File("bin/search4j") );
    339 
    340             exceptions.add( new File("bin/windows/search4j.exe") );
    341             exceptions.add( new File("bin/linux/search4j") );
    342             exceptions.add( new File("bin/darwin/search4j") );
    343 
    344             exceptions.add( new File("packages/jre") );
    345             exceptions.add( new File("uninst.jar") );
    346             exceptions.add( new File("Uninstall.bat") );
    347             exceptions.add( new File("Uninstall.sh") );
     337            exceptions.add( new File("../bin/search4j.exe") );
     338            exceptions.add( new File("../bin/search4j") );
     339
     340            exceptions.add( new File("../bin/windows/search4j.exe") );
     341            exceptions.add( new File("../bin/linux/search4j") );
     342            exceptions.add( new File("../bin/darwin/search4j") );
     343
     344            exceptions.add( new File("../packages/jre") );
     345            exceptions.add( new File("../uninstall") );
    348346
    349347            if ( keepCollections ) {
    350                 exceptions.add( new File("web/sites/localsite/collect") );
    351                 exceptions.add( new File("collect") );
     348                exceptions.add( new File("../web/sites/localsite/collect") );
     349                exceptions.add( new File("../collect") );
    352350            }
    353351
     
    366364            }
    367365           
    368             recursiveDelete( cd , ex );
     366            //recursiveDelete( cd , ex );
     367            selectiveDelete ( cd, ex );
    369368        } catch ( CancelledException ce ) {
    370369            log( bundle.getString("uninstaller.cancelled") + "\n" );
     
    436435        return null;
    437436
     437    }
     438   
     439    public void selectiveDelete( File f, File[] exceptions ) throws CancelledException {
     440       
     441        File[] files = (new File(".")).listFiles();
     442       
     443        for ( int i=0; i < files.length; i++) {
     444            if( files[i].getAbsolutePath().endsWith(".uninstall") ) {
     445                String[] paths = getRelevantPathsFromUninstallFile(files[i]);
     446               
     447                for(int j=0; j < paths.length; j++) {
     448                    recursiveDelete( new File(".." + File.separator + paths[j]), exceptions );
     449                }
     450            }
     451        }
     452    }
     453   
     454    public String[] getRelevantPathsFromUninstallFile ( File uninstallFile ) {
     455       
     456        ArrayList paths = new ArrayList();
     457        try {
     458            BufferedReader in = new BufferedReader(new FileReader(uninstallFile));
     459           
     460            String line;
     461            while ( (line = in.readLine()) != null ) {
     462                int separatorIndex = line.indexOf(File.separator);
     463               
     464                if ( separatorIndex == -1 && line.length() > 0 && !paths.contains(line)) {
     465                    paths.add(line);
     466                }
     467                else if ( separatorIndex > -1 && line.length() > 0) {
     468                    String path = line.substring(0, separatorIndex);
     469                    if ( !paths.contains(path) ) {
     470                        paths.add(path);
     471                    }
     472                }
     473            }
     474           
     475            in.close();
     476        }
     477        catch( Exception ex ) {
     478            ex.printStackTrace();
     479            return null;
     480        }
     481        return (String[]) paths.toArray(new String[0]);
    438482    }
    439483
Note: See TracChangeset for help on using the changeset viewer.