From 1795a7c8dd86c70e485ff0eefc93f502ca8f7786 Mon Sep 17 00:00:00 2001 From: tobspr Date: Sat, 20 Feb 2016 19:55:49 +0100 Subject: [PATCH] Work arround timestamp precision in ramdisks This fixes the timestamp precision when mounting RamDisks, by ensuring that the modified timestamp is always greater than the original timestamp. --- panda/src/express/virtualFileMountRamdisk.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/panda/src/express/virtualFileMountRamdisk.cxx b/panda/src/express/virtualFileMountRamdisk.cxx index 9f10931985..244f5c79df 100644 --- a/panda/src/express/virtualFileMountRamdisk.cxx +++ b/panda/src/express/virtualFileMountRamdisk.cxx @@ -235,7 +235,13 @@ open_write_file(const Filename &file, bool truncate) { if (truncate) { // Reset to an empty string. f->_data.str(string()); - f->_timestamp = time(NULL); + + // Instead of setting the time, we ensure that we always store a newer time. + // This is a workarround for the case that a file is written twice per + // second, since the timer only has a one second precision. The proper + // solution to fix this would be to switch to a higher precision + // timer everywhere. + f->_timestamp = max(f->_timestamp + 1, time(NULL)); } return new OSubStream(&f->_wrapper, 0, 0); @@ -275,7 +281,9 @@ open_read_write_file(const Filename &file, bool truncate) { if (truncate) { // Reset to an empty string. f->_data.str(string()); - f->_timestamp = time(NULL); + + // See open_write_file + f->_timestamp = max(f->_timestamp + 1, time(NULL)); } return new SubStream(&f->_wrapper, 0, 0);