Changeset 10252


Ignore:
Timestamp:
2005-07-19T10:50:57+12:00 (19 years ago)
Author:
mdewsnip
Message:

Unzip.java now takes the zip file path and the directory to unzip into as arguments. This more general functionality is necessary for the West Yorkshire stuff.

The upload script has been changed accordingly, and tidied up a bit.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/Unzip.java

    r10207 r10252  
    88 * <BR><BR>
    99 *
    10  * Author: David Bainbridge, Greenstone Digital Library, University of Waikato
     10 * Author: David Bainbridge, NZDL Project, University of Waikato
    1111 *
    1212 * <BR><BR>
    1313 *
    14  * Copyright (C) 1999 New Zealand Digital Library Project
     14 * Copyright (C) 2005 New Zealand Digital Library Project
    1515 *
    1616 * <BR><BR>
     
    5959    }
    6060
     61
    6162    static public void main(String[] args)
    6263    {
    63     Enumeration entries;
    64     ZipFile zipFile;
    65 
    66     if(args.length != 2) {
    67         System.err.println("Usage: Unzip gsdlhome zipfile");
     64    if (args.length != 2) {
     65        System.err.println("Usage: Unzip <zip-file> <destination-directory>");
    6866        return;
    6967    }
    7068
    71     String gsdl_home = args[0];
    72 
    73     if (!gsdl_home.endsWith(File.separator)) {
    74         gsdl_home += File.separator;
     69    String zip_file_path = args[0];
     70    // System.err.println("Zip file path: " + zip_file_path);
     71    String destination_directory_path = args[1];
     72    if (!destination_directory_path.endsWith(File.separator)) {
     73        destination_directory_path += File.separator;
    7574    }
    76 
    77     String col_dir = gsdl_home + "collect" + File.separator;
    78 
    79     String zip_fname = args[1];
     75    // System.err.println("Destination directory path: " + destination_directory_path);
    8076
    8177    try {
    82         zipFile = new ZipFile(zip_fname);
     78        ZipFile zipFile = new ZipFile(zip_file_path);
    8379
    84         entries = zipFile.entries();
     80        Enumeration entries = zipFile.entries();
     81        while (entries.hasMoreElements()) {
     82        ZipEntry entry = (ZipEntry) entries.nextElement();
    8583
    86         while(entries.hasMoreElements()) {
    87         ZipEntry entry = (ZipEntry)entries.nextElement();
    88 
    89         if(entry.isDirectory()) {
     84        if (entry.isDirectory()) {
    9085            // Assume directories are stored parents first then children.
    9186            // System.err.println("Extracting directory: " + entry.getName());
    9287            // This is not robust, just for demonstration purposes.
    9388            String dir_name = entry.getName();
    94             String full_dir_name = col_dir + dir_name;
     89            String full_dir_name = destination_directory_path + dir_name;
     90            // System.err.println("Full directory name: " + full_dir_name);
    9591            File dirFile = new File(full_dir_name);
    9692            dirFile.mkdir();
     
    9995            // System.err.println("Extracting file: " + entry.getName());
    10096            String file_name = entry.getName();
    101             String full_file_name = col_dir + file_name;
     97            String full_file_name = destination_directory_path + file_name;
     98            // System.err.println("Full file name: " + full_file_name);
    10299            FileOutputStream fos = new FileOutputStream(full_file_name);
    103100            BufferedOutputStream bos = new BufferedOutputStream(fos);
     
    108105
    109106        zipFile.close();
    110     } 
     107    }
    111108    catch (ZipException error) {
    112         System.err.println("Error: Unable to open '"+zip_fname+"'");
    113         System.err.println("This maybe caused by the zip file being empty.");
     109        System.err.println("Error: Unable to open '" + zip_file_path + "'");
     110        System.err.println("This may be caused by the zip file being empty.");
    114111        error.printStackTrace();
    115112    }
    116 
    117     catch (IOException ioe) {
    118         System.err.println("Unhandled exception on " + gsdl_home + " " + zip_fname);
    119         ioe.printStackTrace();
    120         return;
    121     }
    122 
    123     catch (Exception error) {
    124         error.printStackTrace();
     113    catch (Exception exception) {
     114        exception.printStackTrace();
    125115    }
    126116    }
  • trunk/gsdl/cgi-bin/upload

    r10226 r10252  
    4141    $dir = "" if (($dir eq ".") || ($dir =~ m/^\.\./));
    4242
    43     my $zip_content = $gsdl_cgi->clean_param("zip");
    44     my $zip_fname = "$col.zip";
    45 
    46     if ($col =~ m/^\//) {
     43    if ($col =~ m/^\//) {
    4744    # leading / at start denotes special "cols" such as "/tmp"
    4845    $gsdl_cgi->checked_chdir("$gsdlhome");
     
    7471    }
    7572
    76     if (open(ZOUT,"> $zip_fname")) {
     73    my $zip_file_name = $col . ".zip";
     74    my $zip_file_path = &util::filename_cat($full_col_dir, $zip_file_name);
     75    if (open(ZOUT, ">$zip_file_path")) {
    7776    binmode(ZOUT);
    7877
     
    9695                        "SignedGatherer.jar");
    9796
    98     my $java_cmd = "$java -classpath \"$classpath\" org.greenstone.gatherer.util.Unzip \"$gsdlhome\" \"$zip_fname\"";
     97    my $java_cmd = "$java -classpath \"$classpath\" org.greenstone.gatherer.util.Unzip \"$zip_file_path\" \"$full_col_dir\"";
     98    $gsdl_cgi->generate_ok_message("Command: $java_cmd\n");
    9999
    100100    my $java_output = `$java_cmd`;
    101101   
    102102    my $status = $?;
    103     unlink "$zip_fname";
     103    unlink "$zip_file_path";
    104104
    105     if ($status>0) {
     105    if ($status > 0) {
    106106        $status = $status/256;
    107107        my $exit_status = "Exit status: $status\n";
     
    113113    }
    114114    else {
    115     $gsdl_cgi->generate_error("unable to open $zip_fname");
     115    $gsdl_cgi->generate_error("unable to open $zip_file_path");
    116116    }
    117117}
Note: See TracChangeset for help on using the changeset viewer.