Explorar o código

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 %!s(int64=9) %!d(string=hai) anos
pai
achega
1795a7c8dd
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  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) {
   if (truncate) {
     // Reset to an empty string.
     // Reset to an empty string.
     f->_data.str(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);
   return new OSubStream(&f->_wrapper, 0, 0);
@@ -275,7 +281,9 @@ open_read_write_file(const Filename &file, bool truncate) {
   if (truncate) {
   if (truncate) {
     // Reset to an empty string.
     // Reset to an empty string.
     f->_data.str(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);
   return new SubStream(&f->_wrapper, 0, 0);