@@ -629,9 +629,7 @@ public void checkAccess(Path p, Set<? extends AccessMode> modes, LinkOption... l
629
629
}
630
630
} else {
631
631
if (modes .contains (AccessMode .WRITE )) {
632
- String msg = String .format ("read-only filesystem: '%s'" , path );
633
- finer ("VFS.checkAccess %s" , msg );
634
- throw new SecurityException (msg );
632
+ throw securityException ("VFS.checkAccess" , String .format ("read-only filesystem, write access not supported '%s'" , path ));
635
633
}
636
634
if (getEntry (path ) == null ) {
637
635
String msg = String .format ("no such file or directory: '%s'" , path );
@@ -656,9 +654,7 @@ public void createDirectory(Path d, FileAttribute<?>... attrs) throws IOExceptio
656
654
finest ("VFS.createDirectory delegated '%s' %s" , dir , passed ? "passed" : "did not pass" );
657
655
}
658
656
} else {
659
- String msg = String .format ("read-only filesystem: '%s'" , dir );
660
- finer ("VFS.createDirectory %s" , msg );
661
- throw new SecurityException (msg );
657
+ throw securityException ("VFS.createDirectory" , String .format ("read-only filesystem, create directory not supported '%s'" , dir ));
662
658
}
663
659
}
664
660
@@ -675,9 +671,7 @@ public void delete(Path p) throws IOException {
675
671
finest ("VFS.delete delegated '%s' %s" , path , passed ? "passed" : "did not pass" );
676
672
}
677
673
} else {
678
- String msg = String .format ("read-only filesystem: '%s'" , path );
679
- finer ("VFS.delete %s" , msg );
680
- throw new SecurityException (msg );
674
+ throw securityException ("VFS.delete" , String .format ("read-only filesystem, delete not supported: '%s'" , path ));
681
675
}
682
676
}
683
677
@@ -772,9 +766,7 @@ public void close() throws IOException {
772
766
}
773
767
};
774
768
} else {
775
- String msg = String .format ("read-only filesystem: '%s'" , path );
776
- finer ("VFS.newByteChannel '%s'" , msg );
777
- throw new SecurityException (msg );
769
+ throw securityException ("VFS.newByteChannel" , String .format ("read-only filesystem, can create byte channel only for READ: '%s'" , path ));
778
770
}
779
771
}
780
772
@@ -958,9 +950,7 @@ public void copy(Path s, Path t, CopyOption... options) throws IOException {
958
950
Path source = toAbsolutePathInternal (s );
959
951
Path target = toAbsolutePathInternal (t );
960
952
if (pathIsInVfs (target )) {
961
- String msg = String .format ("read-only filesystem, can't copy %s -> %s" , source , target );
962
- finer ("VFS.move %s" , msg );
963
- throw new SecurityException (msg );
953
+ throw securityException ("VFS.move" , String .format ("read-only filesystem, can't copy '%s' to '%s'" , source , target ));
964
954
} else {
965
955
if (allowHostIO == READ_WRITE && pathIsInVfs (source )) {
966
956
FileSystem .super .copy (source , target , options );
@@ -979,9 +969,7 @@ public void move(Path s, Path t, CopyOption... options) throws IOException {
979
969
if (!pathIsInVfs (source ) && !pathIsInVfs (target )) {
980
970
delegate .move (source , target , options );
981
971
} else {
982
- String msg = String .format ("read-only filesystem, can't move %s -> %s" , source , target );
983
- finer ("VFS.move %s" , msg );
984
- throw new SecurityException (msg );
972
+ throw securityException ("VFS.move" , String .format ("read-only filesystem, can't move '%s' to '%s'" , source , target ));
985
973
}
986
974
}
987
975
@@ -1005,9 +993,7 @@ public void createSymbolicLink(Path l, Path t, FileAttribute<?>... attrs) throws
1005
993
if (!pathIsInVfs (link ) && !pathIsInVfs (target )) {
1006
994
delegate .createSymbolicLink (link , target , attrs );
1007
995
} else {
1008
- String msg = String .format ("read-only filesystem, can't create link %s -> %s" , link , target );
1009
- finer ("VFS.createSymbolicLink %s" , msg );
1010
- throw new SecurityException (msg );
996
+ throw securityException ("VFS.createSymbolicLink" , String .format ("read-only filesystem, can't create symbolic link from '%s' to '%s'" , link , target ));
1011
997
}
1012
998
}
1013
999
@@ -1020,9 +1006,7 @@ public void createLink(Path l, Path e) throws IOException {
1020
1006
if (!pathIsInVfs (link ) && !pathIsInVfs (existing )) {
1021
1007
delegate .createLink (link , existing );
1022
1008
} else {
1023
- String msg = String .format ("read-only filesystem, can't create link %s -> %s" , link , existing );
1024
- finer ("VFS.createLink %s" , msg );
1025
- throw new SecurityException (msg );
1009
+ throw securityException ("VFS.createLink" , String .format ("read-only filesystem, can't create link '%s' to '%s'" , link , existing ));
1026
1010
}
1027
1011
}
1028
1012
@@ -1033,9 +1017,7 @@ public Path readSymbolicLink(Path l) throws IOException {
1033
1017
if (!pathIsInVfs (link )) {
1034
1018
return delegate .readSymbolicLink (link );
1035
1019
} else {
1036
- String msg = String .format ("read-only filesystem, can't read symbolic link %s" , link );
1037
- finer ("VFS.readSymbolicLink %s" , msg );
1038
- throw new SecurityException (msg );
1020
+ throw securityException ("VFS.readSymbolicLink" , String .format ("reading symbolic links in VirtualFileSystem not supported %s" , link ));
1039
1021
}
1040
1022
}
1041
1023
@@ -1046,9 +1028,7 @@ public void setAttribute(Path p, String attribute, Object value, LinkOption... o
1046
1028
if (!pathIsInVfs (path )) {
1047
1029
delegate .setAttribute (path , attribute , value , options );
1048
1030
} else {
1049
- String msg = "read-only filesystem" ;
1050
- finer ("VFS.setAttribute %s" , msg );
1051
- throw new SecurityException (msg );
1031
+ throw securityException ("VFS.setAttribute" , String .format ("read-only filesystem, can't set attribute '%s' for '%s" , attribute , p ));
1052
1032
}
1053
1033
}
1054
1034
@@ -1091,6 +1071,14 @@ private static void finest(String msgFormat, Object... args) {
1091
1071
}
1092
1072
}
1093
1073
1074
+ private static SecurityException securityException (String from , String msg ) {
1075
+ finer ("%s %s" , from , msg );
1076
+ throw new SecurityException (msg );
1077
+ }
1078
+
1079
+ /**
1080
+ * copy and paste from c.o.t.polyglot.FileSystems.DeniedIOFileSystem
1081
+ */
1094
1082
private static class DeniedIOFileSystem implements FileSystem {
1095
1083
1096
1084
@ Override
@@ -1104,53 +1092,53 @@ public Path parsePath(final String path) {
1104
1092
}
1105
1093
1106
1094
@ Override
1107
- public void checkAccess (Path path , Set <? extends AccessMode > modes , LinkOption ... linkOptions ) throws IOException {
1108
- throw new SecurityException ( String . format ( "VFS.checkAccess: filesystem without host IO: '%s'" , path ));
1095
+ public void checkAccess (Path path , Set <? extends AccessMode > modes , LinkOption ... linkOptions ) {
1096
+ throw securityException ( "VFS.checkAccess" , String . format ( " filesystem without host IO: '%s'" , path ));
1109
1097
}
1110
1098
1111
1099
@ Override
1112
- public void createDirectory (Path dir , FileAttribute <?>... attrs ) throws IOException {
1113
- throw new SecurityException ( String . format ( "VFS.createDirectory: filesystem without host IO: '%s'" , dir ));
1100
+ public void createDirectory (Path dir , FileAttribute <?>... attrs ) {
1101
+ throw securityException ( "VFS.createDirectory" , String . format ( " filesystem without host IO: '%s'" , dir ));
1114
1102
}
1115
1103
1116
1104
@ Override
1117
- public void delete (Path path ) throws IOException {
1118
- throw new SecurityException ( String . format ( "VFS.delete: filesystem without host IO: '%s'" , path ));
1105
+ public void delete (Path path ) {
1106
+ throw securityException ( "VFS.delete" , String . format ( " filesystem without host IO: '%s'" , path ));
1119
1107
}
1120
1108
1121
1109
@ Override
1122
- public void copy (Path source , Path target , CopyOption ... options ) throws IOException {
1123
- throw new SecurityException ( String . format ( "VFS.copy: filesystem without host IO: '%s', '%s'" , source , target ));
1110
+ public void copy (Path source , Path target , CopyOption ... options ) {
1111
+ throw securityException ( "VFS.copy" , String . format ( " filesystem without host IO: '%s', '%s'" , source , target ));
1124
1112
}
1125
1113
1126
1114
@ Override
1127
- public void move (Path source , Path target , CopyOption ... options ) throws IOException {
1128
- throw new SecurityException ( String . format ( "VFS.move: filesystem without host IO: '%s', '%s'" , source , target ));
1115
+ public void move (Path source , Path target , CopyOption ... options ) {
1116
+ throw securityException ( "VFS.move" , String . format ( " filesystem without host IO: '%s', '%s'" , source , target ));
1129
1117
}
1130
1118
1131
1119
@ Override
1132
1120
public SeekableByteChannel newByteChannel (Path inPath , Set <? extends OpenOption > options , FileAttribute <?>... attrs ) throws IOException {
1133
- throw new SecurityException ( String . format ( "VFS.newByteChannel: filesystem without host IO: '%s'" , inPath ));
1121
+ throw securityException ( "VFS.newByteChannel" , String . format ( "Filesystem without host IO: '%s'" , inPath ));
1134
1122
}
1135
1123
1136
1124
@ Override
1137
1125
public DirectoryStream <Path > newDirectoryStream (Path dir , DirectoryStream .Filter <? super Path > filter ) throws IOException {
1138
- throw new SecurityException ( String . format ( "VFS.newDirectoryStream: filesystem without host IO: '%s'" , dir ));
1126
+ throw securityException ( "VFS.newDirectoryStream" , String . format ( " filesystem without host IO: '%s'" , dir ));
1139
1127
}
1140
1128
1141
1129
@ Override
1142
1130
public Map <String , Object > readAttributes (Path path , String attributes , LinkOption ... options ) {
1143
- throw new SecurityException ( String . format ( "VFS.readAttributes: filesystem without host IO: '%s'" , path ));
1131
+ throw securityException ( "VFS.readAttributes" , String . format ( " filesystem without host IO: '%s'" , path ));
1144
1132
}
1145
1133
1146
1134
@ Override
1147
1135
public void setAttribute (Path path , String attribute , Object value , LinkOption ... options ) {
1148
- throw new SecurityException ( String . format ( "VFS.setAttribute: filesystem without host IO: '%s'" , path ));
1136
+ throw securityException ( "VFS.setAttribute" , String . format ( " filesystem without host IO: '%s'" , path ));
1149
1137
}
1150
1138
1151
1139
@ Override
1152
1140
public Path toAbsolutePath (Path path ) {
1153
- throw new SecurityException ( String . format ( "VFS.toAbsolutePath: filesystem without host IO: '%s'" , path ));
1141
+ throw securityException ( "VFS.toAbsolutePath" , String . format ( " filesystem without host IO: '%s'" , path ));
1154
1142
}
1155
1143
1156
1144
@ Override
@@ -1159,32 +1147,32 @@ public void setCurrentWorkingDirectory(Path currentWorkingDirectory) {
1159
1147
1160
1148
@ Override
1161
1149
public Path toRealPath (Path path , LinkOption ... linkOptions ) {
1162
- throw new SecurityException ( String . format ( "VFS.toRealPath: filesystem without host IO: '%s'" , path ));
1150
+ throw securityException ( "VFS.toRealPath" , String . format ( " filesystem without host IO: '%s'" , path ));
1163
1151
}
1164
1152
1165
1153
@ Override
1166
1154
public Path getTempDirectory () {
1167
- throw new SecurityException ( String . format ( "VFS.getTempDirectory: filesystem without host IO" ));
1155
+ throw securityException ( "VFS.getTempDirectory" , String . format ( " filesystem without host IO" ));
1168
1156
}
1169
1157
1170
1158
@ Override
1171
1159
public void createLink (Path link , Path existing ) {
1172
- throw new SecurityException ( String . format ( "VFS.createLink: filesystem without host IO: '%s'" , link ));
1160
+ throw securityException ( "VFS.createLink" , String . format ( " filesystem without host IO: '%s'" , link ));
1173
1161
}
1174
1162
1175
1163
@ Override
1176
1164
public void createSymbolicLink (Path link , Path target , FileAttribute <?>... attrs ) {
1177
- throw new SecurityException ( String . format ( "VFS.createSymbolicLink: filesystem without host IO: '%s', '%s'" , link , target ));
1165
+ throw securityException ( "VFS.createSymbolicLink" , String . format ( " filesystem without host IO: '%s', '%s'" , link , target ));
1178
1166
}
1179
1167
1180
1168
@ Override
1181
1169
public Path readSymbolicLink (Path link ) {
1182
- throw new SecurityException ( String . format ( "VFS.readSymbolicLink: filesystem without host IO: '%s'" , link ));
1170
+ throw securityException ( "VFS.readSymbolicLink" , String . format ( " filesystem without host IO: '%s'" , link ));
1183
1171
}
1184
1172
1185
1173
@ Override
1186
1174
public boolean isSameFile (Path path1 , Path path2 , LinkOption ... options ) {
1187
- throw new SecurityException ( String . format ( "VFS.isSameFile: filesystem without host IO: '%s', '%s'" , path1 , path2 ));
1175
+ throw securityException ( "VFS.isSameFile" , String . format ( " filesystem without host IO: '%s', '%s'" , path1 , path2 ));
1188
1176
}
1189
1177
}
1190
1178
0 commit comments