Browse Source

Delay LocalFileSystem.hx watchCallback by FileConverter time precision to prevent corrupted converted files.

clementlandrin 9 months ago
parent
commit
b541d043df
1 changed files with 10 additions and 0 deletions
  1. 10 0
      hxd/fs/LocalFileSystem.hx

+ 10 - 0
hxd/fs/LocalFileSystem.hx

@@ -117,6 +117,7 @@ class LocalEntry extends FileEntry {
 	var onChangedDelay : haxe.Timer;
 	#else
 	var watchTime : Float;
+	var lastCheck : { fileTime : Float, stampTime : Float };
 	#end
 
 	static var WATCH_INDEX = 0;
@@ -176,6 +177,14 @@ class LocalEntry extends FileEntry {
 		}
 		#end
 
+		var stampTime = haxe.Timer.stamp();
+		if ( w.lastCheck == null || w.lastCheck.fileTime != t ) {
+			w.lastCheck = { fileTime : t, stampTime : stampTime };
+			return;
+		}
+		if ( stampTime < w.lastCheck.stampTime + FileConverter.FILE_TIME_PRECISION * 0.001 )
+			return;
+
 		w.watchTime = t;
 		w.watchCallback();
 	}
@@ -259,6 +268,7 @@ class LocalEntry extends FileEntry {
 				hide.Ide.inst.quickMessage('Failed convert for ${name}, trying again');
 				// Convert failed, let's mark this watch as not performed.
 				watchTime = -1;
+				lastCheck = null;
 				return;
 			}
 			#else