Skip to content

Commit 89cf68b

Browse files
committed
Catch IOError exceptions when trying to apply patches
- Legacy-Id: 14677
1 parent cdc295b commit 89cf68b

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

ietf/checks.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -359,27 +359,36 @@ def maybe_patch_library(app_configs, **kwargs):
359359
django_path = os.path.dirname(django.__file__)
360360
library_path = os.path.dirname(django_path)
361361
saved_cwd = os.getcwd()
362-
os.chdir(library_path)
363362
# All patches in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY must have a
364363
# relative file path rooted in the django dir, for instance
365364
# 'django/db/models/fields/__init__.py'
366365
for patch_file in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY:
367-
patch_path = os.path.join(saved_cwd, patch_file)
368-
patch_set = patch.fromfile(patch_path)
369-
if patch_set:
370-
if not patch_set.apply():
366+
try:
367+
patch_path = os.path.join(saved_cwd, patch_file)
368+
patch_set = patch.fromfile(patch_path)
369+
if patch_set:
370+
os.chdir(library_path)
371+
if not patch_set.apply():
372+
errors.append(checks.Warning(
373+
"Could not apply patch from file '%s'"%patch_file,
374+
hint="Make sure that the patch file contains a unified diff and has valid file paths",
375+
id="datatracker.W0002",
376+
))
377+
os.chdir(saved_cwd)
378+
else:
371379
errors.append(checks.Warning(
372-
"Could not apply patch from file '%s'"%patch_file,
373-
hint="Make sure that the patch file contains a unified diff and has valid file paths",
374-
id="datatracker.W0002",
380+
"Could not parse patch file '%s'"%patch_file,
381+
hint="Make sure that the patch file contains a unified diff",
382+
id="datatracker.W0001",
375383
))
376-
else:
377-
errors.append(checks.Warning(
378-
"Could not parse patch file '%s'"%patch_file,
379-
hint="Make sure that the patch file contains a unified diff",
380-
id="datatracker.W0001",
381-
))
382-
os.chdir(saved_cwd)
384+
except IOError as e:
385+
errors.append(
386+
checks.Warning("Could not apply patch from %s: %s" % (patch_file, e),
387+
hint="Check file permissions and locations",
388+
id="datatracker.W0003",
389+
)
390+
)
391+
pass
383392
return errors
384393

385394
@checks.register('security')

0 commit comments

Comments
 (0)