Skip to content

Commit 3b4ab52

Browse files
committed
Fix missing QuotaPath.unwrap() instances (#67165)
Closes #67164. There were a couple of places in `QuotaAwareFileSystemProvider` where the supplied paths were not being unwrapped back into platform-specific path objects.
1 parent b0cfc82 commit 3b4ab52

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

x-pack/quota-aware-fs/src/main/java/org/elasticsearch/fs/quotaaware/QuotaAwareFileSystemProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,12 @@ public void close() throws IOException {
408408

409409
@Override
410410
public void createLink(Path link, Path existing) throws IOException {
411-
delegate.createLink(link, existing);
411+
delegate.createLink(QuotaAwarePath.unwrap(link), QuotaAwarePath.unwrap(existing));
412412
}
413413

414414
@Override
415415
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException {
416-
delegate.createSymbolicLink(link, target, attrs);
416+
delegate.createSymbolicLink(QuotaAwarePath.unwrap(link), QuotaAwarePath.unwrap(target), attrs);
417417
}
418418

419419
void purge(FileSystem delegateFileSystem) {

x-pack/quota-aware-fs/src/test/java/org/elasticsearch/fs/quotaaware/QuotaAwareFileSystemProviderTests.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import java.nio.charset.StandardCharsets;
2121
import java.nio.file.FileStore;
2222
import java.nio.file.FileSystems;
23+
import java.nio.file.Files;
2324
import java.nio.file.NoSuchFileException;
2425
import java.nio.file.Path;
26+
import java.nio.file.attribute.FileAttribute;
2527
import java.nio.file.spi.FileSystemProvider;
2628
import java.security.PrivilegedActionException;
2729
import java.util.Properties;
@@ -279,6 +281,48 @@ public Path getPath(URI uri) {
279281
}
280282
}
281283

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+
282326
private void doValidFileTest(long expectedTotal, long expectedRemaining) throws Exception {
283327
Path quotaFile = createTempDir().resolve("quota.properties");
284328
FileSystemProvider systemProvider = quotaFile.getFileSystem().provider();

0 commit comments

Comments
 (0)