From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Best way to check file modification time? Date: 17 Nov 2015 11:09:52 GMT Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1447758637 14498 80.91.229.3 (17 Nov 2015 11:10:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Nov 2015 11:10:37 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Nov 17 12:10:37 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zye9T-0000Ll-A4 for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Nov 2015 12:10:19 +0100 Original-Received: from localhost ([::1]:57436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zye9S-0000Dz-PR for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Nov 2015 06:10:18 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Original-X-Trace: individual.net Qzaos6Q0PzSgp1h4k12dHgjzIv4PLkoQDpzlcyr9sF6ckCl8wX Cancel-Lock: sha1:mYWCQFLgz8Y3BiBQN33kO4Y2OPQ= User-Agent: slrn/1.0.1 (Linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:215826 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108112 Archived-At: Hi all, I'm dealing with files that I do not visit directly, instead I read their contents into a temp buffer and parse them. At a later point, I write the new contents into a temp buffer and save them to the original file, overwriting the previous version. I would like to check whether the original file may have been overwritten by some other process (possibly by Emacs itself if the user visits the same file in a buffer, but also by external programs). Right now, I'm essentially doing the following: ``` (setq my-file-modtime (nth 5 (file-attributes my-file))) (my-parse-function file) ``` where `my-parse-function' reads the contents of FILE into a temp buffer and does the parsing. IOW, there is a function call between saving the mod time and reading the file. Saving is basically the same: the mod time of the file on disk is read again and checked against the saved mod time, then if that checks out, a function is called that creates the temp buffer, writes out the information and saves the file. Now, it seems to me that there may be too much time between checking the mod time and reading/saving the file, such that it is in principle possible that the relevant file gets overwritten at just the wrong moment. I can easily move the mod time checking to a position in the code that's closer to the actual reading or saving of the file, but I suspect that only reduces the problem, it doesn't eliminate it altogether. So I'm wondering if there's a Right Way™ to do this. If not, any advice on how to reduce the risks as much as possible would be great! TIA -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9)