Question

Sometimes I have to work on code that moves the computer clock forward. In this case some .cpp or .h files get their latest modification date set to the future time.

Later on, when my clock is fixed, and I compile my sources, system rebuilds most of the project because some of the latest modification dates are in the future. Each subsequent recompile has the same problem.

Solution that I know are:

a) Find the file that has the future time and re-save it. This method is not ideal because the project is very big and it takes time even for windows advanced search to find the files that are changed.

b) Delete the whole project and re-check it out from svn.

Does anyone know how I can get around this problem?

Is there perhaps a setting in visual studio that will allow me to tell the compiler to use the archive bit instead of the last modification date to detect source file changes?

Or perhaps there is a recursive modification date reset tool that can be used in this situation?

Was it helpful?

Solution

If this was my problem, I'd look for ways to avoid mucking with the system time. Isolating the code under unit tests, or a virtual machine, or something.

However, because I love PowerShell:

Get-ChildItem -r . | 
    ? { $_.LastWriteTime -gt ([DateTime]::Now) } | 
    Set-ItemProperty -Name "LastWriteTime" -Value ([DateTime]::Now)

OTHER TIPS

I would recommend using a virtual machine where you can mess with the clock to your heart's content and it won't affect your development machine. Two free ones are Virtual PC from Microsoft and VirtualBox from Sun.

I don't know if this works in your situation but how about you don't move your clock forward, but wrap your gettime method (or whatever you're using) and make it return the future time that you need?

Install Unix Utils

touch temp
find . -newer temp -exec touch {} ;
rm temp

Make sure to use the full path when calling find or it will probably use Windows' find.exe instead. This is untested in the Windows shell -- you might need to modify the syntax a bit.

I don't use windows - but surely there is something like awk or grep that you can use to find the "future" timestamped files, and then "touch" them so they have the right time - even a perl script.

1) Use a build system that doesn't use timestamps to detect modifications, like scons

2) Use ccache to speed up your build system that does use timestamps (and rebuild all).

In either case it is using md5sum's to verify that a file has been modified, not timestamps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top