Skip to content

Commit ace7f45

Browse files
authored
reflink cleanup: use errcheck (#239)
1 parent 3346a01 commit ace7f45

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/dvc_objects/fs/system.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ def _cdll(name):
5959
"'clonefile' not supported by the standard library",
6060
)
6161

62+
def errcheck(ret, _func, _args):
63+
if ret:
64+
err = ctypes.get_errno()
65+
msg = os.strerror(err)
66+
raise OSError(err, msg)
67+
return ret
68+
6269
clonefile.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int]
6370
clonefile.restype = ctypes.c_int
71+
clonefile.errcheck = errcheck
6472

6573
return clonefile
6674

@@ -71,15 +79,11 @@ def _cdll(name):
7179
clonefile = _clonefile()
7280

7381
def reflink(src, dst):
74-
ret = clonefile(
82+
clonefile(
7583
ctypes.c_char_p(os.fsencode(src)),
7684
ctypes.c_char_p(os.fsencode(dst)),
7785
ctypes.c_int(0),
7886
)
79-
if ret:
80-
err = ctypes.get_errno()
81-
msg = os.strerror(err)
82-
raise OSError(err, msg)
8387

8488
elif sys.platform == "linux":
8589
import fcntl # pylint: disable=import-error

0 commit comments

Comments
 (0)