jdk/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java
changeset 21290 db5e0cad1102
parent 13246 a54c4f70775c
child 21292 f55838e2d1e0
equal deleted inserted replaced
21289:95fcae9543b4 21290:db5e0cad1102
    40  */
    40  */
    41 
    41 
    42 class SolarisUserDefinedFileAttributeView
    42 class SolarisUserDefinedFileAttributeView
    43     extends AbstractUserDefinedFileAttributeView
    43     extends AbstractUserDefinedFileAttributeView
    44 {
    44 {
       
    45     private static final byte[] HERE = { '.' };
       
    46 
    45     private byte[] nameAsBytes(UnixPath file, String name) throws IOException {
    47     private byte[] nameAsBytes(UnixPath file, String name) throws IOException {
    46         byte[] bytes = name.getBytes();
    48         byte[] bytes = Util.toBytes(name);
    47         //  "", "." and ".." not allowed
    49         //  "", "." and ".." not allowed
    48         if (bytes.length == 0 || bytes[0] == '.') {
    50         if ((bytes.length == 0 || bytes[0] == '.') &&
    49             if (bytes.length <= 1 ||
    51             ((bytes.length <= 1 || (bytes.length == 2 && bytes[1] == '.')) {
    50                 (bytes.length == 2 && bytes[1] == '.'))
    52             throw new FileSystemException(file.getPathForExceptionMessage(),
    51             {
    53                 null, "'" + name + "' is not a valid name");
    52                 throw new FileSystemException(file.getPathForExceptionMessage(),
       
    53                     null, "'" + name + "' is not a valid name");
       
    54             }
       
    55         }
    54         }
    56         return bytes;
    55         return bytes;
    57     }
    56     }
    58 
    57 
    59     private final UnixPath file;
    58     private final UnixPath file;
    71 
    70 
    72         int fd = file.openForAttributeAccess(followLinks);
    71         int fd = file.openForAttributeAccess(followLinks);
    73         try {
    72         try {
    74             try {
    73             try {
    75                 // open extended attribute directory
    74                 // open extended attribute directory
    76                 int dfd = openat(fd, ".".getBytes(), (O_RDONLY|O_XATTR), 0);
    75                 int dfd = openat(fd, HERE, (O_RDONLY|O_XATTR), 0);
    77                 long dp;
    76                 long dp;
    78                 try {
    77                 try {
    79                     dp = fdopendir(dfd);
    78                     dp = fdopendir(dfd);
    80                 } catch (UnixException x) {
    79                 } catch (UnixException x) {
    81                     close(dfd);
    80                     close(dfd);
    85                 // read list of extended attributes
    84                 // read list of extended attributes
    86                 List<String> list = new ArrayList<>();
    85                 List<String> list = new ArrayList<>();
    87                 try {
    86                 try {
    88                     byte[] name;
    87                     byte[] name;
    89                     while ((name = readdir(dp)) != null) {
    88                     while ((name = readdir(dp)) != null) {
    90                         String s = new String(name);
    89                         String s = Util.toString(name);
    91                         if (!s.equals(".") && !s.equals(".."))
    90                         if (!s.equals(".") && !s.equals(".."))
    92                             list.add(s);
    91                             list.add(s);
    93                     }
    92                     }
    94                 } finally {
    93                 } finally {
    95                     closedir(dp);
    94                     closedir(dp);
   215         if (System.getSecurityManager() != null)
   214         if (System.getSecurityManager() != null)
   216             checkAccess(file.getPathForPermissionCheck(), false, true);
   215             checkAccess(file.getPathForPermissionCheck(), false, true);
   217 
   216 
   218         int fd = file.openForAttributeAccess(followLinks);
   217         int fd = file.openForAttributeAccess(followLinks);
   219         try {
   218         try {
   220             int dfd = openat(fd, ".".getBytes(), (O_RDONLY|O_XATTR), 0);
   219             int dfd = openat(fd, HERE, (O_RDONLY|O_XATTR), 0);
   221             try {
   220             try {
   222                 unlinkat(dfd, nameAsBytes(file,name), 0);
   221                 unlinkat(dfd, nameAsBytes(file,name), 0);
   223             } finally {
   222             } finally {
   224                 close(dfd);
   223                 close(dfd);
   225             }
   224             }
   241      *          file descriptor for target file
   240      *          file descriptor for target file
   242      */
   241      */
   243     static void copyExtendedAttributes(int ofd, int nfd) {
   242     static void copyExtendedAttributes(int ofd, int nfd) {
   244         try {
   243         try {
   245             // open extended attribute directory
   244             // open extended attribute directory
   246             int dfd = openat(ofd, ".".getBytes(), (O_RDONLY|O_XATTR), 0);
   245             int dfd = openat(ofd, HERE, (O_RDONLY|O_XATTR), 0);
   247             long dp = 0L;
   246             long dp = 0L;
   248             try {
   247             try {
   249                 dp = fdopendir(dfd);
   248                 dp = fdopendir(dfd);
   250             } catch (UnixException x) {
   249             } catch (UnixException x) {
   251                 close(dfd);
   250                 close(dfd);