Ignore:
Timestamp:
2010-08-30T16:29:40+12:00 (14 years ago)
Author:
ak19
Message:

Further changes to ticket 152 (movable collectdir). Need to deal with GLI being started and reading in a non-standard collectdir from config files (stored from a previous GLI session) that now no longer exists. In this case need to revert back to the default Greenstone collectdir. Tested on Windows with the included Apache webserver and server.exe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r22771 r22806  
    505505        // If opening a collection outside the standard GS collect folder, need
    506506        // to open the non-standard collect folder that the collection resides in
    507         if (open_collection_file_path != null && 
    508         !open_collection_file_path.startsWith(getCollectDirectoryPath())) {
     507        if (open_collection_file_path != null &&
     508        !open_collection_file_path.startsWith(getDefaultGSCollectDirectoryPath(true))) {
    509509        File collectFolder = null;
    510510        if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
     
    520520        String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
    521521        if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
    522             collectFolder = collectFolder.getParentFile();
    523            
    524         }
    525         setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder
    526         }
    527        
    528     }
    529     catch (Exception exception) {
     522            collectFolder = collectFolder.getParentFile();         
     523        }
     524       
     525        if(!isGsdlRemote && !collectFolder.exists()) {
     526            // if dealing with a local server but the collectdir no longer exists,
     527            // use the default greenstone collect directory, and write that to affected files
     528            open_collection_file_path = null; // no longer have an open collection from last time if coldir doesn't exist
     529           
     530            String defaultColDir = getDefaultGSCollectDirectoryPath(false); // no file separator at end         
     531           
     532            setCollectDirectoryPath(defaultColDir); // will ensure the required file separator at end
     533           
     534            Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
     535                    true, defaultColDir + File.separator);
     536           
     537            if(Gatherer.GS3) {  // GS2's gsdlsite.cfg was taken care of when LocalLibraryServer was started up
     538                                // (LocalLibraryServer would also already have set glisite.cfg to the correct collecthome)
     539                String gsdlsitecfg = Configuration.gsdl3_path + File.separator
     540                    + "WEB-INF" + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
     541                Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", defaultColDir); // no file separator               
     542            }
     543        } else { // remote GS or collect dir exists
     544            setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder         
     545        }
     546    }
     547    } catch (Exception exception) {
    530548        DebugStream.printStackTrace(exception);
    531549    }
     
    715733    }
    716734   
    717     return getDefaultGSCollectDirectoryPath();
     735    return getDefaultGSCollectDirectoryPath(true); // file separator appended
    718736   
    719737    }
    720738
    721739    /** Returns the path of the Greenstone "collect" directory. */
    722     static public String getDefaultGSCollectDirectoryPath() {
    723         if (!GS3) {
    724             return Configuration.gsdl_path + "collect" + File.separator;
     740    static public String getDefaultGSCollectDirectoryPath(boolean appendSeparator) {
     741        String colDir;
     742        if (GS3) {
     743            colDir = getSitesDirectoryPath() + Configuration.site_name + File.separator + "collect";           
    725744        }
    726745        else {
    727             return getSitesDirectoryPath() + Configuration.site_name + File.separator + "collect" + File.separator;
    728         }
     746            colDir = Configuration.gsdl_path + "collect";
     747        }
     748       
     749        if(appendSeparator) {
     750            colDir += File.separator;
     751        }
     752        return colDir;
    729753    }   
    730754
     
    802826    }
    803827
    804     // first save any open collection in the *old* location
     828    // first save any open collection in the old location, then close it
    805829    if(Gatherer.c_man.getCollection() != null) {
    806         Gatherer.setCollectDirectoryPath(oldCollectPath); // go back to current collection's location
    807830        Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first
    808831    }
     
    830853    if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
    831854        gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF"
    832         + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
     855            + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
    833856    } else { // cgi-bin/gsdlsite.cfg
    834857        gsdlsitecfg = Configuration.gsdl_path + File.separator
    835         + "cgi-bin" + File.separator + "gsdlsite.cfg";
     858            + "cgi-bin" + File.separator + "gsdlsite.cfg";
    836859    }
    837860
Note: See TracChangeset for help on using the changeset viewer.