Does file renaming always fail if the file is shared?

C

Chris

Suppose one process has a file open, and another process attempts to
rename the file. Is File.rename() always guaranteed to return false in
that case?

Does it at least work across all major operating systems?
 
G

Gordon Beaton

Suppose one process has a file open, and another process attempts to
rename the file. Is File.rename() always guaranteed to return false in
that case?

Does it at least work across all major operating systems?

On many operating systems, it is possible to rename or even delete a
file while it is open by another process.

/gordon
 
I

Ingo R. Homann

Hi,
Suppose one process has a file open, and another process attempts to
rename the file. Is File.rename() always guaranteed to return false in
that case?

Does it at least work across all major operating systems?

Depends what you call "all major operating systems". If you think of
about 90+% of all desktop PCs, then you are right: I suppose, that 90+%
of all desktop PCs either run with Windows XP, Windows 2000 or Windows
95. There it 'works' (which means that you *cannot* rename a 'shared' file).

However, using Linux or Unix, it does *not* work (which means that you
*can* rename the file :)

I'm not sure about the other 'exoticals' (like BeOS, Mac, and so on ;-)

Ciao,
Ingo
 
J

Jason Cavett

Hi,



Depends what you call "all major operating systems". If you think of
about 90+% of all desktop PCs, then you are right: I suppose, that 90+%
of all desktop PCs either run with Windows XP, Windows 2000 or Windows
95. There it 'works' (which means that you *cannot* rename a 'shared' file).

However, using Linux or Unix, it does *not* work (which means that you
*can* rename the file :)

I'm not sure about the other 'exoticals' (like BeOS, Mac, and so on ;-)

Ciao,
Ingo

Windows 95

:: makes a face ::

Anyway, that's one question I've always had - shouldn't Java work the
same way across all OSes? Or does the way Java reacts depend on the
underlying OS (such as renaming a file via Windows vs. Linux).
 
C

Chris Smith

Jason Cavett said:
Anyway, that's one question I've always had - shouldn't Java work the
same way across all OSes? Or does the way Java reacts depend on the
underlying OS (such as renaming a file via Windows vs. Linux).

Java has to balance portability (working the same across all operating
systems) with usability (working the way users of the operating system
would expect). Perhaps it would be possible for Java to invent a scheme
to prevent itself from deleting an open file on Linux; but Linux users,
who are by and large knowledgable about how UNIX typically manages a
filesystem, would not expect it to do so. Using File in creative ways
is not transparently portable anyway (e.g., permissions issues), it
makes sense that Java would choose the other goal here.
 
I

Ingo R. Homann

Hi Jason,

Jason said:
Anyway, that's one question I've always had - shouldn't Java work the
same way across all OSes? Or does the way Java reacts depend on the
underlying OS (such as renaming a file via Windows vs. Linux).

Well, as Chris said: It has to be well-balanced.

To be extreme: Would you want to forbid 'System.getProperty("os.name")'
because it reacts differently on different OSs? Do you want to generally
forbid File-IO, because there are some embedded systems that do not have
something like a Harddisk (not to mention applets or webstart)? Should
the maximum size of a window that Java can use, be restricted to 80*40
pixel because that is the only resolution, that *every* hardware (even
mobile phones) supports? Should we forbid network-support?

The other extreme: Should sun invest some months of manpower (not to
mention legal problems) to 'hack' Windows so that Java can rename a file
that is opened by another program? Or should it hack Unix and Linux so
that the File can *not* be renamed, although it would be supported by
the OS?

I think the balance between the two extremes should be practical. And
that is what's happening at the moment. :)

Ciao,
Ingo
 
C

Chris Uppal

Chris said:
Suppose one process has a file open, and another process attempts to
rename the file. Is File.rename() always guaranteed to return false in
that case?
Nope.

Does it at least work across all major operating systems?

Windows and Unix behave differently in this (and it's part of the standard
semantics of their respective file-systems -- nothing Java specific).

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top