Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore shapefiles if they are under a hidden directory in the zip file #10627

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Shapefile Handling will now ignore files under a hidden directory within the zip file

Directories that are hidden will be ignored when determining if a zip file contains Shapefile files.

For more information, see #8945.
42 changes: 26 additions & 16 deletions src/main/java/edu/harvard/iq/dataverse/util/ShapefileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.*;

import java.nio.file.Files;
import java.nio.file.Paths;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -695,33 +696,42 @@ private boolean examineZipfile(FileInputStream zip_file_stream){
this.filesListInDir.clear();
this.filesizeHash.clear();
this.fileGroups.clear();
try{

try{
ZipInputStream zipStream = new ZipInputStream(zip_file_stream);
ZipEntry entry;

List<String> hiddenDirectories = new ArrayList<>();
while((entry = zipStream.getNextEntry())!=null){
String zentryFileName = entry.getName();
boolean isDirectory = entry.isDirectory();

Boolean skip = isDirectory || this.isFileToSkip(zentryFileName);

// check if path is hidden
if (isDirectory && Files.isHidden(Paths.get(zentryFileName))) {
hiddenDirectories.add(zentryFileName);
logger.fine("Ignoring files under hidden directory: " + zentryFileName);
} else {
// check if the path was already found to be hidden
for (String hidden : hiddenDirectories) {
if (zentryFileName.startsWith(hidden)) {
skip = true;
break;
}
}
}

String zentryFileName = entry.getName();
//msg("zip entry: " + entry.getName());
// Skip files or folders starting with __
if (this.isFileToSkip(zentryFileName)){
continue;
}

if (entry.isDirectory()) {
//String dirpath = outputFolder + "/" + zentryFileName;
//createDirectory(dirpath);
continue;
if (skip) {
continue;
}

String unzipFileName = this.getFileBasename(zentryFileName);
if (unzipFileName==null){
logger.warning("Zip Entry Basename is an empty string: " + zentryFileName);
continue;
}
String unzipFolderName = this.getFolderName(zentryFileName);

String unzipFilePath = unzipFileName;
if (unzipFolderName != null) {
unzipFilePath = unzipFolderName + "/" + unzipFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,14 @@ public void testZippedShapefileWithExtraFiles() throws IOException{

msg("Passed!");
}


@Test
public void testHiddenFiles() {
// test with shapefiles in hidden directory
ShapefileHandler shp_handler = new ShapefileHandler("src/test/resources/hiddenShapefiles.zip");
shp_handler.DEBUG= true;
assertFalse(shp_handler.containsShapefile());
}



Expand Down
Binary file added src/test/resources/hiddenShapefiles.zip
Binary file not shown.
Loading