Skip to content

Commit ac9e5a9

Browse files
committed
Don't delete the instance database file on reset
Deleting the file is unsafe as it could be being written to in a different process and cause the write to end up in an unlinked file. For example: `cvd reset` could be called concurrently with a `cvd create` invocation. If the reset command deletes the database file while `create` is writing to it, the writes will be lost, but `create` will not find out and continue to start the device, leaving untracked running devices behind. `cvd reset` clears the database which effectively truncates the file to zero size, so it has almost the same effect as deleting it.
1 parent 2907b20 commit ac9e5a9

File tree

1 file changed

+0
-10
lines changed

1 file changed

+0
-10
lines changed

base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,12 @@ Result<void> InstanceManager::Clear() {
296296

297297
Result<void> InstanceManager::Reset() {
298298
CF_EXPECT(Clear());
299-
auto instance_db_deleted = RemoveFile(InstanceDatabasePath());
300-
if (!instance_db_deleted) {
301-
LOG(ERROR) << "Error deleting instance database file";
302-
}
303-
304299
CF_EXPECT(KillAllCuttlefishInstances(false));
305300
return {};
306301
}
307302

308303
Result<void> InstanceManager::ResetAndClearInstanceDirs() {
309304
CF_EXPECT(Clear());
310-
auto instance_db_deleted = RemoveFile(InstanceDatabasePath());
311-
if (!instance_db_deleted) {
312-
LOG(ERROR) << "Error deleting instance database file";
313-
}
314-
315305
CF_EXPECT(KillAllCuttlefishInstances(true));
316306
return {};
317307
}

0 commit comments

Comments
 (0)