Changeset 5758
- Timestamp:
- Sep 23, 2011, 9:05:23 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/src/docbook/developer/migrate_2_3.xml
r5738 r5758 160 160 <listitem> 161 161 <para> 162 Changes to the <interfacename docapi="net.sf.basedb.util.zip">FileUnpacker</interfacename> 163 interface. The <methodname>unpack()</methodname> method signature has changed and 164 any plug-ins that implement this interface need to be updated. The changes 165 make it possible to get information about the main zip/tar file that is being 166 unpacked. See <ulink 167 url="http://base.thep.lu.se/ticket/978">ticket #978 (Unzipped files never inherit 168 file type specified during upload)</ulink> for more information. 169 </para> 170 </listitem> 171 172 <listitem> 173 <para> 162 174 TODO -- more will probably be added to this list 163 175 </para> -
trunk/src/clients/web/net/sf/basedb/clients/web/servlet/Upload.java
r5643 r5758 182 182 throw new WebException("popup", "File already exists", "Another file with the same name already exists: {1}", uploadedFile.getFilename()); 183 183 } 184 185 f.setName(uploadedFile.getFilename()); 186 String serverMimeType = getServletContext().getMimeType(uploadedFile.getFilename()); 187 String browserMimeType = uploadedFile.getMimeType(); 188 f.setMimeTypeAuto(serverMimeType != null ? serverMimeType : browserMimeType, null); 189 if (subtypeId >= 0) // < 0 = denied or unchanged 190 { 191 ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId); 192 f.setItemSubtype(subtype); 193 if (subtype != null) cc.setRecent(subtype, maxRecent); 194 } 195 f.setDescription(description); 196 f.setCharacterSet(characterSet); 197 toFile = f.getUploadStream(checkMd5, compress); 198 f.setWriteProtected(writeProtected); 199 } 184 } 185 186 if (f == null) 187 { 188 // Create a dummy file that is not saved to the database 189 // We use this so that options from the form can be sent 190 // to the unpacker.unpack() method 191 f = File.getNew(dc, directory); 192 } 193 194 // Set various properties from the form on the file object 195 f.setName(uploadedFile.getFilename()); 196 String serverMimeType = getServletContext().getMimeType(uploadedFile.getFilename()); 197 String browserMimeType = uploadedFile.getMimeType(); 198 f.setMimeTypeAuto(serverMimeType != null ? serverMimeType : browserMimeType, null); 199 if (subtypeId >= 0) // < 0 = denied or unchanged 200 { 201 ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId); 202 f.setItemSubtype(subtype); 203 if (subtype != null) cc.setRecent(subtype, maxRecent); 204 } 205 f.setDescription(description); 206 f.setCharacterSet(characterSet); 207 if (!f.isDetached()) toFile = f.getUploadStream(checkMd5, compress); 208 f.setWriteProtected(writeProtected); 200 209 201 210 // Load plug-in for for unpacking (must implement FileUnpacker) … … 230 239 SimpleAbsoluteProgressReporter unpackProgress = new SimpleAbsoluteProgressReporter(null, fileSize); 231 240 sc.setSessionSetting("UnpackProgress", unpackProgress); 232 numUnpackedFiles = unpacker.unpack(dc, directory, uploadStream, overwriteZip, unpackProgress);241 numUnpackedFiles = unpacker.unpack(dc, directory, uploadStream, f, overwriteZip, unpackProgress); 233 242 } 234 243 uploadStream.close(); -
trunk/src/core/net/sf/basedb/util/zip/AbstractFileUnpacker.java
r5481 r5758 139 139 permissions.add(new Permissions(Item.FILE, null, EnumSet.of(Permission.CREATE, Permission.WRITE))); 140 140 permissions.add(new Permissions(Item.DIRECTORY, null, EnumSet.of(Permission.CREATE, Permission.WRITE))); 141 permissions.add(new Permissions(Item.ITEMSUBTYPE, EnumSet.of(Permission.USE), null)); 141 142 } 142 143 return permissions; … … 159 160 160 161 // Unpack the file 161 int numFiles = unpack(dc, dir, in, overwrite, absoluteProgress);162 int numFiles = unpack(dc, dir, in, zipFile, overwrite, absoluteProgress); 162 163 dc.commit(); 163 164 -
trunk/src/core/net/sf/basedb/util/zip/FileUnpacker.java
r4515 r5758 30 30 import net.sf.basedb.core.DbControl; 31 31 import net.sf.basedb.core.Directory; 32 import net.sf.basedb.core.File; 32 33 import net.sf.basedb.core.plugin.Plugin; 33 34 … … 74 75 75 76 /** 76 Unpack the given input stream into a BASE directory. 77 Unpack the given input stream into a BASE directory. If a source 78 file is given it can be used as a template for setting certain 79 properties on the unpcked files. See {@link 80 PackUtil#copyProperties(File, File)}. 77 81 78 82 @param dc The DbControl to use for database access 79 83 @param dir The directory to unpack the files to 80 84 @param in The input stream containing the packed data 85 @param sourceFile The source packed file that the input stream is 86 coming from or null if not known 81 87 @param overwrite If existing files should be overwritten or ignored 82 88 @param progress A optional progress reporter which expects the number … … 85 91 @throws IOException If there is an error reading the input stream 86 92 @throws BaseException If there is another error 93 @since 3.0 87 94 */ 88 public int unpack(DbControl dc, Directory dir, InputStream in, boolean overwrite,95 public int unpack(DbControl dc, Directory dir, InputStream in, File sourceFile, boolean overwrite, 89 96 AbsoluteProgressReporter progress) 90 97 throws IOException, BaseException; -
trunk/src/core/net/sf/basedb/util/zip/ZipUnpacker.java
r4515 r5758 80 80 @throws IOException If there is an error when unpacking the zip file 81 81 @throws BaseException If there is a BASE error 82 @since 3.0 82 83 */ 83 public int unpackZipFile(Directory rootDir, ZipInputStream zip, boolean overwrite,84 public int unpackZipFile(Directory rootDir, ZipInputStream zip, File sourceFile, boolean overwrite, 84 85 AbsoluteProgressReporter progress) 85 86 throws IOException, BaseException … … 119 120 file.setMimeTypeAuto(null, null); 120 121 OutputStream upload = file.getUploadStream(false); 122 PackUtil.copyProperties(sourceFile, file); 121 123 try 122 124 { -
trunk/src/plugins/core/net/sf/basedb/plugins/TarFileUnpacker.java
r5612 r5758 51 51 import net.sf.basedb.util.Values; 52 52 import net.sf.basedb.util.zip.AbstractFileUnpacker; 53 import net.sf.basedb.util.zip.PackUtil; 53 54 import net.sf.basedb.util.zip.TarUtil; 54 55 … … 97 98 return mimeTypes; 98 99 } 100 @Override 99 101 public int unpack(DbControl dc, Directory rootDir, InputStream in, 100 boolean overwrite, AbsoluteProgressReporter progress)102 File sourceFile, boolean overwrite, AbsoluteProgressReporter progress) 101 103 throws IOException 102 104 { … … 161 163 file.setMimeTypeAuto(null, null); 162 164 OutputStream upload = file.getUploadStream(false); 165 PackUtil.copyProperties(sourceFile, file); 163 166 try 164 167 { -
trunk/src/plugins/core/net/sf/basedb/plugins/ZipFileUnpacker.java
r5612 r5758 32 32 import net.sf.basedb.core.DbControl; 33 33 import net.sf.basedb.core.Directory; 34 import net.sf.basedb.core.File; 34 35 import net.sf.basedb.util.zip.AbstractFileUnpacker; 35 36 import net.sf.basedb.util.zip.ZipUnpacker; … … 77 78 Use the {@link ZipUnpacker} to unpack the file. 78 79 */ 80 @Override 79 81 public int unpack(DbControl dc, Directory dir, InputStream in, 80 boolean overwrite, AbsoluteProgressReporter progress)82 File sourceFile, boolean overwrite, AbsoluteProgressReporter progress) 81 83 throws IOException 82 84 { 83 85 ZipUnpacker unpacker = new ZipUnpacker(dc); 84 86 ZipInputStream zipStream = new ZipInputStream(in); 85 return unpacker.unpackZipFile(dir, zipStream, overwrite, progress);87 return unpacker.unpackZipFile(dir, zipStream, sourceFile, overwrite, progress); 86 88 } 87 89 // ------------------------------------------- -
trunk/src/test/TestFile.java
r5630 r5758 387 387 AbsoluteProgressReporter progress = TestUtil.getSilent() ? 388 388 null : new SimpleAbsoluteProgressReporter(new ConsoleProgressReporter(true), fileToUpload.length()); 389 unpacker.unpackZipFile(dir, zipFile, true, progress);389 unpacker.unpackZipFile(dir, zipFile, keepZip, true, progress); 390 390 if (progress != null) progress.append("\n"); 391 391
Note: See TracChangeset
for help on using the changeset viewer.