Skip to content

Commit

Permalink
Use errno.EISDIR and errno.EACCESS instead of hardcoding values (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
dktrkranz authored Feb 19, 2024
1 parent 85a4557 commit 9f22835
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 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 @@ -376,8 +377,8 @@ def do_write(outfile):
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}:
# the code we get on OS X and Linux (EISDIR), 13 is what we get on Windows (EACCES).
if e.errno in (EISDIR, EACCES):
p = str(outfile)
dirname, basename = op.split(p)
otherfiles = os.listdir(dirname)
Expand Down
7 changes: 3 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,8 @@ 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
# It's a directory, code is 21 on OS X / Linux (EISDIR) and 13 on Windows (EACCES)
if e.errno in (EISDIR, EACCES):
_smart_move_or_copy(shutil.copytree, source_path, dest_path)
else:
raise

0 comments on commit 9f22835

Please sign in to comment.