MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ddio_DeleteLockFile

Function ddio_DeleteLockFile

ddio/file.cpp:105–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105bool ddio_DeleteLockFile(const std::filesystem::path& dir) {
106 int32_t curr_pid = ddio_GetPID();
107
108 std::filesystem::path lock_filename = dir / ".lock";
109 if (!std::filesystem::exists(lock_filename)) {
110 return true;
111 }
112
113 LockFileContent lock_content;
114 try {
115 std::ifstream lockfile(lock_filename, std::ios::binary);
116 lockfile >> lock_content;
117 lockfile.close();
118 } catch (std::exception &e) {
119 return false;
120 }
121
122 if (lock_content.tag != LOCK_TAG) {
123 return false;
124 }
125
126 ASSERT(lock_content.pid != -1);
127
128 // check the file id in the file, compared to our pid
129 if (lock_content.pid != curr_pid) {
130 // it doesn't belong to
131 return false;
132 }
133
134 std::error_code ec;
135 // the lock file in the directory belongs to us!
136 if (!std::filesystem::remove(lock_filename, ec)) {
137 return false;
138 }
139
140 return true;
141}

Callers 1

Descent3Function · 0.85

Calls 1

ddio_GetPIDFunction · 0.70

Tested by

no test coverage detected