davsclaus commented on code in PR #27926:
URL: https://github.com/apache/camel/pull/27926#discussion_r4289672732


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/Dirty.java:
##########
@@ -76,4 +75,28 @@ public Integer doCall() throws Exception {
         return 0;
     }
 
+    /**
+     * The pid a file in the Camel directory belongs to, such as 123 for 
{@code 123-status.json}, {@code 123} and the
+     * infra service file {@code infra-kafka-123.json}, or <tt>null</tt> for a 
file that belongs to no process.
+     */
+    static Long pidOf(String fileName) {
+        if (fileName.startsWith("infra-") && fileName.lastIndexOf('-') > 5) {
+            // infra-<service>-<pid>.json and .log
+            fileName = fileName.substring(fileName.lastIndexOf('-') + 1);
+        }
+        int end = 0;
+        while (end < fileName.length() && 
Character.isDigit(fileName.charAt(end))) {
+            end++;
+        }
+        boolean separated = end == fileName.length() || fileName.charAt(end) 
== '-' || fileName.charAt(end) == '.';
+        if (end == 0 || !separated) {
+            return null;
+        }
+        try {
+            return Long.parseLong(fileName.substring(0, end));
+        } catch (NumberFormatException e) {
+            return null;
+        }

Review Comment:
   Yes, the catch is for a digit string longer than a `long` (e.g. a stray 
`99999999999999999999999.json` in `~/.camel`): such a file belongs to no 
process, so `null` is the right answer and the file is left alone. Leaving the 
code as is, since the javadoc already says `null` is for a file that belongs to 
no process.
   
   _Claude Code on behalf of davsclaus_



-- 
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]

Reply via email to