mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
Fix DSpace Import to accept zip, adding subfolder to sourceDir
This commit is contained in:
@@ -517,6 +517,7 @@ public class ItemImport
|
||||
// If this is a zip archive, unzip it first
|
||||
if (zip)
|
||||
{
|
||||
String sourceDirForZip = sourcedir;
|
||||
ZipFile zf = new ZipFile(zipfilename);
|
||||
ZipEntry entry;
|
||||
Enumeration<? extends ZipEntry> entries = zf.entries();
|
||||
@@ -546,6 +547,17 @@ public class ItemImport
|
||||
{
|
||||
log.error("Unable to create directory");
|
||||
}
|
||||
|
||||
//Entries could have too many directories, and we need to adjust the sourcedir
|
||||
//regex supports either windows or *nix file paths
|
||||
String[] entryChunks = entry.getName().split("/|\\\\");
|
||||
if(entryChunks.length > 1) {
|
||||
if(sourceDirForZip == sourcedir) {
|
||||
sourceDirForZip += "/" + entryChunks[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
@@ -560,6 +572,11 @@ public class ItemImport
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
if(sourceDirForZip != sourcedir) {
|
||||
sourcedir = sourceDirForZip;
|
||||
System.out.println("Set sourceDir using path inside of Zip: " + sourcedir);
|
||||
}
|
||||
}
|
||||
|
||||
c.turnOffAuthorisationSystem();
|
||||
|
Reference in New Issue
Block a user