| 1309 | } |
| 1310 | |
| 1311 | bool SetFileTimestamp(uint32_t accountId, uint32_t appId, const std::string& filename, uint64_t unixSeconds) { |
| 1312 | if (unixSeconds == 0) return false; |
| 1313 | std::lock_guard<std::shared_mutex> lock(g_mutex); |
| 1314 | |
| 1315 | std::string appRoot = GetAppPathInternal(accountId, appId); |
| 1316 | std::string fullPath = ValidateFilename(appRoot, filename); |
| 1317 | if (fullPath.empty()) { |
| 1318 | LOG("SetFileTimestamp BLOCKED: path traversal in filename '%s'", filename.c_str()); |
| 1319 | return false; |
| 1320 | } |
| 1321 | |
| 1322 | auto fileTime = UnixSecondsToFileTime(unixSeconds); |
| 1323 | |
| 1324 | std::error_code ec; |
| 1325 | std::filesystem::last_write_time(FileUtil::Utf8ToPath(fullPath), fileTime, ec); |
| 1326 | if (ec) { |
| 1327 | LOG("SetFileTimestamp: failed for %s: %s", filename.c_str(), ec.message().c_str()); |
| 1328 | return false; |
| 1329 | } |
| 1330 | LOG("SetFileTimestamp: %s -> %llu", filename.c_str(), unixSeconds); |
| 1331 | return true; |
| 1332 | } |
| 1333 | |
| 1334 | } // namespace LocalStorage |
no test coverage detected