Copilot commented on code in PR #3934:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3934#discussion_r2104415834


##########
addons/common/persistence/filesystem/src/main/java/org/kie/kogito/persistence/filesystem/FileSystemProcessInstances.java:
##########
@@ -93,27 +95,32 @@ public Stream<ProcessInstance> 
stream(ProcessInstanceReadMode mode) {
 
     @Override
     public boolean exists(String id) {
-        return Files.exists(Paths.get(storage.toString(), id));
+        Path processInstanceStorage = PathUtils.getSecuredPath(storage, id);
+        return Files.exists(processInstanceStorage) && 
Files.isRegularFile(processInstanceStorage);
     }
 
     @SuppressWarnings("unchecked")
     @Override
+
     public void create(String id, ProcessInstance instance) {
         if (isActive(instance)) {
-            Path processInstanceStorage = Paths.get(storage.toString(), id);
-            if (Files.exists(processInstanceStorage)) {
+            Path processInstanceStorage = PathUtils.getSecuredPath(storage, 
id);
+            if (Files.notExists(processInstanceStorage) || 
!Files.isRegularFile(processInstanceStorage)) {
+                storeProcessInstance(processInstanceStorage, instance);
+            } else {
                 throw new ProcessInstanceDuplicatedException(id);
             }
-            storeProcessInstance(processInstanceStorage, instance);
         }
     }
 
     @SuppressWarnings("unchecked")
     @Override
     public void update(String id, ProcessInstance instance) {
         if (isActive(instance)) {
-            Path processInstanceStorage = Paths.get(storage.toString(), id);
-            if (Files.exists(processInstanceStorage)) {
+            Path processInstanceStorage = PathUtils.getSecuredPath(storage, 
id);
+            if (Files.notExists(processInstanceStorage) && 
!Files.isRegularFile(processInstanceStorage)) {

Review Comment:
   The conditional check in the update method should use a logical OR instead 
of AND to correctly throw an exception when the file either does not exist or 
is not a regular file.
   ```suggestion
               if (Files.notExists(processInstanceStorage) || 
!Files.isRegularFile(processInstanceStorage)) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to