1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-03-11 19:21:39 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Stanislav
e4219fada2 Merge cd70c99c67 into 9f22835f73 2024-02-19 10:20:09 -07:00
Luca Falavigna
9f22835f73 Use errno.EISDIR and errno.EACCESS instead of hardcoding values (#1196) 2024-02-19 09:38:24 -06:00
2 changed files with 6 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ import logging
import re import re
import os import os
import os.path as op import os.path as op
from errno import EISDIR, EACCES
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
from hscommon.jobprogress.job import nulljob from hscommon.jobprogress.job import nulljob
@@ -376,8 +377,8 @@ class Results(Markable):
do_write(outfile) do_write(outfile)
except OSError as e: except OSError as e:
# If our OSError is because dest is already a directory, we want to handle that. 21 is # 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. # the code we get on OS X and Linux (EISDIR), 13 is what we get on Windows (EACCES).
if e.errno in {21, 13}: if e.errno in (EISDIR, EACCES):
p = str(outfile) p = str(outfile)
dirname, basename = op.split(p) dirname, basename = op.split(p)
otherfiles = os.listdir(dirname) otherfiles = os.listdir(dirname)

View File

@@ -14,6 +14,7 @@ import re
import os import os
import shutil import shutil
from errno import EISDIR, EACCES
from pathlib import Path from pathlib import Path
from typing import Callable, List from typing import Callable, List
@@ -75,10 +76,8 @@ def smart_copy(source_path: Path, dest_path: Path) -> None:
try: try:
_smart_move_or_copy(shutil.copy, source_path, dest_path) _smart_move_or_copy(shutil.copy, source_path, dest_path)
except OSError as e: except OSError as e:
if e.errno in { # It's a directory, code is 21 on OS X / Linux (EISDIR) and 13 on Windows (EACCES)
21, if e.errno in (EISDIR, EACCES):
13,
}: # it's a directory, code is 21 on OS X / Linux and 13 on Windows
_smart_move_or_copy(shutil.copytree, source_path, dest_path) _smart_move_or_copy(shutil.copytree, source_path, dest_path)
else: else:
raise raise