62 // cached hashcode (created lazily, no need to be volatile) |
62 // cached hashcode (created lazily, no need to be volatile) |
63 private int hash; |
63 private int hash; |
64 |
64 |
65 // array of offsets of elements in path (created lazily) |
65 // array of offsets of elements in path (created lazily) |
66 private volatile int[] offsets; |
66 private volatile int[] offsets; |
67 |
|
68 // file permissions (created lazily) |
|
69 private volatile FilePermission[] perms; |
|
70 |
67 |
71 UnixPath(UnixFileSystem fs, byte[] path) { |
68 UnixPath(UnixFileSystem fs, byte[] path) { |
72 this.fs = fs; |
69 this.fs = fs; |
73 this.path = path; |
70 this.path = path; |
74 } |
71 } |
766 x.rethrowAsIOException(this); |
763 x.rethrowAsIOException(this); |
767 return -1; // keep compile happy |
764 return -1; // keep compile happy |
768 } |
765 } |
769 } |
766 } |
770 |
767 |
771 // create file permissions used for read and write checks |
768 |
772 private void checkReadOrWrite(boolean checkRead) { |
769 void checkRead() { |
773 SecurityManager sm = System.getSecurityManager(); |
770 SecurityManager sm = System.getSecurityManager(); |
774 if (sm == null) |
771 if (sm != null) |
775 return; |
772 sm.checkRead(getPathForPermissionCheck()); |
776 if (perms == null) { |
|
777 synchronized (this) { |
|
778 if (perms == null) { |
|
779 FilePermission[] p = new FilePermission[2]; |
|
780 String pathForPermCheck = getPathForPermissionCheck(); |
|
781 p[0] = new FilePermission(pathForPermCheck, |
|
782 SecurityConstants.FILE_READ_ACTION); |
|
783 p[1] = new FilePermission(pathForPermCheck, |
|
784 SecurityConstants.FILE_WRITE_ACTION); |
|
785 perms = p; |
|
786 } |
|
787 } |
|
788 } |
|
789 if (checkRead) { |
|
790 sm.checkPermission(perms[0]); |
|
791 } else { |
|
792 sm.checkPermission(perms[1]); |
|
793 } |
|
794 } |
|
795 |
|
796 void checkRead() { |
|
797 checkReadOrWrite(true); |
|
798 } |
773 } |
799 |
774 |
800 void checkWrite() { |
775 void checkWrite() { |
801 checkReadOrWrite(false); |
776 SecurityManager sm = System.getSecurityManager(); |
|
777 if (sm != null) |
|
778 sm.checkWrite(getPathForPermissionCheck()); |
802 } |
779 } |
803 |
780 |
804 void checkDelete() { |
781 void checkDelete() { |
805 SecurityManager sm = System.getSecurityManager(); |
782 SecurityManager sm = System.getSecurityManager(); |
806 if (sm != null) { |
783 if (sm != null) |
807 // permission not cached |
|
808 sm.checkDelete(getPathForPermissionCheck()); |
784 sm.checkDelete(getPathForPermissionCheck()); |
809 } |
|
810 } |
785 } |
811 |
786 |
812 @Override |
787 @Override |
813 public FileStore getFileStore() |
788 public FileStore getFileStore() |
814 throws IOException |
789 throws IOException |