This is an automated email from the ASF dual-hosted git repository.
bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new fee1687a04 Fix#9175 Correct Move/Delete/Zip action results and
success conditions (#9246)
fee1687a04 is described below
commit fee1687a04c285341cfb7b757e96ae50735a28a7
Author: Lance <[email protected]>
AuthorDate: Thu Nov 5 00:15:28 2026 +0800
Fix#9175 Correct Move/Delete/Zip action results and success conditions
(#9246)
* Fix Correct Move/Delete/Zip action results and success conditions
Signed-off-by: leehaut <[email protected]>
* Fix Correct Move/Delete/Zip action results and success conditions
Signed-off-by: leehaut <[email protected]>
---------
Signed-off-by: leehaut <[email protected]>
---
.../ROOT/pages/workflow/actions/deletefiles.adoc | 4 +-
.../ROOT/pages/workflow/actions/movefiles.adoc | 2 +-
.../ROOT/pages/workflow/actions/zipfile.adoc | 8 +-
.../actions/deletefiles/ActionDeleteFiles.java | 78 +++----
.../deletefiles/ActionDeleteFilesResultTest.java | 102 +++++++++
.../actions/movefiles/ActionMoveFiles.java | 55 ++---
.../movefiles/ActionMoveFilesResultTest.java | 234 +++++++++++++++++++++
.../WorkflowActionMoveFilesLocalTest.java | 1 +
.../workflow/actions/zipfile/ActionZipFile.java | 12 +-
.../actions/zipfile/ActionZipFileResultTest.java | 223 ++++++++++++++++++++
10 files changed, 645 insertions(+), 74 deletions(-)
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deletefiles.adoc
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deletefiles.adoc
index b6b3fe4dcb..689d80d854 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deletefiles.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deletefiles.adoc
@@ -48,7 +48,7 @@ What this action passes on to the next action. See
xref:workflow/action-results.
|True|Every file and folder in the list was processed. A path that doesn't
exist counts as already deleted. For a single file the wildcard is not used.
|False|A file could not be deleted. The number of errors is the number of
entries in the list that failed.
|Result files|Passed on unchanged. The deleted files are not added.
-|Result rows|Passed on unchanged. With *Copy previous results to args*, the
action takes the path from the first field and the wildcard from the second
field of each result row, and ignores the list in the dialog, also when there
are no result rows. A row with fewer than two fields stops the action: the
remaining rows are not processed, and the action is still true.
+|Result rows|Passed on unchanged. With *Copy previous results to args*, the
action takes the path from the first field and the wildcard from the second
field of each result row, and ignores the list in the dialog, also when there
are no result rows. A row with fewer than two fields stops the action before
anything is deleted: nothing is deleted, and the action is false.
|===
-NOTE: An invalid regular expression in *Wildcard* deletes nothing, and the
action is still true.
+NOTE: An invalid regular expression in *Wildcard* deletes nothing, and the
action is false.
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/movefiles.adoc
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/movefiles.adoc
index 83d8be3a88..58030043b1 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/movefiles.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/movefiles.adoc
@@ -118,4 +118,4 @@ What this action passes on to the next action. See
xref:workflow/action-results.
|Result rows|Passed on unchanged. With *Copy previous results to args*, the
source, destination and wildcard come from the first three fields of each
result row.
|===
-NOTE: With *Success when number of errors lesser than*, the action stops and
is false as soon as the number of errors reaches *Nr errors lesser than*, but
when the last file brings it to that number, the action is still true. With *If
destination file exists* set to *Fail*, a file that already exists counts as
two errors.
+NOTE: With *Success when number of errors lesser than*, the action stops and
is false as soon as the number of errors reaches *Nr errors lesser than*
(strictly fewer errors than the limit is required for success).
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/zipfile.adoc
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/zipfile.adoc
index 00abff0da4..9b71cb4dec 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/zipfile.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/zipfile.adoc
@@ -89,10 +89,10 @@ What this action passes on to the next action. See
xref:workflow/action-results.
[options="header", width="90%", cols="1,3"]
|===
|Result|Value
-|True|The zip file was created or updated. It is also true when the zip exists
and *If zip file exists* is *Do Nothing*, which leaves it unchanged, and when
no file matches the wildcard with *Include sub-folders* off, which creates an
empty zip. With *Include sub-folders* on, no match makes the action false and
creates no zip.
-|False|The source doesn't exist, the zip exists and *If zip file exists* is
*Fail*, the zip can't be written, or a source file can't be deleted with *After
zipping*; the zip is already created then. With *After zipping* set to *Move
files*, it is also false when the folder to move to doesn't exist and *Create
folder* is off. The number of errors is 1.
+|True|The zip file was created or updated. It is also true when the zip exists
and *If zip file exists* is *Do Nothing*, which leaves it unchanged, and when
no file matches the wildcard with *Include sub-folders* off, which creates an
empty zip. With *Include sub-folders* on, no match makes the action false and
creates no zip. With *Get arguments from previous*, every result row that
produces a zip must succeed for the action to be true.
+|False|The source doesn't exist, *Source directory/file* is empty, the zip
exists and *If zip file exists* is *Fail*, the zip can't be written, or a
source file can't be deleted or moved with *After zipping*; the zip is already
created then. With *After zipping* set to *Move files*, it is also false when
the folder to move to doesn't exist and *Create folder* is off. The number of
errors is 1.
|Result files|With *Add Zip file to result*, the zip file is added, also an
existing zip left unchanged by *Do Nothing*. A zip whose creation fails is not
added, but a zip that was created stays in the result files even when the
action ends up false.
-|Result rows|Passed on unchanged. With *Get arguments from previous*, every
result row gives the source (first field), the include wildcard (second), the
exclude wildcard (third) and the zip file name (fourth). A row with an empty
source or zip file name is skipped. The first row that fails ends the action,
which is then false; the zips of the earlier rows stay, and are in the result
files. When every row is zipped, the result of the previous action is passed
on, true or false.
+|Result rows|Passed on unchanged. With *Get arguments from previous*, every
result row gives the source (first field), the include wildcard (second), the
exclude wildcard (third) and the zip file name (fourth). A row with an empty
source or zip file name is skipped: if at least one other row is zipped the
action is true, and if every row is skipped the action is false. The first row
that fails ends the action, which is then false; the zips of the earlier rows
stay, and are in the result [...]
|===
-NOTE: With an empty *Source directory/file*, or with *Get arguments from
previous* and no result rows, nothing is zipped and the result of the previous
action is passed on. A source file that can't be moved with *After zipping* set
to *Move files* is only logged: the action is still true, and the zip is in the
result files.
+NOTE: With an empty *Source directory/file*, nothing is zipped and the action
is false. With *Get arguments from previous* and no result rows, nothing is
zipped and the action is false. A source file that can't be moved with *After
zipping* set to *Move files* makes the action false; the zip stays in the
result files when *Add Zip file to result* is selected.
diff --git
a/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
b/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
index a4f30b5d51..a23ce2bb14 100644
---
a/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
+++
b/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
@@ -103,7 +103,15 @@ public class ActionDeleteFiles extends ActionBase {
String.valueOf((resultRows != null ? resultRows.size() : 0))));
}
- Multimap<String, String> pathToMaskMap =
populateDataForWorkflowExecution(resultRows);
+ Multimap<String, String> pathToMaskMap;
+ try {
+ pathToMaskMap = populateDataForWorkflowExecution(resultRows);
+ } catch (HopValueException e) {
+ logError(e.getMessage());
+ result.setNrErrors(1);
+ result.setResult(false);
+ return result;
+ }
for (Map.Entry<String, String> pathToMask : pathToMaskMap.entries()) {
final String filePath = resolve(pathToMask.getKey());
@@ -156,12 +164,11 @@ public class ActionDeleteFiles extends ActionBase {
if (argFromPrevious && rowsFromPreviousMeta != null) {
for (RowMetaAndData resultRow : rowsFromPreviousMeta) {
if (resultRow.size() < 2) {
- logError(
+ throw new HopValueException(
BaseMessages.getString(
PKG,
"ActionDeleteFiles.Error.InvalidNumberOfRowsFromPrevMeta",
resultRow.size()));
- return pathToMaskMap;
}
String pathToFile = resultRow.getString(0, null);
String fileMask = resultRow.getString(1, null);
@@ -199,9 +206,11 @@ public class ActionDeleteFiles extends ActionBase {
logDetailed(BaseMessages.getString(PKG,
"ActionDeleteFiles.ProcessingFolder", path));
}
+ final Pattern compiledWildcard = compileWildcard(wildcard);
+
int totalDeleted =
fileFolder.delete(
- new TextFileSelector(fileFolder.toString(), wildcard,
parentWorkflow));
+ new TextFileSelector(fileFolder.toString(),
compiledWildcard, parentWorkflow));
if (isDetailed()) {
logDetailed(
@@ -239,21 +248,26 @@ public class ActionDeleteFiles extends ActionBase {
return isDeleted;
}
+ /**
+ * Compile the file-mask regex once. An invalid expression must fail the
action instead of being
+ * swallowed while selecting files.
+ */
+ private static Pattern compileWildcard(String wildcard) {
+ if (Utils.isEmpty(wildcard)) {
+ return null;
+ }
+ return Pattern.compile(wildcard);
+ }
+
private class TextFileSelector implements FileSelector {
- String fileWildcard = null;
- String sourceFolder = null;
- IWorkflowEngine<WorkflowMeta> workflow;
+ private final Pattern fileWildcard;
+ private final String sourceFolder;
+ private final IWorkflowEngine<WorkflowMeta> workflow;
public TextFileSelector(
- String sourceFolder, String fileWildcard,
IWorkflowEngine<WorkflowMeta> workflow) {
-
- if (!Utils.isEmpty(sourceFolder)) {
- this.sourceFolder = sourceFolder;
- }
-
- if (!Utils.isEmpty(fileWildcard)) {
- this.fileWildcard = fileWildcard;
- }
+ String sourceFolder, Pattern fileWildcard,
IWorkflowEngine<WorkflowMeta> workflow) {
+ this.sourceFolder = sourceFolder;
+ this.fileWildcard = fileWildcard;
this.workflow = workflow;
}
@@ -270,7 +284,7 @@ public class ActionDeleteFiles extends ActionBase {
// Not in the Base Folder. Only if include sub folders
if (includeSubfolders
&& (info.getFile().getType() == FileType.FILE)
- && getFileWildcard(shortFilename, fileWildcard)) {
+ && matchesWildcard(shortFilename)) {
if (isDetailed()) {
logDetailed(
BaseMessages.getString(
@@ -280,8 +294,7 @@ public class ActionDeleteFiles extends ActionBase {
}
} else {
// In the Base Folder...
- if ((info.getFile().getType() == FileType.FILE)
- && getFileWildcard(shortFilename, fileWildcard)) {
+ if ((info.getFile().getType() == FileType.FILE) &&
matchesWildcard(shortFilename)) {
if (isDetailed()) {
logDetailed(
BaseMessages.getString(
@@ -305,31 +318,20 @@ public class ActionDeleteFiles extends ActionBase {
return doReturnCode;
}
+ private boolean matchesWildcard(String selectedFile) {
+ if (fileWildcard == null) {
+ return true;
+ }
+ Matcher matcher = fileWildcard.matcher(selectedFile);
+ return matcher.matches();
+ }
+
@Override
public boolean traverseDescendents(FileSelectInfo info) {
return info.getDepth() == 0 || includeSubfolders;
}
}
- /**********************************************************
- *
- * @param selectedfile
- * @param wildcard
- * @return True if the selected file matches the wildcard
- **********************************************************/
- private boolean getFileWildcard(String selectedfile, String wildcard) {
- boolean getIt = true;
-
- if (!Utils.isEmpty(wildcard)) {
- Pattern pattern = Pattern.compile(wildcard);
- // First see if the file matches the regular expression!
- Matcher matcher = pattern.matcher(selectedfile);
- getIt = matcher.matches();
- }
-
- return getIt;
- }
-
@Override
public boolean isEvaluation() {
return true;
diff --git
a/plugins/actions/deletefiles/src/test/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFilesResultTest.java
b/plugins/actions/deletefiles/src/test/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFilesResultTest.java
new file mode 100644
index 0000000000..392064c8a1
--- /dev/null
+++
b/plugins/actions/deletefiles/src/test/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFilesResultTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.workflow.actions.deletefiles;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import org.apache.hop.core.HopEnvironment;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.RowMetaAndData;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.LogLevel;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.workflow.Workflow;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/** Result behaviour for Delete files (issue #9175 cases 3 and 4). */
+class ActionDeleteFilesResultTest {
+
+ @TempDir Path testFolder;
+
+ private ActionDeleteFiles action;
+
+ @BeforeAll
+ static void setUpBeforeClass() throws Exception {
+ HopLogStore.init();
+ HopEnvironment.init();
+ }
+
+ @BeforeEach
+ void setUp() {
+ action = new ActionDeleteFiles();
+ IWorkflowEngine<WorkflowMeta> parentWorkflow = mock(Workflow.class);
+ doReturn(false).when(parentWorkflow).isStopped();
+ doReturn(LogLevel.BASIC).when(parentWorkflow).getLogLevel();
+ action.setParentWorkflow(parentWorkflow);
+ action.setParentWorkflowMeta(mock(WorkflowMeta.class));
+ action.setIncludeSubfolders(false);
+ }
+
+ /** #9175 case 3: invalid regex must fail the action, not succeed with zero
deletes. */
+ @Test
+ void invalidRegexWildcardFailsTheAction() throws Exception {
+ Path folder = Files.createDirectories(testFolder.resolve("folder"));
+ Path keep = folder.resolve("keep-me.txt");
+ Files.writeString(keep, "should remain", StandardCharsets.UTF_8);
+
+ action.setArgFromPrevious(false);
+ action.setFileItems(List.of(new FileItem(folder.toString(), "[")));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertFalse(result.isResult(), "invalid regex must not succeed");
+ assertTrue(result.getNrErrors() > 0);
+ assertTrue(Files.exists(keep), "file must not be deleted when the mask is
invalid");
+ }
+
+ /** #9175 case 4: a previous result row with fewer than two fields must fail
the action. */
+ @Test
+ void previousRowWithFewerThanTwoFieldsFailsTheAction() throws Exception {
+ action.setArgFromPrevious(true);
+
+ RowMeta meta = new RowMeta();
+ meta.addValueMeta(new ValueMetaString("path_only"));
+ Result previous = new Result();
+ previous.setRows(List.of(new RowMetaAndData(meta,
testFolder.resolve("folder").toString())));
+ previous.setResult(true);
+
+ Result result = action.execute(previous, 0);
+
+ assertFalse(result.isResult(), "short previous row must fail Delete
files");
+ assertEquals(1, result.getNrErrors());
+ }
+}
diff --git
a/plugins/actions/movefiles/src/main/java/org/apache/hop/workflow/actions/movefiles/ActionMoveFiles.java
b/plugins/actions/movefiles/src/main/java/org/apache/hop/workflow/actions/movefiles/ActionMoveFiles.java
index 0f81547be1..c657d81c1d 100644
---
a/plugins/actions/movefiles/src/main/java/org/apache/hop/workflow/actions/movefiles/ActionMoveFiles.java
+++
b/plugins/actions/movefiles/src/main/java/org/apache/hop/workflow/actions/movefiles/ActionMoveFiles.java
@@ -264,9 +264,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
PKG,
CONST_ACTION_MOVE_FILES_ERROR_SUCCESS_CONDITIONBROKEN, "" + nrErrors));
successConditionBrokenExit = true;
}
- result.setNrErrors(nrErrors);
- displayResults();
- return result;
+ return finishWithSuccessCondition(result);
}
resultRow = rows.get(iteration);
@@ -324,9 +322,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
PKG,
CONST_ACTION_MOVE_FILES_ERROR_SUCCESS_CONDITIONBROKEN, "" + nrErrors));
successConditionBrokenExit = true;
}
- result.setNrErrors(nrErrors);
- displayResults();
- return result;
+ return finishWithSuccessCondition(result);
}
if (!Utils.isEmpty(vFileToMove.getSourceFileFolder())
@@ -366,15 +362,20 @@ public class ActionMoveFiles extends ActionBase
implements Cloneable, IAction {
}
}
- // Success Condition
+ return finishWithSuccessCondition(result);
+ }
+
+ /**
+ * Apply the success condition to {@code result}. Used both for the normal
end of {@link #execute}
+ * and for early exit when the error limit is reached, so the same nrErrors
cannot yield true in
+ * one path and false in the other.
+ */
+ private Result finishWithSuccessCondition(Result result) {
result.setNrErrors(nrErrors);
result.setNrLinesWritten(nrSuccess);
- if (getSuccessStatus()) {
- result.setResult(true);
- }
+ result.setResult(getSuccessStatus());
displayResults();
-
return result;
}
@@ -390,10 +391,11 @@ public class ActionMoveFiles extends ActionBase
implements Cloneable, IAction {
}
private boolean getSuccessStatus() {
+ // SUCCESS_IF_ERRORS_LESS matches the UI label "Nr errors lesser than"
(strict <).
return (nrErrors == 0 &&
getSuccessCondition().equals(SUCCESS_IF_NO_ERRORS))
|| (nrSuccess >= limitFiles
&&
getSuccessCondition().equals(SUCCESS_IF_AT_LEAST_X_FILES_UN_ZIPPED))
- || (nrErrors <= limitFiles &&
getSuccessCondition().equals(SUCCESS_IF_ERRORS_LESS));
+ || (nrErrors < limitFiles &&
getSuccessCondition().equals(SUCCESS_IF_ERRORS_LESS));
}
private boolean processFileFolder(
@@ -440,9 +442,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
"ActionMoveFiles.Log.CanNotMoveFolderToFile",
realSourceFilefoldername,
realDestinationFilefoldername));
-
- // Update Errors
- updateErrors();
+ // Leave entryStatus false so the caller counts the error once.
} else {
if (destinationFileFolder.getType().equals(FileType.FOLDER)
&& sourceFileFolder.getType().equals(FileType.FILE)) {
@@ -565,7 +565,8 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
if (fileObjects != null) {
for (int j = 0; j < fileObjects.length &&
!parentWorkflow.isStopped(); j++) {
- // Success condition broken?
+ // Success condition broken? Errors are already counted;
return true so the
+ // caller does not increment nrErrors again.
if (successConditionBroken) {
if (!successConditionBrokenExit) {
logError(
@@ -575,7 +576,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
"" + nrErrors));
successConditionBrokenExit = true;
}
- return false;
+ return true;
}
// Fetch files in list one after one ...
currentFile = fileObjects[j];
@@ -829,6 +830,8 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
addFileToResultFilenames(destinationFile.toString(), result,
parentWorkflow);
}
+ updateSuccess();
+ retVal = true;
} else {
switch (ifExistsOption(ifMovedFileExists)) {
case "overwrite_file" -> {
@@ -887,9 +890,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
updateSuccess();
retVal = true;
}
- case FAIL ->
- // Update Errors
- updateErrors();
+ case FAIL -> retVal = false; // caller counts the error once
case CONST_DO_NOTHING -> retVal = true;
default ->
logError(
@@ -900,9 +901,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
}
}
}
- case FAIL ->
- // Update Errors
- updateErrors();
+ case FAIL -> retVal = false; // caller counts the error once
case CONST_DO_NOTHING -> retVal = true;
default ->
logError(
@@ -921,7 +920,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
destinationFilename.toString(),
e.getMessage() != null ? e.getMessage() :
e.getClass().getSimpleName()),
e);
- updateErrors();
+ // Leave retVal false so the caller counts the error once.
} finally {
if (destinationFile != null) {
try {
@@ -942,7 +941,9 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
IWorkflowEngine<WorkflowMeta> parentWorkflow,
Result result,
FileObject moveToFolderFolder) {
- boolean entryStatus = false;
+ // Default true: skipping the base folder / non-matching wildcard is not
an error. When we do
+ // call moveFile, propagate its result — do not force true afterwards
(#9175).
+ boolean entryStatus = true;
FileObject filename = null;
try {
@@ -963,7 +964,7 @@ public class ActionMoveFiles extends ActionBase implements
Cloneable, IAction {
CONST_ACTION_MOVE_FILES_ERROR_GETTING_FILENAME,
currentFile.getName().getBaseName(),
e.toString())));
- return entryStatus;
+ return false;
}
int lenCurrent = sourceShortFilename.length();
@@ -1040,9 +1041,9 @@ public class ActionMoveFiles extends ActionBase
implements Cloneable, IAction {
}
}
}
- entryStatus = true;
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "ActionMoveFiles.Log.Error",
e.toString()));
+ entryStatus = false;
} finally {
if (filename != null) {
try {
diff --git
a/plugins/actions/movefiles/src/test/java/org/apache/hop/workflow/actions/movefiles/ActionMoveFilesResultTest.java
b/plugins/actions/movefiles/src/test/java/org/apache/hop/workflow/actions/movefiles/ActionMoveFilesResultTest.java
new file mode 100644
index 0000000000..1b8831f326
--- /dev/null
+++
b/plugins/actions/movefiles/src/test/java/org/apache/hop/workflow/actions/movefiles/ActionMoveFilesResultTest.java
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.workflow.actions.movefiles;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.logging.HopLogStore;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Result / nrErrors behaviour for Move files (issue #9175): success-condition
boundary and
+ * single-counting when destination exists with Fail.
+ */
+class ActionMoveFilesResultTest {
+
+ @TempDir Path testFolder;
+
+ private ActionMoveFiles action;
+ private Path sourceFolder;
+ private Path destinationFolder;
+
+ @BeforeAll
+ static void setUpBeforeClass() {
+ HopLogStore.init();
+ }
+
+ @BeforeEach
+ void setUp() throws Exception {
+ action = MoveFilesActionHelper.defaultAction();
+ action.setDestinationIsAFile(false);
+ action.setCreateDestinationFolder(true);
+ sourceFolder = Files.createDirectories(testFolder.resolve("source"));
+ destinationFolder = Files.createDirectories(testFolder.resolve("dest"));
+ }
+
+ /** #9175 case 1a: last entry fails with limit 1 — lesser than means strict
<, so false. */
+ @Test
+ void errorsLesserThanIsFalseWhenLastEntryHitsTheLimit() throws Exception {
+ Path ok = write(sourceFolder.resolve("ok.txt"), "ok");
+ Path missing = sourceFolder.resolve("MISSING.txt");
+
+ action.setSuccessCondition(ActionMoveFiles.SUCCESS_IF_ERRORS_LESS);
+ action.setNrErrorsLessThan("1");
+ action.setFilesToMove(
+ List.of(
+ entry(ok.toString(), destinationFolder.toString()),
+ entry(missing.toString(), destinationFolder.toString())));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertFalse(result.isResult(), "1 error is not lesser than 1");
+ assertEquals(1, result.getNrErrors());
+ }
+
+ /**
+ * #9175 case 1b: first entry hits the limit — early exit must use the same
success condition as
+ * the normal end (also false), not leave the initial result=false for a
different reason while
+ * case 1a would have been true under the old <= check.
+ */
+ @Test
+ void errorsLesserThanIsFalseWhenFirstEntryHitsTheLimit() throws Exception {
+ Path ok = write(sourceFolder.resolve("ok.txt"), "ok");
+ Path missing = sourceFolder.resolve("MISSING.txt");
+
+ action.setSuccessCondition(ActionMoveFiles.SUCCESS_IF_ERRORS_LESS);
+ action.setNrErrorsLessThan("1");
+ action.setFilesToMove(
+ List.of(
+ entry(missing.toString(), destinationFolder.toString()),
+ entry(ok.toString(), destinationFolder.toString())));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertFalse(result.isResult(), "1 error is not lesser than 1");
+ assertEquals(1, result.getNrErrors());
+ }
+
+ /** With limit 2, a single missing source still succeeds under "errors
lesser than". */
+ @Test
+ void errorsLesserThanAllowsFewerErrorsThanTheLimit() throws Exception {
+ Path ok = write(sourceFolder.resolve("ok.txt"), "ok");
+ Path missing = sourceFolder.resolve("MISSING.txt");
+
+ action.setSuccessCondition(ActionMoveFiles.SUCCESS_IF_ERRORS_LESS);
+ action.setNrErrorsLessThan("2");
+ action.setFilesToMove(
+ List.of(
+ entry(ok.toString(), destinationFolder.toString()),
+ entry(missing.toString(), destinationFolder.toString())));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertTrue(result.isResult());
+ assertEquals(1, result.getNrErrors());
+ }
+
+ /**
+ * #9175 case 2: destination exists + Fail must count one error, not two
(inner FAIL + outer
+ * updateErrors on processFileFolder).
+ */
+ @Test
+ void failWhenDestinationExistsCountsOneError() throws Exception {
+ Path sourceFile = write(sourceFolder.resolve("a.txt"), "SOURCE");
+ Path destinationFile = write(destinationFolder.resolve("a.txt"),
"ALREADY-HERE");
+
+ action.setDestinationIsAFile(true);
+ action.setIfFileExists(ActionMoveFiles.FAIL);
+ action.setSuccessCondition(ActionMoveFiles.SUCCESS_IF_NO_ERRORS);
+ action.setFilesToMove(List.of(entry(sourceFile.toString(),
destinationFile.toString())));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertFalse(result.isResult());
+ assertEquals(1, result.getNrErrors(), "one existing destination must be
one error");
+ }
+
+ /**
+ * Folder source + Fail: moveOneFile must propagate moveFile's false (it
used to force true and
+ * hide the failure after updateErrors was moved to the caller).
+ */
+ @Test
+ void failWhenDestinationExistsInFolderSourceCountsOneError() throws
Exception {
+ write(sourceFolder.resolve("a.txt"), "SOURCE");
+ write(destinationFolder.resolve("a.txt"), "ALREADY-HERE");
+
+ action.setDestinationIsAFile(false);
+ action.setIfFileExists(ActionMoveFiles.FAIL);
+ action.setSuccessCondition(ActionMoveFiles.SUCCESS_IF_ERRORS_LESS);
+ action.setNrErrorsLessThan("1");
+ action.setFilesToMove(
+ List.of(entry(sourceFolder.toString(), destinationFolder.toString(),
".*\\.txt")));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertFalse(result.isResult());
+ assertEquals(1, result.getNrErrors(), "one existing destination must be
one error");
+ }
+
+ /**
+ * Folder source + Move to folder: when the destination file exists but the
move-to folder does
+ * not yet contain that name, the move succeeds and must set retVal /
updateSuccess (otherwise
+ * each moved file is counted as an error).
+ */
+ @Test
+ void moveToFolderSucceedsWhenDestinationExistsAndMoveToIsFree() throws
Exception {
+ write(sourceFolder.resolve("a.txt"), "SOURCE");
+ write(destinationFolder.resolve("a.txt"), "ALREADY-HERE");
+ Path moveToFolder = Files.createDirectories(testFolder.resolve("move-to"));
+
+ action.setDestinationIsAFile(false);
+ action.setIfFileExists(ActionMoveFiles.MOVE_FILE);
+ action.setDestinationFolder(moveToFolder.toString());
+ action.setIfMovedFileExists(ActionMoveFiles.FAIL);
+ action.setSuccessCondition(ActionMoveFiles.SUCCESS_IF_NO_ERRORS);
+ action.setFilesToMove(
+ List.of(entry(sourceFolder.toString(), destinationFolder.toString(),
".*\\.txt")));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertTrue(result.isResult(), "successful move-to-folder must not count as
an error");
+ assertEquals(0, result.getNrErrors());
+ assertFalse(Files.exists(sourceFolder.resolve("a.txt")));
+ assertTrue(Files.exists(moveToFolder.resolve("a.txt")));
+ }
+
+ /**
+ * Single-file source + Move to folder: same moveFile() branch as the
folder-source case; without
+ * updateSuccess / retVal=true a successful move was counted as an error
(already wrong on main).
+ */
+ @Test
+ void moveToFolderSucceedsForSingleFileWhenDestinationExistsAndMoveToIsFree()
throws Exception {
+ Path sourceFile = write(sourceFolder.resolve("a.txt"), "SOURCE");
+ Path destinationFile = write(destinationFolder.resolve("a.txt"),
"ALREADY-HERE");
+ Path moveToFolder =
Files.createDirectories(testFolder.resolve("move-to-file"));
+
+ action.setDestinationIsAFile(true);
+ action.setIfFileExists(ActionMoveFiles.MOVE_FILE);
+ action.setDestinationFolder(moveToFolder.toString());
+ action.setIfMovedFileExists(ActionMoveFiles.FAIL);
+ action.setSuccessCondition(ActionMoveFiles.SUCCESS_IF_NO_ERRORS);
+ action.setFilesToMove(List.of(entry(sourceFile.toString(),
destinationFile.toString())));
+
+ Result result = action.execute(new Result(), 0);
+
+ assertTrue(
+ result.isResult(), "successful single-file move-to-folder must not
count as an error");
+ assertEquals(0, result.getNrErrors());
+ assertFalse(Files.exists(sourceFile));
+ assertTrue(Files.exists(moveToFolder.resolve("a.txt")));
+ }
+
+ private static ActionMoveFiles.FileToMove entry(String source, String
destination) {
+ return entry(source, destination, null);
+ }
+
+ private static ActionMoveFiles.FileToMove entry(
+ String source, String destination, String wildcard) {
+ ActionMoveFiles.FileToMove fileToMove = new ActionMoveFiles.FileToMove();
+ fileToMove.setSourceFileFolder(source);
+ fileToMove.setDestinationFileFolder(destination);
+ fileToMove.setWildcard(wildcard);
+ return fileToMove;
+ }
+
+ private static Path write(Path path, String content) throws Exception {
+ Files.createDirectories(path.getParent());
+ return Files.writeString(path, content, StandardCharsets.UTF_8);
+ }
+}
diff --git
a/plugins/actions/movefiles/src/test/java/org/apache/hop/workflow/actions/movefiles/WorkflowActionMoveFilesLocalTest.java
b/plugins/actions/movefiles/src/test/java/org/apache/hop/workflow/actions/movefiles/WorkflowActionMoveFilesLocalTest.java
index 24f56a02c1..755a8c0de9 100644
---
a/plugins/actions/movefiles/src/test/java/org/apache/hop/workflow/actions/movefiles/WorkflowActionMoveFilesLocalTest.java
+++
b/plugins/actions/movefiles/src/test/java/org/apache/hop/workflow/actions/movefiles/WorkflowActionMoveFilesLocalTest.java
@@ -124,6 +124,7 @@ class WorkflowActionMoveFilesLocalTest {
Result result = action.execute(new Result(), 0);
assertFalse(result.isResult(), "Move should not succeed when destination
exists");
+ assertEquals(1, result.getNrErrors(), "Fail on existing destination must
count one error");
assertTrue(Files.exists(sourceFile), "Source file should still exist");
assertEquals(
originalContent,
diff --git
a/plugins/actions/zipfile/src/main/java/org/apache/hop/workflow/actions/zipfile/ActionZipFile.java
b/plugins/actions/zipfile/src/main/java/org/apache/hop/workflow/actions/zipfile/ActionZipFile.java
index 8d2d6e310b..19357db77d 100644
---
a/plugins/actions/zipfile/src/main/java/org/apache/hop/workflow/actions/zipfile/ActionZipFile.java
+++
b/plugins/actions/zipfile/src/main/java/org/apache/hop/workflow/actions/zipfile/ActionZipFile.java
@@ -556,8 +556,7 @@ public class ActionZipFile extends ActionBase implements
Cloneable, IAction {
toString());
result.getResultFiles().put(resultFile.getFile().toString(),
resultFile);
}
-
- successResult = true;
+ // Keep successResult from zip / after-zip delete-or-move; do not
force true.
}
}
} catch (Exception e) {
@@ -916,6 +915,7 @@ public class ActionZipFile extends ActionBase implements
Cloneable, IAction {
}
if (fromPrevious && rows != null) {
try {
+ boolean anyZipped = false;
for (int iteration = 0;
iteration < rows.size() && !parentWorkflow.isStopped();
iteration++) {
@@ -947,6 +947,7 @@ public class ActionZipFile extends ActionBase implements
Cloneable, IAction {
createParentFolder)) {
return errorResult(result);
}
+ anyZipped = true;
} else {
logError("destination zip filename is empty! Ignoring row...");
}
@@ -954,6 +955,12 @@ public class ActionZipFile extends ActionBase implements
Cloneable, IAction {
logError("Target directory is empty! Ignoring row...");
}
}
+ if (anyZipped) {
+ result.setResult(true);
+ } else {
+ // No row produced a zip (empty list or only empty fields) — do not
inherit previous.
+ return errorResult(result);
+ }
} catch (Exception e) {
logError("Error during process!", e);
result.setResult(false);
@@ -991,6 +998,7 @@ public class ActionZipFile extends ActionBase implements
Cloneable, IAction {
}
} else {
logError("Source folder/file is empty! Ignoring row...");
+ return errorResult(result);
}
}
diff --git
a/plugins/actions/zipfile/src/test/java/org/apache/hop/workflow/actions/zipfile/ActionZipFileResultTest.java
b/plugins/actions/zipfile/src/test/java/org/apache/hop/workflow/actions/zipfile/ActionZipFileResultTest.java
new file mode 100644
index 0000000000..19d0b96ccc
--- /dev/null
+++
b/plugins/actions/zipfile/src/test/java/org/apache/hop/workflow/actions/zipfile/ActionZipFileResultTest.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.workflow.actions.zipfile;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.UUID;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.RowMetaAndData;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.LogLevel;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.core.vfs.HopVfs;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+
+/** Result behaviour for Zip file (issue #9175 cases 5 and 6). */
+class ActionZipFileResultTest {
+
+ private String ramFolder;
+
+ @BeforeAll
+ static void init() throws Exception {
+ HopClientEnvironment.init();
+ HopLogStore.init();
+ }
+
+ @BeforeEach
+ void setUp() {
+ ramFolder = "ram:///" + UUID.randomUUID();
+ }
+
+ @AfterEach
+ void tearDown() throws Exception {
+ HopVfs.getFileObject(ramFolder).deleteAll();
+ }
+
+ /** #9175 case 5b: empty source must set result false, not inherit the
previous true. */
+ @Test
+ void emptySourceDirectoryFailsTheAction() {
+ ActionZipFile action = newAction();
+ action.setFromPrevious(false);
+ action.setSourceDirectory("");
+ action.setZipFilename(ramFolder + "/out/empty.zip");
+
+ Result previous = new Result();
+ previous.setResult(true);
+
+ Result result = action.execute(previous, 0);
+
+ assertFalse(result.isResult(), "empty source must not keep the previous
true result");
+ assertEquals(1, result.getNrErrors());
+ }
+
+ /**
+ * Get arguments from previous with no result rows must set result false
(not inherit the previous
+ * true).
+ */
+ @Test
+ void fromPreviousWithNoRowsFailsTheAction() {
+ ActionZipFile action = newAction();
+ action.setFromPrevious(true);
+
+ Result previous = new Result();
+ previous.setResult(true);
+ previous.setRows(List.of());
+
+ Result result = action.execute(previous, 0);
+
+ assertFalse(result.isResult(), "no previous rows must not keep the
previous true result");
+ assertEquals(1, result.getNrErrors());
+ }
+
+ /**
+ * Get arguments from previous: rows with an empty source or zip file name
are skipped. When every
+ * row is skipped, the action is false (it does not inherit the previous
true result).
+ */
+ @Test
+ void fromPreviousWithOnlySkippedRowsFailsTheAction() {
+ ActionZipFile action = newAction();
+ action.setFromPrevious(true);
+
+ Result previous = new Result();
+ previous.setResult(true);
+ previous.setRows(
+ List.of(
+ row("", ramFolder + "/out/skipped.zip"),
+ row(ramFolder + "/source/a.txt", ""),
+ row("", "")));
+
+ Result result = action.execute(previous, 0);
+
+ assertFalse(
+ result.isResult(), "all-skipped previous rows must not keep the
previous true result");
+ assertEquals(1, result.getNrErrors());
+ }
+
+ /**
+ * #9175 case 5: Get arguments from previous must set result true on success
so a prior false hop
+ * is not inherited.
+ */
+ @Test
+ void fromPreviousSuccessSetsResultTrue() throws Exception {
+ writeFile(ramFolder + "/source/a.txt", "zip-me");
+ String zip = ramFolder + "/out/from-previous.zip";
+
+ ActionZipFile action = newAction();
+ action.setFromPrevious(true);
+ action.setCreateParentFolder(true);
+
+ Result previous = new Result();
+ previous.setResult(false);
+ previous.setNrErrors(0);
+ previous.setRows(List.of(row(ramFolder + "/source/a.txt", zip)));
+
+ Result result = action.execute(previous, 0);
+
+ assertTrue(result.isResult(), "successful fromPrevious zip must set result
true");
+ assertEquals(0, result.getNrErrors());
+ assertTrue(HopVfs.getFileObject(zip).exists(), "zip file should exist");
+ }
+
+ /**
+ * #9175 case 6: a failed after-zip Move must leave the action false
(successResult must not be
+ * forced back to true).
+ */
+ @Test
+ void failedMoveAfterZipFailsTheAction() throws Exception {
+ writeFile(ramFolder + "/source/a.txt", "zip-then-move");
+ String zip = ramFolder + "/out/archive.zip";
+ String moveTo = ramFolder + "/move-to";
+ HopVfs.getFileObject(moveTo).createFolder();
+
+ ActionZipFile action = newAction();
+ action.setFromPrevious(false);
+ action.setSourceDirectory(ramFolder + "/source/a.txt");
+ action.setZipFilename(zip);
+ action.setCreateParentFolder(true);
+ action.setAfterZip(2); // Move files
+ action.setMoveToDirectory(moveTo);
+ action.setCreateMoveToDirectory(false);
+ action.setIfZipFileExists(2);
+
+ Result result;
+ try (MockedStatic<HopVfs> vfs = Mockito.mockStatic(HopVfs.class,
Mockito.CALLS_REAL_METHODS)) {
+ // Fail only the after-zip source move, not the temp-zip rename during
creation.
+ vfs.when(() -> HopVfs.moveFile(any(), any()))
+ .thenAnswer(
+ invocation -> {
+ FileObject destination = invocation.getArgument(1,
FileObject.class);
+ if (destination.getName().getPath().contains("move-to")) {
+ throw new FileSystemException("move failed");
+ }
+ return invocation.callRealMethod();
+ });
+ result = action.execute(new Result(), 0);
+ }
+
+ assertFalse(result.isResult(), "failed post-zip move must fail the
action");
+ assertTrue(HopVfs.getFileObject(zip).exists(), "zip should still have been
created");
+ }
+
+ private static ActionZipFile newAction() {
+ ActionZipFile action = new ActionZipFile();
+ action.setParentWorkflow(new LocalWorkflowEngine(new WorkflowMeta()));
+ action.setParentWorkflowMeta(mock(WorkflowMeta.class));
+ action.setLogLevel(LogLevel.NOTHING);
+ action.setCompressionRate(1);
+ action.setAfterZip(0);
+ action.setIfZipFileExists(2);
+ action.setAddFileToResult(false);
+ return action;
+ }
+
+ private static RowMetaAndData row(String source, String zip) {
+ RowMeta meta = new RowMeta();
+ meta.addValueMeta(new ValueMetaString("source"));
+ meta.addValueMeta(new ValueMetaString("wildcard"));
+ meta.addValueMeta(new ValueMetaString("wildcard_exclude"));
+ meta.addValueMeta(new ValueMetaString("zipfile"));
+ return new RowMetaAndData(meta, source, "", "", zip);
+ }
+
+ private static void writeFile(String filename, String content) throws
Exception {
+ FileObject file = HopVfs.getFileObject(filename);
+ file.getParent().createFolder();
+ try (OutputStream out = HopVfs.getOutputStream(file, false)) {
+ out.write(content.getBytes(StandardCharsets.UTF_8));
+ }
+ }
+}