From 44a8be7ec237487b706a5413eb8cb6d409f64a18 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 1 Apr 2024 15:37:32 +0200 Subject: [PATCH 1/2] fix fileheader match for renaming --- src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java b/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java index 179d9c90..df241475 100644 --- a/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java +++ b/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java @@ -125,7 +125,7 @@ private Map.Entry getCorrespondingEntryFromMap(FileHeader fileHe String> fileNamesMap) { for (Map.Entry fileHeaderToBeRenamed : fileNamesMap.entrySet()) { - if (fileHeaderToBeChecked.getFileName().startsWith(fileHeaderToBeRenamed.getKey())) { + if (fileHeaderToBeChecked.getFileName().equals(fileHeaderToBeRenamed.getKey())) { return fileHeaderToBeRenamed; } } From 535979d84d8b188dc452e52f707de3da04116549 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 1 Apr 2024 16:46:35 +0200 Subject: [PATCH 2/2] seems that folder renaming is supported --- .../java/net/lingala/zip4j/tasks/RenameFilesTask.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java b/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java index df241475..05402e44 100644 --- a/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java +++ b/src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java @@ -125,9 +125,11 @@ private Map.Entry getCorrespondingEntryFromMap(FileHeader fileHe String> fileNamesMap) { for (Map.Entry fileHeaderToBeRenamed : fileNamesMap.entrySet()) { - if (fileHeaderToBeChecked.getFileName().equals(fileHeaderToBeRenamed.getKey())) { - return fileHeaderToBeRenamed; - } + if (fileHeaderToBeRenamed.getKey().endsWith(InternalZipConstants.ZIP_FILE_SEPARATOR) && fileHeaderToBeChecked.getFileName().startsWith(fileHeaderToBeRenamed.getKey())) { + return fileHeaderToBeRenamed; + } else if (fileHeaderToBeChecked.getFileName().equals(fileHeaderToBeRenamed.getKey())) { + return fileHeaderToBeRenamed; + } } return null;