1

I have a very simple build script that's behaving in an unexpected way (for me) on Linux.

Part of the script simply checks that the files generated by a build stage hasn't been manually replaced with a stale file.

# load the cache from a json file
if os.path.getmtime(some_path) < cache['timestamp']:
  print("build must run because %s is stale" % some_path)
  run_build = true

...

if run_build:
  cache['timestamp'] = time.time()
  # use subprocess to run process that modifies some_path
  # store updated cache to json file

Unfortunately, this naive logic isn't working on Linux (Ubuntu 16.04): the timestamp stored in the cache is often a few miliseconds ahead of the modification time on the generated files.

I could probably just round down the cached timestamp, but that just feels like a nasty hack, and I wonder if there's better way to get consistent times here.

  • @IsmailBadawi My current logic just has to manage a single timestamp, which is like because it's simple. Having to track separate timestamps for every involved file is extra complexity I do not necessarily need. –  Dec 27 '17 at 21:29
  • 1
    touch a file, use its timestamp? That's basically how 'make' works. – Max Dec 27 '17 at 21:31
  • @MarkPlotnick Right now, neither. –  Dec 27 '17 at 22:21
  • As a side note, checking the modification time of a file isn't sufficient to find out if it's been modified. Moving or renaming a file doesn't change its modification time, so if you delete the original file and then move/rename a different file to that location, it won't trigger your build script. – Aran-Fey Dec 27 '17 at 22:48
  • @Rawing I think you are misinterpreting what that part of the script does, this is about detecting old files replacing new ones, not the other way around. I mean, it's technically possible to manually replace an output file with a random file that was created after the script last ran, but that's a not a scenario that should be possible without really looking for trouble. –  Dec 27 '17 at 23:54
  • If ext4, the lag in modification times may be related to this: https://stackoverflow.com/questions/14392975/timestamp-accuracy-on-ext4-sub-millsecond – Mark Plotnick Dec 28 '17 at 00:16

0 Answers0