Changeset 10252
- Timestamp:
- 2005-07-19T10:50:57+12:00 (19 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/Unzip.java
r10207 r10252 8 8 * <BR><BR> 9 9 * 10 * Author: David Bainbridge, Greenstone Digital Library, University of Waikato10 * Author: David Bainbridge, NZDL Project, University of Waikato 11 11 * 12 12 * <BR><BR> 13 13 * 14 * Copyright (C) 1999New Zealand Digital Library Project14 * Copyright (C) 2005 New Zealand Digital Library Project 15 15 * 16 16 * <BR><BR> … … 59 59 } 60 60 61 61 62 static public void main(String[] args) 62 63 { 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>"); 68 66 return; 69 67 } 70 68 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; 75 74 } 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); 80 76 81 77 try { 82 zipFile = new ZipFile(zip_fname);78 ZipFile zipFile = new ZipFile(zip_file_path); 83 79 84 entries = zipFile.entries(); 80 Enumeration entries = zipFile.entries(); 81 while (entries.hasMoreElements()) { 82 ZipEntry entry = (ZipEntry) entries.nextElement(); 85 83 86 while(entries.hasMoreElements()) { 87 ZipEntry entry = (ZipEntry)entries.nextElement(); 88 89 if(entry.isDirectory()) { 84 if (entry.isDirectory()) { 90 85 // Assume directories are stored parents first then children. 91 86 // System.err.println("Extracting directory: " + entry.getName()); 92 87 // This is not robust, just for demonstration purposes. 93 88 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); 95 91 File dirFile = new File(full_dir_name); 96 92 dirFile.mkdir(); … … 99 95 // System.err.println("Extracting file: " + entry.getName()); 100 96 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); 102 99 FileOutputStream fos = new FileOutputStream(full_file_name); 103 100 BufferedOutputStream bos = new BufferedOutputStream(fos); … … 108 105 109 106 zipFile.close(); 110 } 107 } 111 108 catch (ZipException error) { 112 System.err.println("Error: Unable to open '" +zip_fname+"'");113 System.err.println("This may be 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."); 114 111 error.printStackTrace(); 115 112 } 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(); 125 115 } 126 116 } -
trunk/gsdl/cgi-bin/upload
r10226 r10252 41 41 $dir = "" if (($dir eq ".") || ($dir =~ m/^\.\./)); 42 42 43 my $zip_content = $gsdl_cgi->clean_param("zip"); 44 my $zip_fname = "$col.zip"; 45 46 if ($col =~ m/^\//) { 43 if ($col =~ m/^\//) { 47 44 # leading / at start denotes special "cols" such as "/tmp" 48 45 $gsdl_cgi->checked_chdir("$gsdlhome"); … … 74 71 } 75 72 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")) { 77 76 binmode(ZOUT); 78 77 … … 96 95 "SignedGatherer.jar"); 97 96 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"); 99 99 100 100 my $java_output = `$java_cmd`; 101 101 102 102 my $status = $?; 103 unlink "$zip_f name";103 unlink "$zip_file_path"; 104 104 105 if ($status >0) {105 if ($status > 0) { 106 106 $status = $status/256; 107 107 my $exit_status = "Exit status: $status\n"; … … 113 113 } 114 114 else { 115 $gsdl_cgi->generate_error("unable to open $zip_f name");115 $gsdl_cgi->generate_error("unable to open $zip_file_path"); 116 116 } 117 117 }
Note:
See TracChangeset
for help on using the changeset viewer.