Lisp HUG Maillist Archive

how to check netwroked file timestamp?

I have written a text editor which, before saving the file, tries to check if 
the file has been edited "underneath" it by an external editor.

The code I originally wrote, failed reliably when the file being edited was on 
a "network drive" (running on Windows, accessing a file on some server).

And I'm wondering if anybody knows how to do this "correctly".

I used a state variable that contained the last write time of the file.  And I 
updated this variable with 

(defun file-save (...)
  (with-open-file (...)
    (write-string ...))
  (setf last-saved (get-universal-time)))

It appears that this results in a race condition - the (get-universal-time) on 
the local machine results in a time which is always earlier than the actual 
write-date of the networked file (i.e. the with-open-file appears to be 
asynchronous and returns before the server has actually closed the file and 
written the time stamp).

I changed (get-universal-time) to (file-write-date ...) and it works "better", 
but, I can see that this leaves a tiny hole in the timing during which an 
external write could sneak in and defeat my logic.

Is there a "better" call that I should be making - or, do most text editors 
simply ignore the tiny timing hole?

thanx
pt


Re: how to check netwroked file timestamp?

Unable to parse email body. Email id is 6436

Re: how to check netwroked file timestamp?


On 28 Feb 2007, at 16:45, Paul Tarvydas wrote:

> Is there a "better" call that I should be making - or, do most text  
> editors
> simply ignore the tiny timing hole?

I think that applications that care would use locking of some kind to  
make sure that they own the file when they think they do.  I think  
that's the only really reliable way to make this work.

--tim


Updated at: 2020-12-10 08:46 UTC