renameTo for Directories on Solaris  
Author Message
ebresie





PostPosted: 2006-4-12 5:49:00 Top

java-programmer, renameTo for Directories on Solaris I've been attempting to rename a directory on Solaris 8 and continue to
have problems.

I read other threads that mention it is not possible to do when moving
between partitions on Solaris, but I am renaming to the same
paritition.

I am basically attempting the following:

File oldName = new File("/opt/OldDirectoryName");
File newName = new File("/opt/NewDirectoryName");

if ( oldName.renameTo( newName ) )
// Successfully renamed
else
// Failed to rename

For some reason I seem to continually be unable to do this.

Any ideas?

Eric

 
Thomas Fritsch





PostPosted: 2006-4-12 6:46:00 Top

java-programmer >> renameTo for Directories on Solaris <email***@***.com> wrote:
> I am basically attempting the following:
>
> File oldName = new File("/opt/OldDirectoryName");
> File newName = new File("/opt/NewDirectoryName");
>
> if ( oldName.renameTo( newName ) )
> // Successfully renamed
> else
> // Failed to rename
>
> For some reason I seem to continually be unable to do this.
>
> Any ideas?

What happens if you try it in a shell
mv /opt/OldDirectoryName /opt/NewDirectoryName
? Do you get an error message from the shell?
I would guess, you'll get something like "permission denied", because the
operation requires write-access to the /opt directory.

--
"TFritsch$t-online:de".replace(':','.').replace('$','@')


 
JScoobyCed





PostPosted: 2006-4-12 9:44:00 Top

java-programmer >> renameTo for Directories on Solaris Thomas Fritsch wrote:
> <email***@***.com> wrote:
>> if ( oldName.renameTo( newName ) )
>> // Successfully renamed
>> else
>> // Failed to rename
>>
>> For some reason I seem to continually be unable to do this.
>>
>> Any ideas?
>
> What happens if you try it in a shell
> mv /opt/OldDirectoryName /opt/NewDirectoryName
> ? Do you get an error message from the shell?
> I would guess, you'll get something like "permission denied", because the
> operation requires write-access to the /opt directory.
>

It's a good suggestion, but not necessary the right thing. I got similar
problem on FreeBSD (ok, Mac OS X :) ). I could rename or move or delete
my file with the shell command line, but not from Java File.renameTo(File)
Unfortunately at that time I was in a hurry to close the project and did
"the dirty Harry way" (shame on me):
FileInputStream on the oldFile
FileOutputStream on the new file
read from old file arrays of byte[] and write them to the output.

It has the advantage of working, but in term of performances, it is
really bad. My project didn't need performance, so it was ok, but...

--
JSC
 
 
ebresie





PostPosted: 2006-4-13 0:26:00 Top

java-programmer >> renameTo for Directories on Solaris Does that work for directories as well?

I'm not really up on java security configuration processes, but could
this in any way have to do with security policy for my java
environment?

Eric

 
 
ebresie





PostPosted: 2006-4-13 0:30:00 Top

java-programmer >> renameTo for Directories on Solaris Yup...this seems to be the case.

I had performed the rename step in a perl script previously, which I
was attempting to duplicated in java. The perl script was running as
root at boot time, so it did not exhibit this problem.

Eric

 
 
Thomas Fritsch





PostPosted: 2006-4-13 0:57:00 Top

java-programmer >> renameTo for Directories on Solaris email***@***.com schrieb:

> Does that work for directories as well?
>
> I'm not really up on java security configuration processes, but could
> this in any way have to do with security policy for my java
> environment?
If renameFile() fails because of java security, then you would get a
SecurityException. If it fails because of another reason (OS denies
permission), then you get "false" as return-value. So you can
distinguish between these causes easily.

--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')