File.canWrite() actually writes stuff

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gary Benson writes:
 > Hi all,
 > 
 > I just noticed that File.canWrite() actually writes things in order to
 > check whether they are writable.  This seems really wrong to me: just
 > checking something should not modify the filesystem!  Does anyone mind
 > if I replace this?

I agree with you.  We should just use access("file", W_OK).

The gcj source I'm looking at has 

  public boolean canWrite()
  {
    checkWrite();
    return _access (WRITE);
  }

which is correct, but the Classpath native code I'm looking at uses

  /* The lazy man's way out.  We actually do open the file for writing
     briefly to verify it can be done */
  TARGET_NATIVE_FILE_OPEN_READWRITE (filename, fd, result);
  (*env)->ReleaseStringUTFChars (env, name, filename);
  if (result != TARGET_NATIVE_OK)
    {
      return (0);
    }
  TARGET_NATIVE_FILE_CLOSE (fd, result);

I can't see any code that actually writes anything.

Andrew.


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux