2025-05-30 16:35:54 +02:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class CDatabaseFileSystemManager
|
| | | {
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | private:
|
| | | //--- FolderCreate/FolderClean/FileDelete all shared the same 5-attempt/1s-sleep retry shape,
|
| | | //--- differing only in which op ran and the noun in the log line. One loop, dispatched by an
|
| | | //--- enum rather than a function pointer (MQL5 function pointers cannot bind a built-in call
|
| | | //--- with default parameters with any more certainty than a compile can confirm - not worth the
|
| | | //--- risk for 3 one-line bodies).
|
| | | enum ENUM_FS_RETRY_OP
|
| | | {
|
| | | FS_RETRY_CREATE_DIR,
|
| | | FS_RETRY_CLEAN_DIR,
|
| | | FS_RETRY_DELETE_FILE
|
| | | };
|
| | |
|
| | | bool RetryFileSystemOp(ENUM_FS_RETRY_OP op, string target, string verb, string caller)
|
2025-05-30 16:35:54 +02:00 | | | {
|
| | | int attempts = 0;
|
| | | while(attempts < 5)
|
| | | {
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | bool ok = false;
|
| | | switch(op)
|
2025-05-30 16:35:54 +02:00 | | | {
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | case FS_RETRY_CREATE_DIR:
|
| | | ok = FolderCreate(target, FILE_COMMON);
|
| | | break;
|
| | | case FS_RETRY_CLEAN_DIR:
|
| | | ok = FolderClean(target, FILE_COMMON);
|
| | | break;
|
| | | case FS_RETRY_DELETE_FILE:
|
| | | ok = FileDelete(target, FILE_COMMON);
|
| | | break;
|
2025-05-30 16:35:54 +02:00 | | | }
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | if(ok)
|
| | | return true;
|
| | | Print(caller + ": Retry " + IntegerToString(attempts + 1) + " failed to " + verb + ": " + target);
|
2025-05-30 16:35:54 +02:00 | | | Sleep(1000); // Wait for a second before retrying
|
| | | attempts++;
|
| | | }
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | Print(caller + ": Failed to " + verb + " after retries: " + target);
|
2025-05-30 16:35:54 +02:00 | | | return false;
|
| | | }
|
| | |
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | public:
|
| | | bool CreateDirectory(string folderName)
|
| | | {
|
| | | return RetryFileSystemOp(FS_RETRY_CREATE_DIR, folderName, "create directory", __FUNCTION__);
|
| | | }
|
| | |
|
2025-05-30 16:35:54 +02:00 | | | bool CleanDirectory(string folderName)
|
| | | {
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | return RetryFileSystemOp(FS_RETRY_CLEAN_DIR, folderName, "clean folder", __FUNCTION__);
|
2025-05-30 16:35:54 +02:00 | | | }
|
| | |
|
| | | bool DeleteFile(string fileName)
|
| | | {
|
 refactor(db): dedupe the 5x/1s retry loop in FileSystemManager + VersionManager
CDatabaseFileSystemManager's CreateDirectory/CleanDirectory/DeleteFile had
three identical retry loops differing only in which FolderCreate/FolderClean/
FileDelete ran and the noun in the log line - collapsed into one
RetryFileSystemOp(enum, target, verb, caller) private helper, dispatched by
enum rather than a function pointer (MQL5 function pointers to a built-in
with default params is untested territory, not worth it for 3 one-liners).
CDatabaseVersionManager's ReadStoredDbVersion/UpdateStoredDbVersion had the
same retry shape around FileOpen, differing only in the open flags and the
reading/writing noun - collapsed into OpenVersionFileWithRetry(path, flags,
verb).
CDatabaseConnectionManager::OpenDatabase (the 6th instance the finding named)
is the only retry loop in its file - no in-file duplication to fix there, and
sharing it with the other two would need a cross-class free function bound to
DatabaseOpen/FileOpen as function pointers, an untested construct for a
20-line win. Left as-is.
Every Print() message text verified identical at each call site; public
method signatures unchanged, no external caller needed a rewrite.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 01:25:34 -04:00 | | | return RetryFileSystemOp(FS_RETRY_DELETE_FILE, fileName, "delete file", __FUNCTION__);
|
2025-05-30 16:35:54 +02:00 | | | }
|
| | | };
|
| | | //+------------------------------------------------------------------+
|