nashorn/src/jdk/nashorn/internal/runtime/CodeStore.java
changeset 23769 e461495852b7
parent 23767 7c0614b75e23
child 24778 2ff5d7041566
equal deleted inserted replaced
23767:7c0614b75e23 23769:e461495852b7
    68      * @param path directory to store code in
    68      * @param path directory to store code in
    69      * @param minSize minimum file size for caching scripts
    69      * @param minSize minimum file size for caching scripts
    70      * @throws IOException
    70      * @throws IOException
    71      */
    71      */
    72     public CodeStore(final String path, final int minSize) throws IOException {
    72     public CodeStore(final String path, final int minSize) throws IOException {
    73         this.dir = new File(path);
    73         this.dir = checkDirectory(path);
    74         this.minSize = minSize;
    74         this.minSize = minSize;
    75         checkDirectory(this.dir);
       
    76     }
    75     }
    77 
    76 
    78     private static void checkDirectory(final File dir) throws IOException {
    77     private static File checkDirectory(final String path) throws IOException {
    79         try {
    78         try {
    80             AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
    79             return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() {
    81                 @Override
    80                 @Override
    82                 public Void run() throws IOException {
    81                 public File run() throws IOException {
       
    82                     final File dir = new File(path).getAbsoluteFile();
    83                     if (!dir.exists() && !dir.mkdirs()) {
    83                     if (!dir.exists() && !dir.mkdirs()) {
    84                         throw new IOException("Could not create directory: " + dir);
    84                         throw new IOException("Could not create directory: " + dir);
    85                     } else if (!dir.isDirectory()) {
    85                     } else if (!dir.isDirectory()) {
    86                         throw new IOException("Not a directory: " + dir);
    86                         throw new IOException("Not a directory: " + dir);
    87                     } else if (!dir.canRead() || !dir.canWrite()) {
    87                     } else if (!dir.canRead() || !dir.canWrite()) {
    88                         throw new IOException("Directory not readable or writable: " + dir);
    88                         throw new IOException("Directory not readable or writable: " + dir);
    89                     }
    89                     }
    90                     return null;
    90                     return dir;
    91                 }
    91                 }
    92             });
    92             });
    93         } catch (PrivilegedActionException e) {
    93         } catch (PrivilegedActionException e) {
    94             throw (IOException) e.getException();
    94             throw (IOException) e.getException();
    95         }
    95         }