Skip to content

Fix: robustify file handling and resolve path creation bugs in utils#96

Open
kamilansri wants to merge 1 commit intohumanai-foundation:mainfrom
kamilansri:fix/utils-file-handling-and-paths
Open

Fix: robustify file handling and resolve path creation bugs in utils#96
kamilansri wants to merge 1 commit intohumanai-foundation:mainfrom
kamilansri:fix/utils-file-handling-and-paths

Conversation

@kamilansri
Copy link

Description

This PR addresses several bugs and cleans up the utility functions handling file discovery and result saving for the text detection outputs.

Changes Made

  • Extension Bug Fix: Added the missing dot to the .tiff check in list_files (previously 'tiff'), ensuring TIFF files are correctly identified.
  • Performance & Readability: Converted the long if ext == ... or ext == ... chains into O(1) set lookups (in {'.jpg', '.png', ...}).
  • Path Safety: Refactored manual string concatenation (dirname + "res_" + filename + '.txt') to use os.path.join to prevent path malformations if dirname is passed without a trailing slash.
  • Robust Directory Creation: Replaced os.mkdir with os.makedirs(dirname, exist_ok=True). The previous implementation would crash if the parent directory didn't exist or if a race condition occurred in a multi-threaded environment.

Checklist

  • Tested directory creation with nested, non-existent paths.
  • Code follows project styling conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant