Skip to content

Commit

Permalink
reflink cleanup: use errcheck (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry authored Dec 6, 2023
1 parent 3346a01 commit ace7f45
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/dvc_objects/fs/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ def _cdll(name):
"'clonefile' not supported by the standard library",
)

def errcheck(ret, _func, _args):
if ret:
err = ctypes.get_errno()
msg = os.strerror(err)
raise OSError(err, msg)
return ret

clonefile.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int]
clonefile.restype = ctypes.c_int
clonefile.errcheck = errcheck

return clonefile

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

def reflink(src, dst):
ret = clonefile(
clonefile(
ctypes.c_char_p(os.fsencode(src)),
ctypes.c_char_p(os.fsencode(dst)),
ctypes.c_int(0),
)
if ret:
err = ctypes.get_errno()
msg = os.strerror(err)
raise OSError(err, msg)

elif sys.platform == "linux":
import fcntl # pylint: disable=import-error
Expand Down

0 comments on commit ace7f45

Please sign in to comment.