File.canWrite() actually writes stuff

2006-03-30 Thread Gary Benson
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?

Cheers,
Gary



Re: File.canWrite() actually writes stuff

2006-03-30 Thread Andrew Haley
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.



Re: File.canWrite() actually writes stuff

2006-03-30 Thread Gary Benson
Andrew Haley wrote:
> Gary Benson writes:
> > 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.

That particular bit doesn't write any bytes, but it modifies the
file's timestamp.  If you look in VMFile.canWriteDirectory() you'll
see some actual writing.

Cheers,
Gary



Re: File.canWrite() actually writes stuff

2006-03-30 Thread Andrew Haley
Gary Benson writes:
 > 
 > That particular bit doesn't write any bytes, but it modifies the
 > file's timestamp.

Ah, OK.  Nasty.

Andrew.



Re: File.canWrite() actually writes stuff

2006-04-03 Thread Mark Wielaard
Hi Gary,

On Thu, 2006-03-30 at 10:24 +0100, Gary Benson wrote:
> 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?

Yes please! It would be nice if we had a real test instead of the
canWriteDirectory(File) hack that is in place now.

Cheers,

Mark


signature.asc
Description: This is a digitally signed message part