This repository was archived by the owner on Jul 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,28 @@ cpp::result<void, std::string> FileFsRepository::StoreFile(
1818 }
1919
2020 cortex::db::File db;
21- auto file_full_path = file_container_path / file_metadata.filename ;
22- if (std::filesystem::exists (file_full_path)) {
23- return cpp::fail (" File already exists: " + file_full_path.string ());
21+ auto original_filename = file_metadata.filename ;
22+ auto file_full_path = file_container_path / original_filename;
23+
24+ // Handle duplicate filenames
25+ int counter = 1 ;
26+ while (std::filesystem::exists (file_full_path)) {
27+ auto dot_pos = original_filename.find_last_of (' .' );
28+ std::string name_part;
29+ std::string ext_part;
30+
31+ if (dot_pos != std::string::npos) {
32+ name_part = original_filename.substr (0 , dot_pos);
33+ ext_part = original_filename.substr (dot_pos);
34+ } else {
35+ name_part = original_filename;
36+ ext_part = " " ;
37+ }
38+
39+ auto new_filename = name_part + " _" + std::to_string (counter) + ext_part;
40+ file_full_path = file_container_path / new_filename;
41+ file_metadata.filename = new_filename;
42+ counter++;
2443 }
2544
2645 try {
You can’t perform that action at this time.
0 commit comments