[cmake-developers] "Cannot restore timestamp" error due to Sharing Violation during Rename on Windows

Brad King brad.king at kitware.com
Mon May 12 11:44:55 EDT 2014


On 05/12/2014 11:23 AM, Eric Berge wrote:
> My first question is whether the cmake code was expecting to
> avoid this type of race by other means or it was just expecting
> that the last one would succeed.

The goal is to write a file atomically because multiple processes
might be trying to do so at once.  We do not care which one wins.

The standard approach in the POSIX world is to write to a temporary
file name and then rename atomically once at the end.  This seems
virtually impossible to achieve on Windows.  The code is here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmSystemTools.cxx;hb=v3.0.0-rc4#l904

We already have a retry loop.  I recently added an undocumented
way to configure it:

 Windows: Make file delete/rename retry configurable
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7b1f966a

I cannot imagine every application that wants to create a file
atomically on Windows has to go through this.  Any idea how to
do it better?  Is inter-process synchronization (e.g. locking)
really needed just to create a file reliably?

-Brad




More information about the cmake-developers mailing list