Skip to content

Commit de8a64e

Browse files
committed
Merge pull request godotengine#113637 from aaronp64/snapshot_overwrites
Prevent ObjectDB snapshots being overwritten
2 parents e076acf + 520f159 commit de8a64e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

modules/objectdb_profiler/editor/objectdb_profiler_panel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,19 @@ bool ObjectDBProfilerPanel::handle_debug_message(const String &p_message, const
113113

114114
void ObjectDBProfilerPanel::receive_snapshot(int request_id) {
115115
const Vector<uint8_t> &in_data = partial_snapshots[request_id].data;
116-
String snapshot_file_name = Time::get_singleton()->get_datetime_string_from_system(false).replace_char('T', '_').replace_char(':', '-');
117116
Ref<DirAccess> snapshot_dir = _get_and_create_snapshot_storage_dir();
118117
if (snapshot_dir.is_valid()) {
119118
Error err;
119+
String base_snapshot_file_name = Time::get_singleton()->get_datetime_string_from_system(false).replace_char('T', '_').replace_char(':', '-');
120+
String snapshot_file_name = base_snapshot_file_name;
120121
String current_dir = snapshot_dir->get_current_dir();
121122
String joined_dir = current_dir.path_join(snapshot_file_name) + ".odb_snapshot";
122123

124+
for (int i = 2; FileAccess::exists(joined_dir); i++) {
125+
snapshot_file_name = base_snapshot_file_name + '_' + String::chr('0' + i);
126+
joined_dir = current_dir.path_join(snapshot_file_name) + ".odb_snapshot";
127+
}
128+
123129
Ref<FileAccess> file = FileAccess::open(joined_dir, FileAccess::WRITE, &err);
124130
if (err == OK) {
125131
file->store_buffer(in_data);

0 commit comments

Comments
 (0)