6728842: File.setReadOnly does not make a directory read-only (win)

Rémi Forax forax at univ-mlv.fr
Wed Sep 29 14:40:49 UTC 2010


Le 29/09/2010 15:57, Alan Bateman a écrit :
>
> I need a reviewer for a change to java.io.File's setReadOnly and 
> setWritable methods so that they don't change the DOS readonly 
> attribute on directories (or folders as Windows calls them). These 
> methods have never worked correctly for directories on Windows because 
> the semantics of this attribute is different for directories (it 
> determines if the directory can be deleted, not whether is is 
> writable, and is used by Windows Explorer to determine if the 
> directory is special, sending it off looking for a hidden Desktop.ini 
> file). Early on in jdk7, the canWrite method was changed to ignore the 
> readonly attribute on directories so changing the set* methods to 
> ignore the attribute  restores the status quo. I should say that 
> changing the implementation has some risk. If it does cause problems 
> they we may need to include a compatibility switch. The alternative to 
> ignoring the readonly attribute is to insert a deny rule into the 
> directory's DACL (when on NTFS) but that has a lot of potential to 
> cause problems for end-users. As part of the change proposed here, the 
> SetAccess test has been changed so that it no longer execs "ls -l" and 
> this fixes another bug (6464744) where the test fails if the sticky 
> bit is set. The webrev with the changes is here:
>  http://cr.openjdk.java.net/~alanb/6728842/webrev/
>
> Thanks,
> Alan.

There is a small copy/paste error in setAccess.doTest() for Windows 
specific tests,
the exception message of the thrown Exception doesn't match the test.

                      // setWritable should fail on directories because the DOS readonly
  148                 // attribute prevents a directory from being deleted.
  149                 if (f.setWritable(false, true))
  150                     throw new Exception(f + ": setWritable(false, true) Succeeded");
  151                 if (f.setWritable(false, false))
  152                     throw new Exception(f + ": setWritable(false, true) Succeeded");
  153                 if (f.setWritable(false))
  154                     throw new Exception(f + ": setWritable(false, true) Succeeded");

should be

                      // setWritable should fail on directories because the DOS readonly
  148                 // attribute prevents a directory from being deleted.
  149                 if (f.setWritable(false, true))
  150                     throw new Exception(f + ": setWritable(false, true) Succeeded");
  151                 if (f.setWritable(false, false))
  152                     throw new Exception(f + ": setWritable(false, false) Succeeded");
  153                 if (f.setWritable(false))
  154                     throw new Exception(f + ": setWritable(false) Succeeded");

Other changes look fine.

Rémi




More information about the core-libs-dev mailing list