Skip to content

Commit

Permalink
Fix file not found exception (gcovr#1000)
Browse files Browse the repository at this point in the history
* Do not fail on missing files
* Add check for same file
  - If we check if the current working directory is accessible in upper and
    lower case we also check if they are pointing to the same file.
  • Loading branch information
Spacetown authored Oct 15, 2024
1 parent 4cff3ee commit 5fe42c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ New features and notable changes:

Bug fixes and small improvements:

- Fixed an error handling bug throwing a `TypeError` exception on a gcov merge assertion failure
- Fixed an error handling bug throwing a ``TypeError`` exception on a gcov merge assertion failure
instead of reporting the error and (if requested by the user) continuing execution. (:issue:`997`)
- Check format version of external generated ``gcov`` JSON files. (:issue:`999`)
- Fix crash on Windows when trying to fix the case of the files. (:issue:`1000`)

Documentation:

Expand Down
25 changes: 15 additions & 10 deletions gcovr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ def already_visited(self, path):
def is_fs_case_insensitive():
cwd = os.getcwd()
# Guessing if file system is case insensitive.
# The working directory is not the root and accessible in upper and lower case.
# The working directory is not the root and accessible in upper and lower case
# and pointing to same file.
ret = (
(cwd != os.path.sep)
and os.path.exists(cwd.upper())
and os.path.exists(cwd.lower())
and os.path.samefile(cwd.upper(), cwd.lower())
)
LOGGER.debug(f"File system is case {'in' if ret else ''}sensitive.")

Expand All @@ -79,15 +81,18 @@ def fix_case_of_path(path: str):
if not cur: # e.g path = "C:/"
return rest.upper() # Always use uppercase drive letter

curL = cur.lower()
matchedFileName = [f for f in os.listdir(rest) if f.lower() == curL]
if len(matchedFileName) > 1:
raise RuntimeError(
"Seems that we have a case sensitive filesystem, can't fix file case"
)

if len(matchedFileName) == 1:
path = os.path.join(fix_case_of_path(rest), matchedFileName[0])
try:
curL = cur.lower()
matchedFileName = [f for f in os.listdir(rest) if f.lower() == curL]
if len(matchedFileName) > 1:
raise RuntimeError(
"Seems that we have a case sensitive filesystem, can't fix file case"
)

if len(matchedFileName) == 1:
path = os.path.join(fix_case_of_path(rest), matchedFileName[0])
except FileNotFoundError:
LOGGER.warning(f"Can not fix case of path because {rest} not found.")

return path.replace("\\", "/")

Expand Down

0 comments on commit 5fe42c0

Please sign in to comment.