From 01fc5814018d32b9142bd23e11e89bc4576ea017 Mon Sep 17 00:00:00 2001 From: Kunal Patel Date: Tue, 24 Nov 2026 15:19:59 -0500 Subject: [PATCH 1/5] fix(vector): keep embedding file paths and zip entries inside the insight space Resolve filePaths with Utility.resolveContainedFile and extract zips with the limit-checked ZipUtils.unzip (new unzipNested for nested zips) instead of the hand-rolled ZipInputStream loops that trusted entry names. --- .../CreateEmbeddingsFromDocumentsReactor.java | 92 ++------------ ...ateEmbeddingsFromVectorCSVFileReactor.java | 113 ++++-------------- src/prerna/util/ZipUtils.java | 27 +++++ 3 files changed, 59 insertions(+), 173 deletions(-) diff --git a/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java b/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java index bd885bd6bd..2b6264f836 100644 --- a/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java +++ b/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java @@ -29,14 +29,11 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; @@ -59,6 +56,7 @@ import prerna.util.AssetUtility; import prerna.util.Constants; import prerna.util.Utility; +import prerna.util.ZipUtils; public class CreateEmbeddingsFromDocumentsReactor extends AbstractReactor { @@ -209,10 +207,8 @@ private String getRootFolder() { } /** - * @param insightFolder + * @param rootFolder * @param validFiles - * @param invalidFiles - * @return * @throws IOException */ private void getFiles(String rootFolder, List validFiles) throws IOException { @@ -220,11 +216,18 @@ private void getFiles(String rootFolder, List validFiles) throws IOExcep if (grs != null && !grs.isEmpty()) { int size = grs.size(); for (int i = 0; i < size; i++) { - String filePath = rootFolder + "/" + grs.get(i).toString(); + String relativePath = grs.get(i).toString().replace('\\', '/').replaceFirst("^/+", ""); + // the file must be inside the insight or project space + String filePath; + try { + filePath = Utility.resolveContainedFile(rootFolder, relativePath).toString(); + } catch (IOException e) { + throw new IllegalArgumentException( + "File path for " + relativePath + " does not exist within the insight or project space."); + } if (isZipFile(filePath)) { - String zipFileLocation = filePath.replace('\\', '/'); File zipFileExtractFolder = new File(rootFolder, PATH_TO_UNZIP_FILES); - unzipAndFilter(zipFileLocation, zipFileExtractFolder.getAbsolutePath(), validFiles); + validFiles.addAll(ZipUtils.unzipNested(filePath, zipFileExtractFolder.getAbsolutePath())); } else { validFiles.add(filePath); } @@ -232,77 +235,6 @@ private void getFiles(String rootFolder, List validFiles) throws IOExcep } } - /** - * Recursively go through all the zips, directories and files in a zip file and - * save the paths of valid file types - * - * @param zipFilePath - * @param destDirectory - * @param validFiles - * @param invalidFiles - * @throws IOException - */ - private void unzipAndFilter(String zipFilePath, String destDirectory, List validFiles) throws IOException { - File destDir = new File(Utility.normalizePath(destDirectory)); - if (!destDir.exists()) { - destDir.mkdir(); - } - - try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(Utility.normalizePath(zipFilePath)))) { - ZipEntry entry = zipIn.getNextEntry(); - - while (entry != null) { - String filePath = destDirectory + "/" + entry.getName(); - if (!entry.isDirectory()) { - validFiles.add(filePath); - } else if (entry.isDirectory()) { - File dir = new File(Utility.normalizePath(filePath)); - dir.mkdirs(); - } else if (isZipFile(filePath)) { - // Handle nested zip file - this.extractFile(zipIn, filePath); - - // Check if the entry is not in the root directory - String parentPath = null; - if (filePath.contains("/")) { // ZIP entries use "/" as a separator - parentPath = filePath.substring(0, filePath.lastIndexOf('/')); - } - - // Extract the last part of the path (file name + extension) - String fileNameWithExtension = filePath.contains("/") - ? filePath.substring(filePath.lastIndexOf('/') + 1) - : filePath; - - // Remove the extension - String baseName = fileNameWithExtension.contains(".") - ? fileNameWithExtension.substring(0, fileNameWithExtension.lastIndexOf('.')) - : fileNameWithExtension; - - unzipAndFilter(filePath, parentPath + "/" + baseName, validFiles); - } - - zipIn.closeEntry(); - entry = zipIn.getNextEntry(); - } - } - } - - /** - * - * @param zipIn - * @param filePath - * @throws IOException - */ - private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { - try (FileOutputStream fos = new FileOutputStream(Utility.normalizePath(filePath))) { - byte[] buffer = new byte[1024]; - int bytesRead; - while ((bytesRead = zipIn.read(buffer)) != -1) { - fos.write(buffer, 0, bytesRead); - } - } - } - /** * * @param filePath diff --git a/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java b/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java index eaac779d37..44458e74c5 100644 --- a/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java +++ b/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java @@ -29,14 +29,11 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -58,6 +55,7 @@ import prerna.util.AssetUtility; import prerna.util.Constants; import prerna.util.Utility; +import prerna.util.ZipUtils; public class CreateEmbeddingsFromVectorCSVFileReactor extends AbstractReactor { @@ -162,91 +160,36 @@ private Map getMap() { } /** - * @param insightFolder + * @param rootFolder * @param validFiles * @param invalidFiles - * @return * @throws IOException */ - private void getFiles(String insightFolder, List validFiles, List invalidFiles) throws IOException { + private void getFiles(String rootFolder, List validFiles, List invalidFiles) throws IOException { GenRowStruct grs = this.store.getGenRowStruct(this.keysToGet[1]); if (grs != null && !grs.isEmpty()) { int size = grs.size(); for (int i = 0; i < size; i++) { - String filePath = insightFolder + "/" + grs.get(i).toString(); - if (isZipFile(filePath)) { - String zipFileLocation = filePath.replace('\\', '/'); - File zipFileExtractFolder = new File(insightFolder, PATH_TO_UNZIP_FILES); - unzipAndFilter(zipFileLocation, zipFileExtractFolder.getAbsolutePath(), validFiles, invalidFiles); - } else { - // String filePath = destDirectory + File.separator + entry.getName(); - if (isSupportedFileType(filePath)) { - validFiles.add(filePath); - } else { - invalidFiles.add(filePath); - } + String relativePath = grs.get(i).toString().replace('\\', '/').replaceFirst("^/+", ""); + // the file must be inside the insight or project space + String filePath; + try { + filePath = Utility.resolveContainedFile(rootFolder, relativePath).toString(); + } catch (IOException e) { + throw new IllegalArgumentException("File path for " + relativePath + " does not exist."); } - } - } - } - - /** - * Recursively go through all the zips, directories and files in a zip file and - * save the paths of valid file types - * - * @param zipFilePath - * @param destDirectory - * @param validFiles - * @param invalidFiles - * @throws IOException - */ - private void unzipAndFilter(String zipFilePath, String destDirectory, List validFiles, - List invalidFiles) throws IOException { - File destDir = new File(Utility.normalizePath(destDirectory)); - if (!destDir.exists()) { - destDir.mkdir(); - } - - try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(Utility.normalizePath(zipFilePath)))) { - ZipEntry entry = zipIn.getNextEntry(); - - while (entry != null) { - String filePath = destDirectory + "/" + entry.getName(); - if (!entry.isDirectory() && isSupportedFileType(filePath)) { - if (isSupportedFileType(filePath)) { - extractFile(zipIn, filePath); - validFiles.add(filePath); - } else { - invalidFiles.add(filePath); - } - } else if (entry.isDirectory()) { - File dir = new File(Utility.normalizePath(filePath)); - dir.mkdirs(); - } else if (isZipFile(filePath)) { - // Handle nested zip file - this.extractFile(zipIn, filePath); - - // Check if the entry is not in the root directory - String parentPath = null; - if (filePath.contains("/")) { // ZIP entries use "/" as a separator - parentPath = filePath.substring(0, filePath.lastIndexOf('/')); + if (isZipFile(filePath)) { + File zipFileExtractFolder = new File(rootFolder, PATH_TO_UNZIP_FILES); + for (String extracted : ZipUtils.unzipNested(filePath, zipFileExtractFolder.getAbsolutePath())) { + if (isSupportedFileType(extracted)) { + validFiles.add(extracted); + } } - - // Extract the last part of the path (file name + extension) - String fileNameWithExtension = filePath.contains("/") - ? filePath.substring(filePath.lastIndexOf('/') + 1) - : filePath; - - // Remove the extension - String baseName = fileNameWithExtension.contains(".") - ? fileNameWithExtension.substring(0, fileNameWithExtension.lastIndexOf('.')) - : fileNameWithExtension; - - unzipAndFilter(filePath, parentPath + "/" + baseName, validFiles, invalidFiles); + } else if (isSupportedFileType(filePath)) { + validFiles.add(filePath); + } else { + invalidFiles.add("/" + relativePath); } - - zipIn.closeEntry(); - entry = zipIn.getNextEntry(); } } } @@ -265,22 +208,6 @@ private String getRootFolder() { return AssetUtility.getRootFolderPath(this.insight, space, false); } - /** - * - * @param zipIn - * @param filePath - * @throws IOException - */ - private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { - try (FileOutputStream fos = new FileOutputStream(Utility.normalizePath(filePath))) { - byte[] buffer = new byte[1024]; - int bytesRead; - while ((bytesRead = zipIn.read(buffer)) != -1) { - fos.write(buffer, 0, bytesRead); - } - } - } - /** * * @param filePath diff --git a/src/prerna/util/ZipUtils.java b/src/prerna/util/ZipUtils.java index 73f3c362b9..312e68ebe3 100644 --- a/src/prerna/util/ZipUtils.java +++ b/src/prerna/util/ZipUtils.java @@ -98,6 +98,9 @@ public final class ZipUtils { */ public static final String ZIP_MAX_ENTRIES = "ZIP_MAX_ENTRIES"; + // how many zips inside zips unzipNested will open + public static final int MAX_NESTED_ZIP_DEPTH = 5; + /** * RDF_Map key for the most bytes a zip may expand to when extracted, counted as * they are written rather than from the sizes the zip declares. Defaults to 20 @@ -376,6 +379,30 @@ public static Map> unzip(String zipFilePath, String destina return listFilesInZip(Paths.get(zipFilePath)); } + // unzip, then unzip each zip it held beside itself (limited depth); returns the absolute paths of the files that are not zips + public static List unzipNested(String zipFilePath, String destination) throws IOException { + return unzipNested(zipFilePath, destination, 0); + } + + private static List unzipNested(String zipFilePath, String destination, int depth) throws IOException { + if (depth > MAX_NESTED_ZIP_DEPTH) { + throw new ZipException("The zip holds more than " + MAX_NESTED_ZIP_DEPTH + " levels of zips"); + } + Path folder = Paths.get(destination).toAbsolutePath().normalize(); + List files = new ArrayList<>(); + for (String relative : unzip(zipFilePath, destination).get("FILE")) { + Path extracted = folder.resolve(relative).normalize(); + String name = extracted.getFileName().toString(); + if (name.toLowerCase().endsWith(".zip")) { + String base = name.substring(0, name.length() - ".zip".length()); + files.addAll(unzipNested(extracted.toString(), extracted.resolveSibling(base).toString(), depth + 1)); + } else { + files.add(extracted.toString().replace('\\', '/')); + } + } + return files; + } + /** * Extracts a zip file into a folder. With {@code override}, the extracted * entries replace what is already there. Without it, each top level file or From 0c1e1575a959800c5571308c0f4acdc706a2866a Mon Sep 17 00:00:00 2001 From: Kunal Patel Date: Tue, 24 Nov 2026 15:19:59 -0500 Subject: [PATCH 2/5] fix(vector): stat a listed document only when it is a file directly in the documents folder The source names a vector database returns can be arbitrary (CSV Source column); a name with a path no longer reaches new File(documentsDir, name). --- .../engine/impl/vector/AbstractVectorDatabaseEngine.java | 9 +++++++++ .../vector/AzureAISearchRestVectorDatabaseEngine.java | 4 ++-- .../vector/ElasticSearchRestVectorDatabaseEngine.java | 4 ++-- src/prerna/engine/impl/vector/FaissDatabaseEngine.java | 4 ++-- .../engine/impl/vector/MilvusVectorDatabaseEngine.java | 4 ++-- .../impl/vector/OpenSearchRestVectorDatabaseEngine.java | 4 ++-- .../engine/impl/vector/PGVectorDatabaseEngine.java | 4 ++-- .../engine/impl/vector/PineConeVectorDatabaseEngine.java | 4 ++-- .../engine/impl/vector/WeaviateVectorDatabaseEngine.java | 4 ++-- 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java index 62a1d1e8b0..0d351fdea1 100644 --- a/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java @@ -496,6 +496,15 @@ public String getIndexFilesPath(String indexClass) { + INDEXED_FOLDER_NAME); } + // the stored copy of a listed document, or null unless its name is a plain file name directly inside the documents folder + public static File storedDocument(File documentsDir, String fileName) { + if (fileName == null || fileName.isEmpty()) { + return null; + } + File file = new File(documentsDir, fileName); + return documentsDir.equals(file.getParentFile()) ? file : null; + } + /** * * @param indexClass diff --git a/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java index 0afc514c7e..9a73bcb28e 100644 --- a/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java @@ -554,8 +554,8 @@ public List> listDocuments(Map parameters) { Map fileInfo = new HashMap<>(); String fileName = bucketDetails.get("value").getAsString(); fileInfo.put("fileName", fileName); - File thisF = new File(documentsDir, fileName); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, fileName); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java index 3a457139c8..94d64006b7 100644 --- a/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java @@ -554,8 +554,8 @@ public List> listDocuments(Map parameters) { String fileName = bucketDetails.get("key").getAsString(); fileInfo.put("fileName", fileName); - File thisF = new File(documentsDir, fileName); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, fileName); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/prerna/engine/impl/vector/FaissDatabaseEngine.java b/src/prerna/engine/impl/vector/FaissDatabaseEngine.java index 88f0a5b36e..5091eaaf47 100644 --- a/src/prerna/engine/impl/vector/FaissDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/FaissDatabaseEngine.java @@ -693,8 +693,8 @@ public List> listDocuments(Map parameters) { for (String fileName : sources) { Map fileInfo = new HashMap<>(); fileInfo.put("fileName", fileName); - File thisF = new File(documentsDir, fileName); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, fileName); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java index c99f2e23a2..218e2b3b2b 100644 --- a/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java @@ -453,8 +453,8 @@ public List> listDocuments(Map parameters) { Map fileInfo = new HashMap<>(); fileInfo.put("fileName", source); - File thisF = new File(documentsDir, source); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, source); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java index b933a1b6de..47109e3e8c 100644 --- a/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java @@ -856,8 +856,8 @@ public List> listDocuments(Map parameters) { for (String source : sources) { Map fileInfo = new HashMap<>(); fileInfo.put("fileName", source); - File thisF = new File(documentsDir, source); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, source); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java index 10b7486d4e..7128c9ece3 100644 --- a/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java @@ -837,8 +837,8 @@ public List> listDocuments(Map parameters) { for (Map fileInPostgresDb : sourcesInPostgresDb) { String fileName = (String) fileInPostgresDb.get("fileName"); - File thisF = new File(documentsDir, fileName); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, fileName); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java index c2904c9c84..a4a55d8301 100644 --- a/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java @@ -448,8 +448,8 @@ public List> listDocuments(Map parameters) { for (String fileName : sources) { Map fileInfo = new HashMap<>(); fileInfo.put("fileName", fileName); - File thisF = new File(documentsDir, fileName); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, fileName); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java index 22a7b75ff7..5217a4f8ee 100644 --- a/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java @@ -517,8 +517,8 @@ public List> listDocuments(Map parameters) { Map fileInfo = new HashMap<>(); fileInfo.put("fileName", fileName); - File thisF = new File(documentsDir, fileName); - if (thisF.exists() && thisF.isFile()) { + File thisF = AbstractVectorDatabaseEngine.storedDocument(documentsDir, fileName); + if (thisF != null && thisF.isFile()) { long fileSizeInBytes = thisF.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); From 1deeedf90c6e5c98bf2fa56f17c81cb4ced1b12e Mon Sep 17 00:00:00 2001 From: Kunal Patel Date: Tue, 24 Nov 2026 16:16:32 -0500 Subject: [PATCH 3/5] fix(zip): cap nested zip extraction with one shared budget and give each zip its own folder --- .../CreateEmbeddingsFromDocumentsReactor.java | 10 +- ...ateEmbeddingsFromVectorCSVFileReactor.java | 23 +++- src/prerna/util/ZipUtils.java | 124 +++++++++++------- 3 files changed, 107 insertions(+), 50 deletions(-) diff --git a/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java b/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java index 2b6264f836..4a9f32c906 100644 --- a/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java +++ b/src/prerna/reactor/vector/CreateEmbeddingsFromDocumentsReactor.java @@ -30,9 +30,12 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import org.apache.commons.io.FileUtils; @@ -227,7 +230,10 @@ private void getFiles(String rootFolder, List validFiles) throws IOExcep } if (isZipFile(filePath)) { File zipFileExtractFolder = new File(rootFolder, PATH_TO_UNZIP_FILES); - validFiles.addAll(ZipUtils.unzipNested(filePath, zipFileExtractFolder.getAbsolutePath())); + zipFileExtractFolder.mkdirs(); + // each zip gets its own folder so zips with the same file names never overwrite each other + Path zipDir = Files.createTempDirectory(zipFileExtractFolder.toPath(), "zip-"); + validFiles.addAll(ZipUtils.unzipNested(filePath, zipDir.toString())); } else { validFiles.add(filePath); } @@ -246,7 +252,7 @@ private boolean isZipFile(String filePath) { if (dotIndex > 0 && dotIndex < filePath.length() - 1) { // Extract the extension and convert it to lower case - String extension = filePath.substring(dotIndex + 1).toLowerCase(); + String extension = filePath.substring(dotIndex + 1).toLowerCase(Locale.ROOT); return extension.equals("zip"); } else { diff --git a/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java b/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java index 44458e74c5..ff4e8e4de9 100644 --- a/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java +++ b/src/prerna/reactor/vector/CreateEmbeddingsFromVectorCSVFileReactor.java @@ -30,11 +30,15 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; +import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tika.Tika; @@ -123,6 +127,16 @@ public NounMetadata execute() { } catch (Exception e) { classLogger.error("Error creating embeddings from vector CSV files for engine {}", engineId, e); throw new IllegalArgumentException("The following exception occured: " + e.getMessage()); + } finally { + File zipFileExtractionDir = new File(rootFolder + "/" + PATH_TO_UNZIP_FILES); + if (zipFileExtractionDir.exists()) { + try { + FileUtils.forceDelete(zipFileExtractionDir); + } catch (IOException e) { + classLogger.error("Error deleting temporary extraction directory {}", + zipFileExtractionDir.getAbsolutePath(), e); + } + } } NounMetadata noun = new NounMetadata(fileStatusList, PixelDataType.CUSTOM_DATA_STRUCTURE, @@ -180,7 +194,10 @@ private void getFiles(String rootFolder, List validFiles, List i } if (isZipFile(filePath)) { File zipFileExtractFolder = new File(rootFolder, PATH_TO_UNZIP_FILES); - for (String extracted : ZipUtils.unzipNested(filePath, zipFileExtractFolder.getAbsolutePath())) { + zipFileExtractFolder.mkdirs(); + // each zip gets its own folder so zips with the same file names never overwrite each other + Path zipDir = Files.createTempDirectory(zipFileExtractFolder.toPath(), "zip-"); + for (String extracted : ZipUtils.unzipNested(filePath, zipDir.toString())) { if (isSupportedFileType(extracted)) { validFiles.add(extracted); } @@ -217,7 +234,7 @@ private boolean isSupportedFileType(String filePath) { // Find the last index of '.' int dotIndex = filePath.lastIndexOf('.'); if (dotIndex > 0 && dotIndex < filePath.length() - 1) { - String extension = filePath.substring(dotIndex + 1).toLowerCase(); + String extension = filePath.substring(dotIndex + 1).toLowerCase(Locale.ROOT); return extension.equals("csv"); } @@ -235,7 +252,7 @@ private boolean isZipFile(String filePath) { if (dotIndex > 0 && dotIndex < filePath.length() - 1) { // Extract the extension and convert it to lower case - String extension = filePath.substring(dotIndex + 1).toLowerCase(); + String extension = filePath.substring(dotIndex + 1).toLowerCase(Locale.ROOT); return extension.equals("zip"); } else { diff --git a/src/prerna/util/ZipUtils.java b/src/prerna/util/ZipUtils.java index 312e68ebe3..92222257c3 100644 --- a/src/prerna/util/ZipUtils.java +++ b/src/prerna/util/ZipUtils.java @@ -57,6 +57,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -359,43 +360,64 @@ private static void addAllToZip(File file, ZipOutputStream zos, String prefix, L * @throws IOException if the zip cannot be read or an entry cannot be written */ public static Map> unzip(String zipFilePath, String destination) throws IOException { + Budget budget = new Budget(); + try { + return unzip(zipFilePath, destination, budget); + } catch (IOException | RuntimeException e) { + budget.undo(e); + throw e; + } + } + + // extracts under a shared budget; the caller rolls back on failure + private static Map> unzip(String zipFilePath, String destination, Budget budget) + throws IOException { Path zip = Paths.get(Utility.normalizePath(zipFilePath)); try (ZipFile zipIn = new ZipFile(zip.toFile())) { - Extraction extraction = new Extraction(zip, destination, zipIn.size()); - try { - Enumeration entries = zipIn.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - String entryPath = relativeEntryPath(entry); - if (!entryPath.isEmpty()) { - extraction.extract(zipIn, entry, extraction.resolve(entryPath, entry)); - } + Extraction extraction = new Extraction(zip, destination, zipIn.size(), budget); + Enumeration entries = zipIn.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + String entryPath = relativeEntryPath(entry); + if (!entryPath.isEmpty()) { + extraction.extract(zipIn, entry, extraction.resolve(entryPath, entry)); } - } catch (IOException | RuntimeException e) { - extraction.undo(e); - throw e; } } return listFilesInZip(Paths.get(zipFilePath)); } - // unzip, then unzip each zip it held beside itself (limited depth); returns the absolute paths of the files that are not zips + // unzip, then unzip each zip it held into its own new folder beside it (limited depth, one shared budget and rollback); + // returns the absolute paths of the files that are not zips public static List unzipNested(String zipFilePath, String destination) throws IOException { - return unzipNested(zipFilePath, destination, 0); + Budget budget = new Budget(); + try { + return unzipNested(zipFilePath, destination, 0, budget); + } catch (IOException | RuntimeException e) { + budget.undo(e); + throw e; + } } - private static List unzipNested(String zipFilePath, String destination, int depth) throws IOException { + private static List unzipNested(String zipFilePath, String destination, int depth, Budget budget) + throws IOException { if (depth > MAX_NESTED_ZIP_DEPTH) { throw new ZipException("The zip holds more than " + MAX_NESTED_ZIP_DEPTH + " levels of zips"); } Path folder = Paths.get(destination).toAbsolutePath().normalize(); List files = new ArrayList<>(); - for (String relative : unzip(zipFilePath, destination).get("FILE")) { + for (String relative : unzip(zipFilePath, destination, budget).get("FILE")) { Path extracted = folder.resolve(relative).normalize(); String name = extracted.getFileName().toString(); - if (name.toLowerCase().endsWith(".zip")) { + if (name.toLowerCase(Locale.ROOT).endsWith(".zip")) { String base = name.substring(0, name.length() - ".zip".length()); - files.addAll(unzipNested(extracted.toString(), extracted.resolveSibling(base).toString(), depth + 1)); + if (base.length() > 100) { + base = base.substring(0, 100); + } + // a new folder so a sibling named like the zip, or a file named ".zip", never collides + Path nested = Files.createTempDirectory(extracted.getParent(), (base.isEmpty() ? "zip" : base) + "-"); + budget.created.add(nested); + files.addAll(unzipNested(extracted.toString(), nested.toString(), depth + 1, budget)); } else { files.add(extracted.toString().replace('\\', '/')); } @@ -428,7 +450,8 @@ public static Map unzip(String zipFilePath, String destination, Map topLevelNames = new LinkedHashMap<>(); Path zip = Paths.get(Utility.normalizePath(zipFilePath)); try (ZipFile zipIn = new ZipFile(zip.toFile())) { - Extraction extraction = new Extraction(zip, destination, zipIn.size()); + Budget budget = new Budget(); + Extraction extraction = new Extraction(zip, destination, zipIn.size(), budget); try { Enumeration entries = zipIn.entries(); while (entries.hasMoreElements()) { @@ -456,7 +479,7 @@ public static Map unzip(String zipFilePath, String destination, extraction.extract(zipIn, entry, extraction.resolve(extractedPath, entry)); } } catch (IOException | RuntimeException e) { - extraction.undo(e); + budget.undo(e); throw e; } } @@ -542,9 +565,8 @@ private static final class Extraction { private final Path folder; private final long zipSize; - private final long maxExtractedBytes; private final long maxCompressionRatio; - private final List created = new ArrayList<>(); + private final Budget budget; private final Set checkedDirectories = new HashSet<>(); private long extractedBytes = 0; @@ -558,17 +580,13 @@ private static final class Extraction { * @throws IOException if the zip has too many entries or the folder cannot be * created */ - private Extraction(Path zip, String destination, int entryCount) throws IOException { - long maxEntries = limit(ZIP_MAX_ENTRIES, DEFAULT_MAX_ENTRIES); - if (entryCount > maxEntries) { - throw new ZipException("The zip has " + entryCount + " entries, more than the " + maxEntries - + " this server extracts (" + ZIP_MAX_ENTRIES + ")"); - } + private Extraction(Path zip, String destination, int entryCount, Budget budget) throws IOException { + this.budget = budget; + budget.addEntries(entryCount); Path requested = Paths.get(destination); Files.createDirectories(requested); this.folder = requested.toRealPath(); this.zipSize = Math.max(Files.size(zip), 1); - this.maxExtractedBytes = limit(ZIP_MAX_EXTRACTED_BYTES, DEFAULT_MAX_EXTRACTED_BYTES); this.maxCompressionRatio = limit(ZIP_MAX_COMPRESSION_RATIO, DEFAULT_MAX_COMPRESSION_RATIO); this.checkedDirectories.add(this.folder); } @@ -596,7 +614,7 @@ private Path resolve(String relativePath, ZipEntry entry) throws ZipException { * @param path the file or folder created */ private void created(Path path) { - created.add(path); + budget.created.add(path); } /** @@ -629,7 +647,7 @@ private void extract(ZipFile zip, ZipEntry entry, Path target) throws IOExceptio deleteQuietly(part); } if (!existed) { - created.add(target); + budget.created.add(target); } } @@ -646,11 +664,7 @@ private void copy(InputStream in, OutputStream out) throws IOException { int read; while ((read = in.read(buffer)) != -1) { extractedBytes += read; - if (extractedBytes > maxExtractedBytes) { - throw new ZipException( - "The zip expands to more than " + FileUtils.byteCountToDisplaySize(maxExtractedBytes) - + ", the most this server extracts (" + ZIP_MAX_EXTRACTED_BYTES + ")"); - } + budget.addBytes(read); if (extractedBytes > RATIO_CHECK_FLOOR && extractedBytes / zipSize > maxCompressionRatio) { throw new ZipException("The zip expands to more than " + maxCompressionRatio + " times its size, the most this server extracts (" + ZIP_MAX_COMPRESSION_RATIO + ")"); @@ -690,20 +704,40 @@ private void createDirectories(Path directory, ZipEntry entry) throws IOExceptio } for (Path next : missing) { Files.createDirectory(next); - created.add(next); + budget.created.add(next); } checkedDirectories.add(directory); } + } - /** - * Removes the files and folders this extraction created, newest first, after it - * failed. - * - * @param cause why the extraction failed - */ + // what one call may extract in total across all its zips (nested ones included), and what it created, for rollback + private static final class Budget { + + private final long maxEntries = limit(ZIP_MAX_ENTRIES, DEFAULT_MAX_ENTRIES); + private final long maxBytes = limit(ZIP_MAX_EXTRACTED_BYTES, DEFAULT_MAX_EXTRACTED_BYTES); + private final List created = new ArrayList<>(); + private long entries = 0; + private long bytes = 0; + + private void addEntries(int count) throws ZipException { + entries += count; + if (entries > maxEntries) { + throw new ZipException("The zip has " + entries + " entries, more than the " + maxEntries + + " this server extracts (" + ZIP_MAX_ENTRIES + ")"); + } + } + + private void addBytes(long count) throws ZipException { + bytes += count; + if (bytes > maxBytes) { + throw new ZipException("The zip expands to more than " + FileUtils.byteCountToDisplaySize(maxBytes) + + ", the most this server extracts (" + ZIP_MAX_EXTRACTED_BYTES + ")"); + } + } + + // removes what was created, newest first, after a failure private void undo(Exception cause) { - classLogger.warn("Removing what was extracted into '{}' after the extraction failed: {}", folder, - cause.getMessage()); + classLogger.warn("Removing what was extracted after the extraction failed: {}", cause.getMessage()); for (int i = created.size() - 1; i >= 0; i--) { deleteQuietly(created.get(i)); } From 96948b8ea7f8952ee6ad20b650f425b478a7a7c5 Mon Sep 17 00:00:00 2001 From: Kunal Patel Date: Tue, 24 Nov 2026 16:16:32 -0500 Subject: [PATCH 4/5] fix(vector): delete a removed document's stored copy only when it is a file in the documents folder --- .../vector/AbstractVectorDatabaseEngine.java | 32 ++++++++++++++++--- ...AzureAISearchRestVectorDatabaseEngine.java | 4 +-- .../vector/ChromaVectorDatabaseEngine.java | 6 ++-- ...ElasticSearchRestVectorDatabaseEngine.java | 4 +-- .../impl/vector/FaissDatabaseEngine.java | 6 ++-- .../vector/MilvusVectorDatabaseEngine.java | 4 +-- .../OpenSearchRestVectorDatabaseEngine.java | 4 +-- .../impl/vector/PGVectorDatabaseEngine.java | 4 +-- .../vector/PineConeVectorDatabaseEngine.java | 8 ++--- .../vector/WeaviateVectorDatabaseEngine.java | 6 ++-- 10 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java index 0d351fdea1..329f41c3d5 100644 --- a/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/AbstractVectorDatabaseEngine.java @@ -29,6 +29,9 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; @@ -496,13 +499,34 @@ public String getIndexFilesPath(String indexClass) { + INDEXED_FOLDER_NAME); } - // the stored copy of a listed document, or null unless its name is a plain file name directly inside the documents folder + // the stored copy of a listed document, or null unless it is an existing regular file directly inside the documents folder public static File storedDocument(File documentsDir, String fileName) { - if (fileName == null || fileName.isEmpty()) { + if (documentsDir == null || fileName == null || fileName.isEmpty() || ".".equals(fileName) + || "..".equals(fileName) || fileName.indexOf('/') >= 0 || fileName.indexOf('\\') >= 0 + || fileName.indexOf('\0') >= 0) { return null; } - File file = new File(documentsDir, fileName); - return documentsDir.equals(file.getParentFile()) ? file : null; + try { + Path realDir = documentsDir.toPath().toRealPath(); + Path candidate = realDir.resolve(fileName); + // the real path rules out a link that leads out of the folder + if (!Files.isRegularFile(candidate) || !realDir.equals(candidate.toRealPath().getParent())) { + return null; + } + return new File(documentsDir, fileName); + } catch (IOException | InvalidPathException e) { + return null; + } + } + + // the stored copy to delete with a removed document, or null (logged) when there is none to delete safely + protected static File storedDocumentToRemove(File documentsDir, String documentName) { + File file = storedDocument(documentsDir, documentName); + if (file == null) { + classLogger.warn("Not deleting a stored copy of '{}': it is missing or not a file directly in the documents folder", + documentName); + } + return file; } /** diff --git a/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java index 9a73bcb28e..4a28de1be1 100644 --- a/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/AzureAISearchRestVectorDatabaseEngine.java @@ -426,8 +426,8 @@ public void removeDocument(List fileNames, Map parameter for (String document : sourceNames) { String documentName = Paths.get(document).getFileName().toString(); // remove the physical documents - File documentFile = new File(DOCUMENT_FOLDER, documentName); - if (documentFile.exists()) { + File documentFile = storedDocumentToRemove(new File(DOCUMENT_FOLDER), documentName); + if (documentFile != null) { try { FileUtils.forceDelete(documentFile); } catch (IOException e) { diff --git a/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java index 1d13436fca..0ae3a5fc13 100644 --- a/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java @@ -290,9 +290,9 @@ public void removeDocument(List fileNames, Map parameter String documentName = Paths.get(fileName).getFileName().toString(); // remove the physical documents - File documentFile = new File(this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + indexClass + FILE_SEPARATOR + "documents", documentName); + File documentFile = storedDocumentToRemove(new File(this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + indexClass + FILE_SEPARATOR + "documents"), documentName); try { - if (documentFile.exists()) { + if (documentFile != null) { FileUtils.forceDelete(documentFile); filesToRemoveFromCloud.add(documentFile.getAbsolutePath()); } @@ -402,4 +402,4 @@ public VectorDatabaseTypeEnum getVectorDatabaseType() { return VectorDatabaseTypeEnum.CHROMA; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java index 94d64006b7..110660b85f 100644 --- a/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/ElasticSearchRestVectorDatabaseEngine.java @@ -359,8 +359,8 @@ public void removeDocument(List fileNames, Map parameter for (String document : fileNames) { String documentName = Paths.get(document).getFileName().toString(); // remove the physical documents - File documentFile = new File(DOCUMENT_FOLDER, documentName); - if (documentFile.exists()) { + File documentFile = storedDocumentToRemove(new File(DOCUMENT_FOLDER), documentName); + if (documentFile != null) { try { FileUtils.forceDelete(documentFile); } catch (IOException e) { diff --git a/src/prerna/engine/impl/vector/FaissDatabaseEngine.java b/src/prerna/engine/impl/vector/FaissDatabaseEngine.java index 5091eaaf47..45a9738c79 100644 --- a/src/prerna/engine/impl/vector/FaissDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/FaissDatabaseEngine.java @@ -459,9 +459,9 @@ public void removeDocument(List fileNames, Map parameter } try { - File documentFile = new File(this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + indexClass - + FILE_SEPARATOR + "documents", document); - if (documentFile.exists() && documentFile.isFile()) { + File documentFile = storedDocumentToRemove(new File(this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + + indexClass + FILE_SEPARATOR + "documents"), documentName); + if (documentFile != null) { FileUtils.forceDelete(documentFile); filesToRemoveFromCloud.add(documentFile.getAbsolutePath()); } diff --git a/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java index 218e2b3b2b..3639b609bf 100644 --- a/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/MilvusVectorDatabaseEngine.java @@ -312,9 +312,9 @@ public void removeDocument(List fileNames, Map parameter List filesToRemoveFromCloud = new ArrayList<>(); for (String name : fileNames) { String documentName = Paths.get(name).getFileName().toString(); - File documentFile = new File(DOCUMENT_FOLDER, documentName); + File documentFile = storedDocumentToRemove(new File(DOCUMENT_FOLDER), documentName); - if (documentFile.exists()) { + if (documentFile != null) { try { FileUtils.forceDelete(documentFile); } catch (IOException e) { diff --git a/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java index 47109e3e8c..6101586843 100644 --- a/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/OpenSearchRestVectorDatabaseEngine.java @@ -555,8 +555,8 @@ public void removeDocument(List fileNames, Map parameter for (String document : sourceNames) { String documentName = Paths.get(document).getFileName().toString(); // remove the physical documents - File documentFile = new File(DOCUMENT_FOLDER, documentName); - if (documentFile.exists()) { + File documentFile = storedDocumentToRemove(new File(DOCUMENT_FOLDER), documentName); + if (documentFile != null) { try { FileUtils.forceDelete(documentFile); } catch (IOException e) { diff --git a/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java index 7128c9ece3..451072295b 100644 --- a/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/PGVectorDatabaseEngine.java @@ -603,8 +603,8 @@ public void removeDocument(List fileNames, Map parameter for (String document : sourceNames) { String documentName = Paths.get(document).getFileName().toString(); // remove the physical documents - File documentFile = new File(DOCUMENT_FOLDER, documentName); - if (documentFile.exists()) { + File documentFile = AbstractVectorDatabaseEngine.storedDocumentToRemove(new File(DOCUMENT_FOLDER), documentName); + if (documentFile != null) { FileUtils.forceDelete(documentFile); filesToRemoveFromCloud.add(documentFile.getAbsolutePath()); } diff --git a/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java index a4a55d8301..886fc6c246 100644 --- a/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java @@ -274,11 +274,11 @@ public void removeDocument(List fileNames, Map parameter String documentName = Paths.get(fileName).getFileName().toString(); // remove the physical documents - File documentFile = new File( - this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + indexClass + FILE_SEPARATOR + "documents", + File documentFile = storedDocumentToRemove(new File( + this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + indexClass + FILE_SEPARATOR + "documents"), documentName); try { - if (documentFile.exists()) { + if (documentFile != null) { FileUtils.forceDelete(documentFile); filesToRemoveFromCloud.add(documentFile.getAbsolutePath()); } @@ -594,4 +594,4 @@ public VectorDatabaseTypeEnum getVectorDatabaseType() { return VectorDatabaseTypeEnum.PINECONE; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java index 5217a4f8ee..5dd0ad5a52 100644 --- a/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/WeaviateVectorDatabaseEngine.java @@ -378,11 +378,11 @@ public void removeDocument(List fileNames, Map parameter String documentName = Paths.get(sourceName).getFileName().toString(); // remove the physical documents - File documentFile = new File( - this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + indexClass + FILE_SEPARATOR + "documents", + File documentFile = storedDocumentToRemove(new File( + this.schemaFolder.getAbsolutePath() + FILE_SEPARATOR + indexClass + FILE_SEPARATOR + "documents"), documentName); try { - if (documentFile.exists()) { + if (documentFile != null) { FileUtils.forceDelete(documentFile); filesToRemoveFromCloud.add(documentFile.getAbsolutePath()); } From da5cd8571cdc4f067d9767e8ba43a49f6de2eeb5 Mon Sep 17 00:00:00 2001 From: Kunal Patel Date: Tue, 24 Nov 2026 16:18:29 -0500 Subject: [PATCH 5/5] chore(vector): drop a stray carriage return added at the end of two engine files --- src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java | 2 +- src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java index 0ae3a5fc13..31f57f077e 100644 --- a/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/ChromaVectorDatabaseEngine.java @@ -402,4 +402,4 @@ public VectorDatabaseTypeEnum getVectorDatabaseType() { return VectorDatabaseTypeEnum.CHROMA; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java b/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java index 886fc6c246..f63b084732 100644 --- a/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java +++ b/src/prerna/engine/impl/vector/PineConeVectorDatabaseEngine.java @@ -594,4 +594,4 @@ public VectorDatabaseTypeEnum getVectorDatabaseType() { return VectorDatabaseTypeEnum.PINECONE; } -} \ No newline at end of file +} \ No newline at end of file