Browse Source

core: do not crash when add_watch() fails

Daniele Bartolini 3 năm trước cách đây
mục cha
commit
c1b572fdab

+ 1 - 0
docs/changelog.rst

@@ -10,6 +10,7 @@ Changelog
 * Fixed file changes not detected sometimes.
 * Fixed file changes not detected sometimes.
 * Fixed Ctrl+C/SIGTERM/SIGINT not being honored when launched with --server.
 * Fixed Ctrl+C/SIGTERM/SIGINT not being honored when launched with --server.
 * Fixed handling of filenames containing some special characters.
 * Fixed handling of filenames containing some special characters.
+* Fixed a crash when a directory was created and deleted immediately after in a project folder.
 
 
 **Runtime**
 **Runtime**
 
 

+ 6 - 2
src/core/filesystem/file_monitor_linux.cpp

@@ -61,7 +61,9 @@ struct FileMonitorImpl
 			| IN_DONT_FOLLOW // Don't dereference pathname if it is a symbolic link.
 			| IN_DONT_FOLLOW // Don't dereference pathname if it is a symbolic link.
 			| IN_ONLYDIR     // Only watch pathname if it is a directory.
 			| IN_ONLYDIR     // Only watch pathname if it is a directory.
 			);
 			);
-		CE_ASSERT(wd != -1, "inotify_add_watch: errno: %d", errno);
+
+		if (wd == -1)
+			return;
 
 
 		TempAllocator512 ta;
 		TempAllocator512 ta;
 		DynamicString str(ta);
 		DynamicString str(ta);
@@ -116,7 +118,9 @@ struct FileMonitorImpl
 		_user_data = user_data;
 		_user_data = user_data;
 
 
 		_fd = inotify_init();
 		_fd = inotify_init();
-		CE_ASSERT(_fd != -1, "inotify_init: errno: %d", errno);
+
+		if (_fd == -1)
+			return;
 
 
 		for (u32 i = 0; i < num; ++i)
 		for (u32 i = 0; i < num; ++i)
 			add_watch(paths[i], recursive);
 			add_watch(paths[i], recursive);

+ 3 - 1
src/core/filesystem/file_monitor_windows.cpp

@@ -82,7 +82,9 @@ struct FileMonitorImpl
 			| FILE_FLAG_OVERLAPPED       // Required by CreateIoCompletionPort
 			| FILE_FLAG_OVERLAPPED       // Required by CreateIoCompletionPort
 			, NULL
 			, NULL
 			);
 			);
-		CE_ASSERT(fh != INVALID_HANDLE_VALUE, "CreateFile: GetLastError: %d", GetLastError());
+
+		if (fh == INVALID_HANDLE_VALUE)
+			return;
 
 
 		// Create new IOCP or return already created one
 		// Create new IOCP or return already created one
 		_iocp = CreateIoCompletionPort(fh, _iocp, _key, 0);
 		_iocp = CreateIoCompletionPort(fh, _iocp, _key, 0);