Hi all,
Is there a way, once a file has been opened, to determine whether it’s
been deleted versus moved?
More of an OS question I suppose, but…
For example, using a file called “temp” with a single line “Hello
World!” in it, let’s say I do this.
f = File.open(“temp”,“r”)
while true
What should the test be?
puts f.gets
f.rewind
end
As is, this program will continue to function if “temp” is moved to,
say, temp1. The filehandle then reads from temp1. But, how do I detect
that the file which the filehandle is attached to no longer exists?
The trick is, in the while loop above, I can’t simply use an 'exist?'
test, because that wants a filename, and “temp” no longer exists (it’s
now temp1).
I tried using stat.inode, thinking the inode would be set to nil if the
file that the filehandle was attached to was deleted, but that doesn’t
seem to be the case.
Any ideas?
Sincerely,
Daniel Berger
Hi all,
Is there a way, once a file has been opened, to determine whether it’s
been deleted versus moved?
[...]
As is, this program will continue to function if “temp” is moved to,
say, temp1. The filehandle then reads from temp1. But, how do I detect
that the file which the filehandle is attached to no longer exists?
Depending on OS, can you create a hard link to the file so that when
it is renamed (mv) the hard link remains?
Daniel Berger
Hugh
···
On Thu, 1 Aug 2002, Daniel Berger wrote:
In article 200207311505.g6VF5Y6m019232@v55host11.interprise.com,
Daniel Berger wrote:
… this program will continue to function if “temp” is moved to,
say, temp1. The filehandle then reads from temp1. But, how do I
detect that the file which the filehandle is attached to no longer
exists?
Um, but the file does still exist. The thing that no longer exists
is an entry in the directory in which you found the file. But the
filehandle was never attached to that.
Any ideas?
You would have to monitor the directory in which you found the file to
see if it still contains a link to the file you opened.
Regards,
Jeremy Henty