mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 15:28:28 +01:00
dvc: avoid using pyreflink module
Fixes #1149 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import platform
|
||||
from cffi import FFI
|
||||
|
||||
|
||||
WINDOWS_SRC = """
|
||||
int reflink(char *src, char *dst)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
"""
|
||||
|
||||
DARWIN_SRC = """
|
||||
#include <AvailabilityMacros.h>
|
||||
/* NOTE: sys/clonefile.h is available since OS X 10.12 */
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
|
||||
#include <sys/clonefile.h> /* for clonefile(2) */
|
||||
#include <errno.h>
|
||||
int reflink(char *src, char *dst)
|
||||
{
|
||||
return clonefile(src, dst, 0);
|
||||
}
|
||||
#else
|
||||
int reflink(char *src, char *dst)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
"""
|
||||
|
||||
LINUX_SRC = """
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
int reflink(char *src, char *dst)
|
||||
{
|
||||
int ret = -1;
|
||||
#ifdef FICLONE
|
||||
int src_fd = -1;
|
||||
int dst_fd = -1;
|
||||
|
||||
src_fd = open(src, O_RDONLY);
|
||||
if (src_fd < 0)
|
||||
return ret;
|
||||
|
||||
dst_fd = open(dst, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
if (src_fd < 0) {
|
||||
close(src_fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ioctl(dst_fd, FICLONE, src_fd);
|
||||
if (ret != 0)
|
||||
unlink(dst);
|
||||
|
||||
out:
|
||||
if (src_fd >= 0)
|
||||
close(src_fd);
|
||||
if (dst_fd >= 0)
|
||||
close(dst_fd);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
"""
|
||||
|
||||
ffibuilder = FFI()
|
||||
|
||||
ffibuilder.cdef("""
|
||||
int reflink(char *src, char *dst);
|
||||
""")
|
||||
|
||||
system = platform.system()
|
||||
if system == 'Windows':
|
||||
src = WINDOWS_SRC
|
||||
elif system == 'Linux':
|
||||
src = LINUX_SRC
|
||||
elif system == 'Darwin':
|
||||
src = DARWIN_SRC
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
ffibuilder.set_source("reflink", src)
|
||||
|
||||
if __file__ == '__main__':
|
||||
ffibuilder.compile(verbose=True)
|
||||
+9
-2
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import ctypes
|
||||
import reflink
|
||||
|
||||
if os.name == 'nt':
|
||||
import ntfsutils.hardlink as winlink
|
||||
@@ -36,7 +35,15 @@ class System(object):
|
||||
|
||||
@staticmethod
|
||||
def reflink(source, link_name):
|
||||
return reflink.reflink(source, link_name)
|
||||
from dvc.reflink import reflink
|
||||
from dvc.exceptions import DvcException
|
||||
|
||||
ret = reflink(source, link_name)
|
||||
if ret != 0:
|
||||
raise DvcException("Failed to reflink '{}' -> '{}' returned "
|
||||
"non-zero code '{}'".format(source,
|
||||
link_name,
|
||||
ret))
|
||||
|
||||
# FIXME
|
||||
# Temporary fix while waiting for the PR to be merged and released:
|
||||
|
||||
+1
-1
@@ -18,9 +18,9 @@ pyasn1>=0.4.1
|
||||
schema>=0.6.7
|
||||
paramiko>=2.4.1
|
||||
jsonpath-rw==1.4.0
|
||||
reflink==0.2.0
|
||||
requests>=2.18.4
|
||||
wheel>=0.31.1
|
||||
futures>=3.2.0; python_version == "2.7"
|
||||
grandalf==0.6
|
||||
asciicanvas==0.0.3
|
||||
cffi
|
||||
|
||||
Reference in New Issue
Block a user