-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fix crash when tessdata directory doesn't exist #4465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -146,14 +146,24 @@ static void ExtractFontName(const char* filename, std::string* fontname) { | |||||||||||
*/ | ||||||||||||
static void addAvailableLanguages(const std::string &datadir, | ||||||||||||
std::vector<std::string> *langs) { | ||||||||||||
for (const auto& entry : | ||||||||||||
std::filesystem::recursive_directory_iterator(datadir, | ||||||||||||
std::filesystem::directory_options::follow_directory_symlink | | ||||||||||||
std::filesystem::directory_options::skip_permission_denied)) { | ||||||||||||
auto path = entry.path().lexically_relative(datadir); | ||||||||||||
if (path.extension() == ".traineddata") { | ||||||||||||
langs->push_back(path.replace_extension("").string()); | ||||||||||||
// Check if directory exists before attempting to iterate | ||||||||||||
if (!std::filesystem::exists(datadir) || !std::filesystem::is_directory(datadir)) { | ||||||||||||
return; | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
// Check if directory exists before attempting to iterate | |
if (!std::filesystem::exists(datadir) || !std::filesystem::is_directory(datadir)) { | |
return; | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done Removed the existence check as suggested. The code now uses only the try-catch approach to handle filesystem errors, which is cleaner and still prevents the crash
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Permission denied" was already silently handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code block is not needed. The iteration will raise an exception for both bases, and this exception is handled.