Bläddra i källkod

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.
tobspr 9 år sedan
förälder
incheckning
1795a7c8dd
1 ändrade filer med 10 tillägg och 2 borttagningar
  1. 10 2
      panda/src/express/virtualFileMountRamdisk.cxx

+ 10 - 2
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);