puppetlabs/puppet — pull request #2727 by kylog (2014-06-03 05:12:09+00:00)
Title: (PUP-2710) For audit only, compare Time objects as strings

Previously, auditing the mtime or ctime properties of a file
on ext4 (or any nanosecond resolution filesystem) when running
under ruby 1.9+ would spuriously report a change on every catalog
run.

This was because the yaml library (or libraries, more on that
shortly) correctly serialize the nanosecond resolution of the Time
object to yaml, *but* on deserialization they produce a Time object
truncated to microseconds. This led to a false inequality operation
leading to the spurious audit messages.

This patch is an unfortunate hack consisting of special-casing
the comparison of Time objects in the audit equality operation.

For context, I also considered alternatives:
* Monkey-patching the Time object == method to ignore nanoseconds.
But this would affect all Time objects and could have undesired
consequences.
* Monkey-patching the yaml library to correctly deserialize. But
this got messy because there are several different yaml libraries
that may be involved.
* Intercepting the serialization in Puppet::Util::Yaml, but this
would mean discarding nanoseconds for all serialization of Time
objects to yaml.

In the end, this spot fix seemed like the least evil solution.