mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-25 01:40:57 +00:00
Fall Back When a Replace Is Refused and Sweep Only Old Temporaries
Some mounts refuse to replace an existing file in one rename, and the old remove-then-rename worked there where the atomic path now fails, so rename_file() takes the two-step route when a one-step replace is refused and write_file_atomically() writes in place whenever the rename fails, not only for the Windows sharing case. An instance that gave up waiting for the lock writes unlocked by design, so a peer holding the lock could sweep its in-flight temporary and make its rename fail; only temporaries older than ten minutes are removed now, and the sweep uses the error-code overloads so an entry vanishing between listing and stat cannot throw out of startup. The registry mutex is leaked like the map it guards, so a save during static destruction does not lock a destroyed mutex. The physical printer loader is never called, so its guard is gone, while the two delete paths that do run now hold the lock. The bundle metadata loader is lock-free again, since the zip import reads it from a scratch folder; the guard sits at the two scans that read the user's bundles. Preset::save() builds what it writes before taking the lock, the cache writer reserves its payload, and the retry test tolerates a slow runner.
This commit is contained in:
@@ -67,9 +67,10 @@ TEST_CASE("InstanceLock retries a lock file it could not open once the cool-down
|
||||
ScopedTemporaryDir dir;
|
||||
const std::string path = (dir.path() / "later" / "shared.lock").string();
|
||||
const auto saved_cooldown = InstanceLock::cooldown;
|
||||
InstanceLock::cooldown = 50ms;
|
||||
InstanceLock::cooldown = 300ms;
|
||||
|
||||
bool before_dir, during_cooldown, after_cooldown;
|
||||
const auto started = std::chrono::steady_clock::now();
|
||||
{
|
||||
InstanceLock lock(path, 100ms);
|
||||
before_dir = lock.locked();
|
||||
@@ -79,7 +80,8 @@ TEST_CASE("InstanceLock retries a lock file it could not open once the cool-down
|
||||
InstanceLock lock(path, 100ms);
|
||||
during_cooldown = lock.locked();
|
||||
}
|
||||
std::this_thread::sleep_for(80ms);
|
||||
const bool second_guard_inside_cooldown = std::chrono::steady_clock::now() - started < InstanceLock::cooldown;
|
||||
std::this_thread::sleep_for(400ms);
|
||||
{
|
||||
InstanceLock lock(path, 100ms);
|
||||
after_cooldown = lock.locked();
|
||||
@@ -87,7 +89,10 @@ TEST_CASE("InstanceLock retries a lock file it could not open once the cool-down
|
||||
InstanceLock::cooldown = saved_cooldown;
|
||||
|
||||
REQUIRE_FALSE(before_dir);
|
||||
REQUIRE_FALSE(during_cooldown);
|
||||
// A loaded runner may take longer than the cool-down to get here; then the
|
||||
// second guard legitimately retried, so only assert when the timing held.
|
||||
if (second_guard_inside_cooldown)
|
||||
REQUIRE_FALSE(during_cooldown);
|
||||
REQUIRE(after_cooldown);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user