|
20 | 20 | import java.nio.charset.StandardCharsets;
|
21 | 21 | import java.nio.file.FileStore;
|
22 | 22 | import java.nio.file.FileSystems;
|
| 23 | +import java.nio.file.Files; |
23 | 24 | import java.nio.file.NoSuchFileException;
|
24 | 25 | import java.nio.file.Path;
|
| 26 | +import java.nio.file.attribute.FileAttribute; |
25 | 27 | import java.nio.file.spi.FileSystemProvider;
|
26 | 28 | import java.security.PrivilegedActionException;
|
27 | 29 | import java.util.Properties;
|
@@ -279,6 +281,48 @@ public Path getPath(URI uri) {
|
279 | 281 | }
|
280 | 282 | }
|
281 | 283 |
|
| 284 | + /** |
| 285 | + * If the implementation of {@link QuotaAwareFileSystemProvider#createLink(Path, Path)} |
| 286 | + * doesn't unwrap its {@link Path} arguments, it causes a runtime exception, so exercise |
| 287 | + * this method to check that it unwraps correctly. |
| 288 | + */ |
| 289 | + public void testCreateLinkUnwrapsPaths() throws Exception { |
| 290 | + final Path tempDir = createTempDir(); |
| 291 | + Path quotaFile = tempDir.resolve("quota.properties"); |
| 292 | + FileSystemProvider systemProvider = quotaFile.getFileSystem().provider(); |
| 293 | + writeQuota(500, 200, systemProvider, quotaFile); |
| 294 | + |
| 295 | + try (QuotaAwareFileSystemProvider provider = new QuotaAwareFileSystemProvider(systemProvider, quotaFile.toUri())) { |
| 296 | + final Path quotaFilePath = provider.getPath(tempDir.resolve("path1.txt").toUri()); |
| 297 | + final Path quotaLinkPath = provider.getPath(tempDir.resolve("path2.txt").toUri()); |
| 298 | + |
| 299 | + Files.write(quotaFilePath, "some text".getBytes(StandardCharsets.UTF_8)); |
| 300 | + |
| 301 | + provider.createLink(quotaLinkPath, quotaFilePath); |
| 302 | + } |
| 303 | + } |
| 304 | + |
| 305 | + /** |
| 306 | + * If the implementation of {@link QuotaAwareFileSystemProvider#createSymbolicLink(Path, Path, FileAttribute[])} |
| 307 | + * doesn't unwrap its {@link Path} arguments, it causes a runtime exception, so exercise |
| 308 | + * this method to check that it unwraps correctly. |
| 309 | + */ |
| 310 | + public void testCreateSymbolicLinkUnwrapsPaths() throws Exception { |
| 311 | + final Path tempDir = createTempDir(); |
| 312 | + Path quotaFile = tempDir.resolve("quota.properties"); |
| 313 | + FileSystemProvider systemProvider = quotaFile.getFileSystem().provider(); |
| 314 | + writeQuota(500, 200, systemProvider, quotaFile); |
| 315 | + |
| 316 | + try (QuotaAwareFileSystemProvider provider = new QuotaAwareFileSystemProvider(systemProvider, quotaFile.toUri())) { |
| 317 | + final Path quotaFilePath = provider.getPath(tempDir.resolve("path1.txt").toUri()); |
| 318 | + final Path quotaLinkPath = provider.getPath(tempDir.resolve("path2.txt").toUri()); |
| 319 | + |
| 320 | + Files.write(quotaFilePath, "some text".getBytes(StandardCharsets.UTF_8)); |
| 321 | + |
| 322 | + provider.createSymbolicLink(quotaLinkPath, quotaFilePath); |
| 323 | + } |
| 324 | + } |
| 325 | + |
282 | 326 | private void doValidFileTest(long expectedTotal, long expectedRemaining) throws Exception {
|
283 | 327 | Path quotaFile = createTempDir().resolve("quota.properties");
|
284 | 328 | FileSystemProvider systemProvider = quotaFile.getFileSystem().provider();
|
|
0 commit comments