@xiangyang9999/folib-server-sync-a8be7ecd6f05 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +57 -2
  2. package/bin/folib-commit-sync.js +70 -0
  3. package/package.json +22 -4
  4. package/payload/INSTRUCTIONS.docx +0 -0
  5. package/payload/changes.patch +1538 -0
  6. package/payload/manifest.json +367 -0
  7. package/payload/manifest.sha256 +41 -0
  8. package/payload/source-files.zip +0 -0
  9. package/source/SECURITY_DEPENDENCY_UPGRADE.md +97 -0
  10. package/source/folib-client/pom.xml +160 -0
  11. package/source/folib-commons/folib-commons-core/pom.xml +297 -0
  12. package/source/folib-commons/folib-commons-core/src/main/java/com/veadan/folib/util/ArchiveExtractionPaths.java +86 -0
  13. package/source/folib-commons/folib-commons-core/src/main/java/com/veadan/folib/util/CompressUtils.java +148 -0
  14. package/source/folib-commons/folib-commons-core/src/test/java/com/veadan/folib/util/ArchiveExtractionPathsTest.java +77 -0
  15. package/source/folib-commons/folib-commons-core/src/test/java/com/veadan/folib/util/CompressUtilsTest.java +286 -0
  16. package/source/folib-commons/folib-commons-io/pom.xml +184 -0
  17. package/source/folib-data-service/pom.xml +259 -0
  18. package/source/folib-data-service/src/test/java/com/veadan/folib/config/hazelcast/HazelcastClusterCompatibilityTest.java +124 -0
  19. package/source/folib-rest-client/pom.xml +166 -0
  20. package/source/folib-security/folib-authentication-registry/pom.xml +117 -0
  21. package/source/folib-security/folib-security-api/pom.xml +416 -0
  22. package/source/folib-storage/folib-storage-layout-providers/folib-storage-debian-layout-provider/src/main/java/com/veadan/folib/indexer/DebianGroupInterceptor.java +251 -0
  23. package/source/folib-storage/folib-storage-layout-providers/folib-storage-debian-layout-provider/src/main/java/com/veadan/folib/indexer/DebianPackagesMetadataIndexer.java +72 -0
  24. package/source/folib-storage/folib-storage-layout-providers/folib-storage-docker-layout-provider/pom.xml +236 -0
  25. package/source/folib-storage/folib-storage-layout-providers/folib-storage-gitlfs-layout-provider/pom.xml +187 -0
  26. package/source/folib-storage/folib-storage-layout-providers/folib-storage-go-layout-provider/pom.xml +180 -0
  27. package/source/folib-storage/folib-storage-layout-providers/folib-storage-helm-layout-provider/pom.xml +125 -0
  28. package/source/folib-storage/folib-storage-layout-providers/folib-storage-huggingface-layout-provider/pom.xml +193 -0
  29. package/source/folib-storage/folib-storage-layout-providers/folib-storage-maven-layout/folib-maven-metadata-api/pom.xml +101 -0
  30. package/source/folib-storage/folib-storage-layout-providers/folib-storage-maven-layout/folib-storage-maven-layout-provider/pom.xml +179 -0
  31. package/source/folib-storage/folib-storage-layout-providers/folib-storage-npm-layout-provider/pom.xml +162 -0
  32. package/source/folib-storage/folib-storage-layout-providers/folib-storage-nuget-layout-provider/pom.xml +155 -0
  33. package/source/folib-storage/folib-storage-layout-providers/folib-storage-p2-layout-provider/pom.xml +116 -0
  34. package/source/folib-storage/folib-storage-layout-providers/folib-storage-php-layout-provider/pom.xml +170 -0
  35. package/source/folib-storage/folib-storage-layout-providers/folib-storage-pypi-layout-provider/pom.xml +278 -0
  36. package/source/folib-storage/folib-storage-layout-providers/folib-storage-raw-layout-provider/pom.xml +183 -0
  37. package/source/folib-web-core/pom.xml +1089 -0
  38. package/source/folib-web-core/src/main/java/com/veadan/folib/app/FolibSpringBootApplication.java +67 -0
  39. package/source/folib-web-core/src/main/java/com/veadan/folib/config/LegacySpringDataWebConfig.java +41 -0
  40. package/source/folib-web-core/src/main/java/com/veadan/folib/config/WebConfig.java +377 -0
  41. package/source/folib-web-core/src/main/java/com/veadan/folib/model/response/OhpmPublishRes.java +16 -0
  42. package/source/folib-web-core/src/main/java/com/veadan/folib/promotion/DockerParsePacketsUtil.java +202 -0
  43. package/source/folib-web-core/src/test/java/com/veadan/folib/config/LegacySpringDataWebConfigTest.java +75 -0
  44. package/source/folib-web-core/src/test/java/com/veadan/folib/config/WebConfigResourceHandlersTest.java +31 -0
  45. package/source/folib-web-core/src/test/java/com/veadan/folib/promotion/DockerArchiveExtractionTest.java +112 -0
  46. package/source/folib-web-core/src/test/java/com/veadan/folib/utils/DependencyCompatibilityTest.java +62 -0
@@ -0,0 +1,160 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+
6
+ <modelVersion>4.0.0</modelVersion>
7
+
8
+ <groupId>com.veadan.folib</groupId>
9
+ <artifactId>folib-client</artifactId>
10
+ <version>3.0.0-RELEASE</version>
11
+ <packaging>jar</packaging>
12
+ <name>Folib: Client</name>
13
+ <inceptionYear>2019</inceptionYear>
14
+
15
+ <scm>
16
+ <url>http://git.folib.com/folib/folib-server</url>
17
+ <connection>scm:git:git://git.folib.com/folib/folib-server.git</connection>
18
+ <developerConnection>scm:git:git://git.folib.com/folib/folib-server.git</developerConnection>
19
+ </scm>
20
+
21
+ <properties>
22
+ <dir.folib.home>${project.build.directory}/folib</dir.folib.home>
23
+ <dir.folib.vault>${project.build.directory}/folib-vault</dir.folib.vault>
24
+ </properties>
25
+
26
+ <build>
27
+ <plugins>
28
+ <plugin>
29
+ <groupId>org.apache.maven.plugins</groupId>
30
+ <artifactId>maven-compiler-plugin</artifactId>
31
+ <version>3.5</version>
32
+ <configuration>
33
+ <source>1.8</source>
34
+ <target>1.8</target>
35
+ </configuration>
36
+ </plugin>
37
+ <plugin>
38
+ <groupId>org.apache.maven.plugins</groupId>
39
+ <artifactId>maven-dependency-plugin</artifactId>
40
+ <version>3.1.1</version>
41
+ </plugin>
42
+ </plugins>
43
+ </build>
44
+
45
+ <dependencies>
46
+ <!-- <dependency>-->
47
+ <!-- <groupId>javax.ws.rs</groupId>-->
48
+ <!-- <artifactId>javax.ws.rs-api</artifactId>-->
49
+ <!-- <version>2.1.1</version>-->
50
+ <!-- </dependency>-->
51
+ <dependency>
52
+ <groupId>com.google.code.findbugs</groupId>
53
+ <artifactId>annotations</artifactId>
54
+ <version>3.0.1</version>
55
+ </dependency>
56
+ <dependency>
57
+ <groupId>org.springframework.security</groupId>
58
+ <artifactId>spring-security-core</artifactId>
59
+ <version>6.5.11</version>
60
+ </dependency>
61
+ <dependency>
62
+ <groupId>org.glassfish.jersey.core</groupId>
63
+ <artifactId>jersey-common</artifactId>
64
+ <version>2.46</version>
65
+ </dependency>
66
+ <dependency>
67
+ <groupId>org.glassfish.jersey.containers</groupId>
68
+ <artifactId>jersey-container-servlet-core</artifactId>
69
+ <version>2.46</version>
70
+ </dependency>
71
+ <dependency>
72
+ <groupId>org.glassfish.jersey.core</groupId>
73
+ <artifactId>jersey-client</artifactId>
74
+ <version>2.46</version>
75
+ </dependency>
76
+ <dependency>
77
+ <groupId>org.glassfish.jersey.connectors</groupId>
78
+ <artifactId>jersey-apache-connector</artifactId>
79
+ <version>2.46</version>
80
+ </dependency>
81
+ <dependency>
82
+ <groupId>org.glassfish.jersey.inject</groupId>
83
+ <artifactId>jersey-hk2</artifactId>
84
+ <version>2.46</version>
85
+ </dependency>
86
+ <dependency>
87
+ <groupId>org.apache.httpcomponents</groupId>
88
+ <artifactId>httpclient</artifactId>
89
+ <version>4.5</version>
90
+ </dependency>
91
+ <dependency>
92
+ <groupId>org.apache.httpcomponents</groupId>
93
+ <artifactId>fluent-hc</artifactId>
94
+ <version>4.5</version>
95
+ </dependency>
96
+
97
+ <!-- Logging -->
98
+ <dependency>
99
+ <groupId>org.slf4j</groupId>
100
+ <artifactId>jcl-over-slf4j</artifactId>
101
+ <version>1.7.25</version>
102
+ </dependency>
103
+ <dependency>
104
+ <groupId>org.slf4j</groupId>
105
+ <artifactId>jul-to-slf4j</artifactId>
106
+ <version>1.7.25</version>
107
+ </dependency>
108
+ <dependency>
109
+ <groupId>ch.qos.logback</groupId>
110
+ <artifactId>logback-classic</artifactId>
111
+ <version>1.2.3</version>
112
+ </dependency>
113
+
114
+ <dependency>
115
+ <groupId>org.junit.jupiter</groupId>
116
+ <artifactId>junit-jupiter</artifactId>
117
+ <version>5.7.0</version>
118
+ </dependency>
119
+
120
+ <dependency>
121
+ <groupId>org.mockito</groupId>
122
+ <artifactId>mockito-core</artifactId>
123
+ <version>3.6.28</version>
124
+ </dependency>
125
+ <dependency>
126
+ <groupId>org.springframework</groupId>
127
+ <artifactId>spring-core</artifactId>
128
+ <version>6.2.19</version>
129
+ </dependency>
130
+ <dependency>
131
+ <groupId>org.springframework</groupId>
132
+ <artifactId>spring-web</artifactId>
133
+ <version>6.2.19</version>
134
+ </dependency>
135
+ <dependency>
136
+ <groupId>org.springframework</groupId>
137
+ <artifactId>spring-webmvc</artifactId>
138
+ <version>6.2.19</version>
139
+ </dependency>
140
+ <dependency>
141
+ <artifactId>jakarta.xml.bind-api</artifactId>
142
+ <groupId>jakarta.xml.bind</groupId>
143
+ <version>4.0.1</version>
144
+ </dependency>
145
+ </dependencies>
146
+ <repositories>
147
+ <repository>
148
+ <id>folib-local-maven</id>
149
+ <url>https://public.bocloud.com.cn/storages/folib/folib-maven-local</url>
150
+ </repository>
151
+ </repositories>
152
+
153
+ <distributionManagement>
154
+ <repository>
155
+ <id>folib-local-maven</id>
156
+ <url>https://public.bocloud.com.cn/storages/folib/folib-maven-local</url>
157
+ </repository>
158
+ </distributionManagement>
159
+
160
+ </project>
@@ -0,0 +1,297 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+
6
+ <modelVersion>4.0.0</modelVersion>
7
+
8
+ <parent>
9
+ <groupId>com.veadan.folib</groupId>
10
+ <artifactId>folib-parent</artifactId>
11
+ <version>3.0-SNAPSHOT</version>
12
+ <relativePath/>
13
+ </parent>
14
+
15
+ <artifactId>folib-commons-core</artifactId>
16
+ <packaging>jar</packaging>
17
+ <name>Folib: Commons Core</name>
18
+ <inceptionYear>2019</inceptionYear>
19
+
20
+ <scm>
21
+ <url>http://git.folib.com/folib/folib-server</url>
22
+ <connection>scm:git:git://git.folib.com/folib/folib-server.git</connection>
23
+ <developerConnection>scm:git:git://git.folib.com/folib/folib-server.git</developerConnection>
24
+ </scm>
25
+
26
+ <build>
27
+ <plugins>
28
+ <plugin>
29
+ <groupId>org.apache.maven.plugins</groupId>
30
+ <artifactId>maven-compiler-plugin</artifactId>
31
+ <configuration>
32
+ <source>17</source>
33
+ <target>17</target>
34
+ </configuration>
35
+ </plugin>
36
+ <plugin>
37
+ <groupId>org.apache.maven.plugins</groupId>
38
+ <artifactId>maven-source-plugin</artifactId>
39
+ </plugin>
40
+
41
+ <plugin>
42
+ <groupId>org.codehaus.mojo</groupId>
43
+ <artifactId>buildnumber-maven-plugin</artifactId>
44
+ <executions>
45
+ <execution>
46
+ <phase>validate</phase>
47
+ <goals>
48
+ <goal>create</goal>
49
+ </goals>
50
+ </execution>
51
+ </executions>
52
+ </plugin>
53
+
54
+ <plugin>
55
+ <groupId>org.apache.maven.plugins</groupId>
56
+ <artifactId>maven-jar-plugin</artifactId>
57
+ </plugin>
58
+
59
+ <plugin>
60
+ <groupId>org.apache.maven.plugins</groupId>
61
+ <artifactId>maven-surefire-plugin</artifactId>
62
+
63
+ <configuration>
64
+ <systemPropertyVariables>
65
+ <folib.home>${project.build.directory}/folib</folib.home>
66
+ </systemPropertyVariables>
67
+ </configuration>
68
+ </plugin>
69
+ <plugin>
70
+ <groupId>org.apache.maven.plugins</groupId>
71
+ <artifactId>maven-failsafe-plugin</artifactId>
72
+ </plugin>
73
+ <plugin>
74
+ <groupId>org.apache.maven.plugins</groupId>
75
+ <artifactId>maven-resources-plugin</artifactId>
76
+ <configuration>
77
+ <useDefaultDelimiters>false</useDefaultDelimiters>
78
+ <delimiters>
79
+ <delimiter>@{*}</delimiter>
80
+ </delimiters>
81
+ </configuration>
82
+ </plugin>
83
+ </plugins>
84
+ <resources>
85
+ <resource>
86
+ <directory>src/main/resources</directory>
87
+ <filtering>true</filtering>
88
+ </resource>
89
+ </resources>
90
+ </build>
91
+
92
+ <dependencies>
93
+ <dependency>
94
+ <groupId>org.mapstruct</groupId>
95
+ <artifactId>mapstruct</artifactId>
96
+ <version>1.5.5.Final</version>
97
+ </dependency>
98
+
99
+ <dependency>
100
+ <groupId>org.mapstruct</groupId>
101
+ <artifactId>mapstruct-processor</artifactId>
102
+ <version>1.5.5.Final</version>
103
+ </dependency>
104
+ <dependency>
105
+ <groupId>${project.groupId}</groupId>
106
+ <artifactId>folib-commons-resources</artifactId>
107
+ <version>3.0-SNAPSHOT</version>
108
+ </dependency>
109
+
110
+ <dependency>
111
+ <groupId>com.veadan.folib.commons</groupId>
112
+ <artifactId>folib-commons-http</artifactId>
113
+ <version>${project.version}</version>
114
+ </dependency>
115
+
116
+ <dependency>
117
+ <groupId>com.veadan.folib.commons</groupId>
118
+ <artifactId>folib-commons-io</artifactId>
119
+ <version>${project.version}</version>
120
+ </dependency>
121
+
122
+ <dependency>
123
+ <groupId>commons-io</groupId>
124
+ <artifactId>commons-io</artifactId>
125
+ </dependency>
126
+ <dependency>
127
+ <groupId>org.apache.commons</groupId>
128
+ <artifactId>commons-lang3</artifactId>
129
+ </dependency>
130
+ <dependency>
131
+ <groupId>org.apache.commons</groupId>
132
+ <artifactId>commons-collections4</artifactId>
133
+ </dependency>
134
+
135
+ <!-- <dependency>-->
136
+ <!-- <groupId>javax.inject</groupId>-->
137
+ <!-- <artifactId>javax.inject</artifactId>-->
138
+ <!-- </dependency>-->
139
+ <dependency>
140
+ <groupId>jakarta.inject</groupId>
141
+ <artifactId>jakarta.inject-api</artifactId>
142
+ <version>2.0.1</version>
143
+ </dependency>
144
+
145
+ <dependency>
146
+ <groupId>javax.ws.rs</groupId>
147
+ <artifactId>javax.ws.rs-api</artifactId>
148
+ <version>2.1.1</version>
149
+ </dependency>
150
+
151
+ <dependency>
152
+ <groupId>com.lambdista</groupId>
153
+ <artifactId>try</artifactId>
154
+ <version>0.3.1</version>
155
+ </dependency>
156
+
157
+ <dependency>
158
+ <groupId>com.google.code.findbugs</groupId>
159
+ <artifactId>jsr305</artifactId>
160
+ </dependency>
161
+ <dependency>
162
+ <groupId>com.google.code.findbugs</groupId>
163
+ <artifactId>annotations</artifactId>
164
+ </dependency>
165
+
166
+ <dependency>
167
+ <groupId>com.google.guava</groupId>
168
+ <artifactId>guava</artifactId>
169
+ </dependency>
170
+ <dependency>
171
+ <groupId>org.reflections</groupId>
172
+ <artifactId>reflections</artifactId>
173
+ </dependency>
174
+
175
+ <!-- Logging -->
176
+ <dependency>
177
+ <groupId>org.slf4j</groupId>
178
+ <artifactId>jcl-over-slf4j</artifactId>
179
+ </dependency>
180
+ <dependency>
181
+ <groupId>org.slf4j</groupId>
182
+ <artifactId>jul-to-slf4j</artifactId>
183
+ </dependency>
184
+ <dependency>
185
+ <groupId>ch.qos.logback</groupId>
186
+ <artifactId>logback-core</artifactId>
187
+ </dependency>
188
+ <dependency>
189
+ <groupId>ch.qos.logback</groupId>
190
+ <artifactId>logback-classic</artifactId>
191
+ </dependency>
192
+
193
+ <dependency>
194
+ <groupId>org.springframework</groupId>
195
+ <artifactId>spring-context</artifactId>
196
+ </dependency>
197
+
198
+ <dependency>
199
+ <groupId>com.fasterxml.jackson.core</groupId>
200
+ <artifactId>jackson-core</artifactId>
201
+ </dependency>
202
+ <dependency>
203
+ <groupId>com.fasterxml.jackson.core</groupId>
204
+ <artifactId>jackson-databind</artifactId>
205
+ </dependency>
206
+ <dependency>
207
+ <groupId>com.fasterxml.jackson.module</groupId>
208
+ <artifactId>jackson-module-jaxb-annotations</artifactId>
209
+ </dependency>
210
+ <dependency>
211
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
212
+ <artifactId>jackson-dataformat-yaml</artifactId>
213
+ </dependency>
214
+ <dependency>
215
+ <groupId>org.junit.jupiter</groupId>
216
+ <artifactId>junit-jupiter</artifactId>
217
+ </dependency>
218
+ <dependency>
219
+ <groupId>org.objenesis</groupId>
220
+ <artifactId>objenesis</artifactId>
221
+ </dependency>
222
+
223
+ <dependency>
224
+ <groupId>org.projectlombok</groupId>
225
+ <artifactId>lombok</artifactId>
226
+ </dependency>
227
+ <dependency>
228
+ <groupId>javax.persistence</groupId>
229
+ <artifactId>javax.persistence-api</artifactId>
230
+ </dependency>
231
+ <dependency>
232
+ <groupId>io.swagger</groupId>
233
+ <artifactId>swagger-annotations</artifactId>
234
+ <version>1.6.2</version>
235
+ <scope>compile</scope>
236
+ </dependency>
237
+ <dependency>
238
+ <groupId>com.baomidou</groupId>
239
+ <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
240
+ <version>3.5.9</version>
241
+ </dependency>
242
+ <dependency>
243
+ <groupId>org.springframework.boot</groupId>
244
+ <artifactId>spring-boot</artifactId>
245
+ </dependency>
246
+ <dependency>
247
+ <groupId>com.veadan.folib</groupId>
248
+ <artifactId>folib-s3fs-nio</artifactId>
249
+ <version>2.0-SNAPSHOT</version>
250
+ <scope>compile</scope>
251
+ </dependency>
252
+ <dependency>
253
+ <groupId>org.bouncycastle</groupId>
254
+ <artifactId>bcprov-jdk15on</artifactId>
255
+ <version>1.70</version>
256
+ </dependency>
257
+ <dependency>
258
+ <groupId>cn.hutool</groupId>
259
+ <artifactId>hutool-all</artifactId>
260
+ <version>5.8.26</version>
261
+ </dependency>
262
+ <!-- <dependency>-->
263
+ <!-- <groupId>org.redisson</groupId>-->
264
+ <!-- <artifactId>redisson</artifactId>-->
265
+ <!-- <version>3.22.0</version>-->
266
+ <!-- </dependency>-->
267
+ <dependency>
268
+ <groupId>org.apache.commons</groupId>
269
+ <artifactId>commons-compress</artifactId>
270
+ </dependency>
271
+ <dependency>
272
+ <groupId>com.hazelcast</groupId>
273
+ <artifactId>hazelcast-spring</artifactId>
274
+ </dependency>
275
+ <dependency>
276
+ <groupId>com.alibaba</groupId>
277
+ <artifactId>fastjson</artifactId>
278
+ <version>1.2.83_noneautotype</version>
279
+ </dependency>
280
+ <dependency>
281
+ <groupId>com.github.zafarkhaja</groupId>
282
+ <artifactId>java-semver</artifactId>
283
+ <version>0.9.0</version>
284
+ </dependency>
285
+ <dependency>
286
+ <groupId>org.jsoup</groupId>
287
+ <artifactId>jsoup</artifactId>
288
+ </dependency>
289
+ <!-- <dependency>-->
290
+ <!-- <groupId>com.googlecode.juniversalchardet</groupId>-->
291
+ <!-- <artifactId>juniversalchardet</artifactId>-->
292
+ <!-- <version>1.0.3</version>-->
293
+ <!-- <scope>compile</scope>-->
294
+ <!-- </dependency>-->
295
+ </dependencies>
296
+
297
+ </project>
@@ -0,0 +1,86 @@
1
+ package com.veadan.folib.util;
2
+
3
+ import java.io.IOException;
4
+ import java.io.OutputStream;
5
+ import java.nio.file.FileAlreadyExistsException;
6
+ import java.nio.file.Files;
7
+ import java.nio.file.InvalidPathException;
8
+ import java.nio.file.LinkOption;
9
+ import java.nio.file.Path;
10
+ import java.nio.file.StandardOpenOption;
11
+
12
+ /**
13
+ * Resolves untrusted archive names inside a caller-selected extraction directory.
14
+ * The directory must not be concurrently writable by untrusted local processes.
15
+ */
16
+ public final class ArchiveExtractionPaths {
17
+
18
+ private ArchiveExtractionPaths() {
19
+ }
20
+
21
+ public static Path createRoot(String destination) throws IOException {
22
+ return Files.createDirectories(Path.of(destination)).toRealPath();
23
+ }
24
+
25
+ private static Path resolve(Path root, String entryName) throws IOException {
26
+ if (entryName == null || entryName.isEmpty()) {
27
+ throw new IOException("Empty archive entry name");
28
+ }
29
+ String name = entryName.replace('\\', '/');
30
+ // Reject both Unix absolute paths and Windows rooted/drive-relative paths on all platforms.
31
+ if (name.startsWith("/") || name.matches("^[A-Za-z]:.*")) {
32
+ throw new IOException("Absolute archive entry path");
33
+ }
34
+ try {
35
+ Path relative = Path.of(name);
36
+ if (relative.isAbsolute()) {
37
+ throw new IOException("Absolute archive entry path");
38
+ }
39
+ for (Path part : relative) {
40
+ if ("..".equals(part.toString())) {
41
+ throw new IOException("Parent traversal in archive entry");
42
+ }
43
+ }
44
+ Path result = root.resolve(relative).normalize();
45
+ if (!result.startsWith(root)) {
46
+ throw new IOException("Archive entry outside destination");
47
+ }
48
+ return result;
49
+ } catch (InvalidPathException e) {
50
+ throw new IOException("Invalid archive entry path", e);
51
+ }
52
+ }
53
+
54
+ public static void directory(Path root, String entryName) throws IOException {
55
+ ensureDirectory(root, resolve(root, entryName));
56
+ }
57
+
58
+ public static OutputStream openFile(Path root, String entryName) throws IOException {
59
+ Path target = resolve(root, entryName);
60
+ if (target.equals(root)) {
61
+ throw new IOException("Archive file entry names the destination directory");
62
+ }
63
+ ensureDirectory(root, target.getParent());
64
+ if (Files.exists(target, LinkOption.NOFOLLOW_LINKS)
65
+ && !Files.isRegularFile(target, LinkOption.NOFOLLOW_LINKS)) {
66
+ throw new IOException("Archive entry would overwrite a link or non-regular file");
67
+ }
68
+ return Files.newOutputStream(target, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING,
69
+ StandardOpenOption.WRITE, LinkOption.NOFOLLOW_LINKS);
70
+ }
71
+
72
+ private static void ensureDirectory(Path root, Path directory) throws IOException {
73
+ Path current = root;
74
+ for (Path part : root.relativize(directory)) {
75
+ current = current.resolve(part);
76
+ try {
77
+ Files.createDirectory(current);
78
+ } catch (FileAlreadyExistsException ignored) {
79
+ // Validate the existing component without following symbolic links.
80
+ }
81
+ if (!Files.isDirectory(current, LinkOption.NOFOLLOW_LINKS)) {
82
+ throw new IOException("Archive entry traverses a link or non-directory");
83
+ }
84
+ }
85
+ }
86
+ }