浏览代码

frontend: Change crash sentinel location to separate subdirectory

Putting the crash sentinel in the main "obs-studio" directory carries
the risk of unwanted deletion of files in the same directory, which
usually contains user configuration files like "user.ini" and
"global.ini".

Even though the code will ignore any file that does not start with the
crash sentinel prefix string, the code itself would allow changing the
prefix to "global.ini" and thus inadvertently delete the global
configuration file as well.

To further reduce the risk, this change will put the sentinels in a
separate sub-directory that should only ever contain sentinel files,
all of which can possibly deleted without any data loss for the user.
PatTheMav 1 月之前
父节点
当前提交
e8d4224992
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. 10 4
      frontend/utility/CrashHandler.cpp

+ 10 - 4
frontend/utility/CrashHandler.cpp

@@ -33,8 +33,8 @@ using CrashLogUpdateResult = OBS::CrashHandler::CrashLogUpdateResult;
 
 
 namespace {
 namespace {
 
 
-constexpr std::string_view crashSentinelPath = "obs-studio";
-constexpr std::string_view crashSentinelPrefix = "crash_sentinel_";
+constexpr std::string_view crashSentinelPath = "obs-studio/.sentinel";
+constexpr std::string_view crashSentinelPrefix = "run_";
 constexpr std::string_view crashUploadURL = "https://obsproject.com/logs/upload";
 constexpr std::string_view crashUploadURL = "https://obsproject.com/logs/upload";
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
@@ -190,8 +190,14 @@ void CrashHandler::checkCrashState()
 	std::filesystem::path crashSentinelPath = crashSentinelFile_.parent_path();
 	std::filesystem::path crashSentinelPath = crashSentinelFile_.parent_path();
 
 
 	if (!std::filesystem::exists(crashSentinelPath)) {
 	if (!std::filesystem::exists(crashSentinelPath)) {
-		blog(LOG_ERROR, "Crash sentinel location '%s' does not exist", crashSentinelPath.u8string().c_str());
-		return;
+		try {
+			std::filesystem::create_directory(crashSentinelPath);
+		} catch (const std::filesystem::filesystem_error &error) {
+			blog(LOG_ERROR,
+			     "Crash sentinel location '%s' does not exist and unable to create directory:\n%s.",
+			     crashSentinelPath.u8string().c_str(), error.what());
+			return;
+		}
 	}
 	}
 
 
 	for (const auto &entry : std::filesystem::directory_iterator(crashSentinelPath)) {
 	for (const auto &entry : std::filesystem::directory_iterator(crashSentinelPath)) {