65
65
import java .nio .file .attribute .FileAttribute ;
66
66
import java .nio .file .attribute .FileTime ;
67
67
import java .util .ArrayList ;
68
- import java .util .Collections ;
69
68
import java .util .HashSet ;
70
69
import java .util .Iterator ;
71
70
import java .util .List ;
@@ -156,7 +155,7 @@ public void toRealPath() throws Exception {
156
155
assertEquals (VFS_ROOT_PATH .resolve ("dir1" ), rwHostIOVFS .toRealPath (Path .of (realFSDir .toString () + "/.." .repeat (realFSDir .getNameCount ()) + VFS_ROOT ).resolve ("dir1" )));
157
156
}
158
157
159
- private void toRealPathVFS (FileSystem fs , String pathPrefix ) throws IOException {
158
+ private static void toRealPathVFS (FileSystem fs , String pathPrefix ) throws IOException {
160
159
// check regular resource dir
161
160
assertEquals (Path .of (VFS_ROOT + "dir1" ), fs .toRealPath (Path .of (pathPrefix + "dir1/../dir1" )));
162
161
// check regular resource file
@@ -330,7 +329,7 @@ public void checkAccess() throws Exception {
330
329
checkException (SecurityException .class , () -> noHostIOVFS .checkAccess (realFSPath , Set .of (AccessMode .READ )), "expected error for no host io fs" );
331
330
}
332
331
333
- private void checkAccessVFS (FileSystem fs , String pathPrefix ) throws IOException {
332
+ private static void checkAccessVFS (FileSystem fs , String pathPrefix ) throws IOException {
334
333
// check regular resource dir
335
334
fs .checkAccess (Path .of (pathPrefix + "dir1" ), Set .of (AccessMode .READ ));
336
335
// check regular resource file
@@ -418,7 +417,7 @@ public void delete() throws Exception {
418
417
});
419
418
}
420
419
421
- private void deleteVFS (FileSystem fs , String pathPrefix ) {
420
+ private static void deleteVFS (FileSystem fs , String pathPrefix ) {
422
421
checkDelete (fs , pathPrefix + "file1" );
423
422
checkDelete (fs , pathPrefix + "dir1" );
424
423
checkDelete (fs , pathPrefix + "extractme" );
@@ -457,7 +456,7 @@ public void newByteChannel() throws Exception {
457
456
}
458
457
}
459
458
460
- private void newByteChannelVFS (FileSystem fs , String pathPrefix ) throws IOException {
459
+ private static void newByteChannelVFS (FileSystem fs , String pathPrefix ) throws IOException {
461
460
Path path = Path .of (pathPrefix + "file1" );
462
461
for (StandardOpenOption o : StandardOpenOption .values ()) {
463
462
if (o == StandardOpenOption .READ ) {
@@ -479,7 +478,7 @@ private void newByteChannelVFS(FileSystem fs, String pathPrefix) throws IOExcept
479
478
checkCanOnlyRead (fs , path , StandardOpenOption .READ , StandardOpenOption .WRITE );
480
479
}
481
480
482
- private void newByteChannelRealFS (FileSystem fs , Path path , String expectedText ) throws IOException {
481
+ private static void newByteChannelRealFS (FileSystem fs , Path path , String expectedText ) throws IOException {
483
482
SeekableByteChannel bch = fs .newByteChannel (path , Set .of (StandardOpenOption .READ ));
484
483
ByteBuffer buffer = ByteBuffer .allocate (expectedText .length ());
485
484
bch .read (buffer );
@@ -580,7 +579,7 @@ public void libsExtract() throws Exception {
580
579
windowsMountPoint (VFS_WIN_MOUNT_POINT ).//
581
580
extractFilter (p -> p .getFileName ().toString ().endsWith (".tso" )).//
582
581
resourceLoadingClass (VirtualFileSystemTest .class ).build ());
583
- Path p = fs .toAbsolutePath (VFS_ROOT_PATH .resolve ("site-packages/testpkg/file.tso" ));
582
+ Path p = fs .toRealPath (VFS_ROOT_PATH .resolve ("site-packages/testpkg/file.tso" ));
584
583
checkExtractedFile (p , null );
585
584
Path extractedRoot = p .getParent ().getParent ().getParent ();
586
585
@@ -592,7 +591,7 @@ public void libsExtract() throws Exception {
592
591
checkExtractedFile (extractedRoot .resolve ("site-packages/testpkg.libs/dir/dir/file1.tso" ), null );
593
592
checkExtractedFile (extractedRoot .resolve ("site-packages/testpkg.libs/dir/dir/file2.tso" ), null );
594
593
595
- p = fs .toAbsolutePath (VFS_ROOT_PATH .resolve ("site-packages/testpkg-nolibs/file.tso" ));
594
+ p = fs .toRealPath (VFS_ROOT_PATH .resolve ("site-packages/testpkg-nolibs/file.tso" ));
596
595
checkExtractedFile (p , null );
597
596
}
598
597
@@ -667,33 +666,33 @@ public void currentWorkingDirectory() throws Exception {
667
666
checkException (IllegalArgumentException .class , () -> fs .setCurrentWorkingDirectory (VFS_ROOT_PATH .resolve ("file1" )));
668
667
669
668
try {
670
- // support non existing working dir
671
669
Path nonExistingDir = VFS_ROOT_PATH .resolve ("does-not-exist" );
672
670
fs .setCurrentWorkingDirectory (nonExistingDir );
673
671
assertEquals (nonExistingDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
674
672
675
673
Path vfsDir = VFS_ROOT_PATH .resolve ("dir1" );
676
674
fs .setCurrentWorkingDirectory (vfsDir );
677
675
assertEquals (vfsDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
678
- } finally {
679
- resetCWD (fs );
680
- }
681
676
682
- checkException (IllegalArgumentException .class , () -> fs .setCurrentWorkingDirectory (realFSFile ));
683
- try {
684
- // support non existing working dir
685
- Path nonExistingDir = realFSDir .resolve ("does-not-exist" );
686
- fs .setCurrentWorkingDirectory (nonExistingDir );
687
- assertEquals (nonExistingDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
677
+ fs .setCurrentWorkingDirectory (Path .of (realFSDir .toString () + "/.." .repeat (realFSDir .getNameCount ()) + VFS_ROOT ));
678
+ assertEquals (VFS_ROOT_PATH .resolve ("dir1" ), fs .toAbsolutePath (Path .of ("dir1" )));
688
679
689
- fs .setCurrentWorkingDirectory (realFSDir );
690
- assertEquals (realFSDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
680
+ if (fs == noHostIOVFS ) {
681
+ fs .setCurrentWorkingDirectory (realFSFile );
682
+ assertEquals (VFS_ROOT_PATH , fs .toAbsolutePath (Path .of (realFSFile .toString () + "/.." .repeat (realFSFile .getNameCount ()) + VFS_ROOT )));
683
+ } else {
684
+ checkException (IllegalArgumentException .class , () -> fs .setCurrentWorkingDirectory (realFSFile ));
691
685
692
- fs .setCurrentWorkingDirectory (Path .of (VFS_ROOT + "../" + realFSDir .toString ()));
693
- assertEquals (realFSDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
686
+ nonExistingDir = realFSDir .resolve ("does-not-exist" );
687
+ fs .setCurrentWorkingDirectory (nonExistingDir );
688
+ assertEquals (nonExistingDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
694
689
695
- fs .setCurrentWorkingDirectory (Path .of (realFSDir .toString () + "/.." .repeat (realFSDir .getNameCount ()) + VFS_ROOT ));
696
- assertEquals (VFS_ROOT_PATH .resolve ("dir1" ), fs .toAbsolutePath (Path .of ("dir1" )));
690
+ fs .setCurrentWorkingDirectory (realFSDir );
691
+ assertEquals (realFSDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
692
+
693
+ fs .setCurrentWorkingDirectory (Path .of (VFS_ROOT + "../" + realFSDir .toString ()));
694
+ assertEquals (realFSDir , fs .toAbsolutePath (Path .of ("dir" )).getParent ());
695
+ }
697
696
} finally {
698
697
resetCWD (fs );
699
698
}
0 commit comments