wenjin272 commented on code in PR #655:
URL: https://github.com/apache/flink-agents/pull/655#discussion_r3240589796


##########
runtime/src/main/java/org/apache/flink/agents/runtime/skill/repository/SkillMaterializer.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.flink.agents.runtime.skill.repository;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * Internal helpers for materializing skill sources (zip files, URL downloads, 
classpath JAR
+ * entries) into a local temp directory. Cleanup is registered as a JVM 
shutdown hook so the temp
+ * directories are removed when the process exits.
+ */
+public final class SkillMaterializer {
+
+    private static final String TEMP_DIR_PREFIX = "flink-agents-skills-";
+
+    private SkillMaterializer() {}
+
+    /**
+     * Register a JVM shutdown hook that removes {@code path} recursively. 
Failures during deletion
+     * are silently ignored (best-effort cleanup).
+     */
+    public static void registerCleanup(Path path) {
+        Thread hook =
+                new Thread(() -> deleteRecursively(path), "skill-cleanup-" + 
path.getFileName());
+        Runtime.getRuntime().addShutdownHook(hook);
+    }
+
+    /**
+     * Extract a zip into a fresh temp directory and return that directory. 
Validates every entry
+     * against zip-slip (paths must resolve inside the extraction directory). 
Registers a JVM
+     * shutdown hook to remove the extraction directory at process exit.
+     *
+     * @throws IOException if any zip entry resolves outside the extraction 
directory.
+     */
+    public static Path extractZipSafely(Path zipPath) throws IOException {

Review Comment:
   Similar to the question above, I believe we can iterate on and implement 
this improvement in future versions.



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