Skip to content
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

Use errno.EISDIR and errno.EACCESS instead of hardcoding values #1196

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import os
import os.path as op
from errno import EISDIR, EACCES
from xml.etree import ElementTree as ET

from hscommon.jobprogress.job import nulljob
Expand Down Expand Up @@ -375,9 +376,8 @@ def do_write(outfile):
try:
do_write(outfile)
except OSError as e:
# If our OSError is because dest is already a directory, we want to handle that. 21 is
# the code we get on OS X and Linux, 13 is what we get on Windows.
if e.errno in {21, 13}:
# If our OSError is because dest is already a directory, we want to handle that.
if e.errno in (EISDIR, EACCES):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think maybe leaving the note about how different errors here are due to the different OSes would be helpful in the future. Same in the other file as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments refactored as per suggestion

p = str(outfile)
dirname, basename = op.split(p)
otherfiles = os.listdir(dirname)
Expand Down
6 changes: 2 additions & 4 deletions hscommon/conflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import shutil

from errno import EISDIR, EACCES
from pathlib import Path
from typing import Callable, List

Expand Down Expand Up @@ -75,10 +76,7 @@ def smart_copy(source_path: Path, dest_path: Path) -> None:
try:
_smart_move_or_copy(shutil.copy, source_path, dest_path)
except OSError as e:
if e.errno in {
21,
13,
}: # it's a directory, code is 21 on OS X / Linux and 13 on Windows
if e.errno in (EISDIR, EACCES): # it's a directory
_smart_move_or_copy(shutil.copytree, source_path, dest_path)
else:
raise
Loading