Skip to content

Commit

Permalink
Merge pull request #8 from antirotor/develop
Browse files Browse the repository at this point in the history
Fixing relative path of windows
  • Loading branch information
antirotor authored Jan 10, 2020
2 parents 7c07113 + bf48395 commit 4b71ac8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 deletions speedcopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def copyfile(src, dst, follow_symlinks=True):
os.symlink(os.readlink(src), dst)
else:
fs_src_type = FilesystemInfo().filesystem(src.encode('utf-8'))
fs_dst_type = FilesystemInfo().filesystem(
os.path.dirname(dst.encode('utf-8')))
dst_dir_path = os.path.normpath(os.path.dirname(dst.encode('utf-8'))) # noqa: E501
fs_dst_type = FilesystemInfo().filesystem(dst_dir_path)
supported_fs = ['CIFS', 'SMB2']
debug(">>> Source FS: {}".format(fs_src_type))
debug(">>> Destination FS: {}".format(fs_dst_type))
Expand Down Expand Up @@ -218,8 +218,8 @@ def copyfile(src, dst, follow_symlinks=True):
ctypes.c_void_p)
copyfile.restype = ctypes.HRESULT

source_file = os.path.normpath(src)
dest_file = os.path.normpath(dst)
source_file = os.path.abspath(os.path.normpath(src))
dest_file = os.path.abspath(os.path.normpath(dst))
if source_file.startswith('\\\\'):
source_file = 'UNC\\' + source_file[2:]
if dest_file.startswith('\\\\'):
Expand Down
23 changes: 21 additions & 2 deletions tests/test_speedcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

speedcopy.SPEEDCOPY_DEBUG = True
_FILE_SIZE = 5 * 1024 * 1024


def setup_function(function):
Expand All @@ -13,18 +14,36 @@ def teadown_function(function):
speedcopy.unpatch_copyfile()


def test_copy(tmpdir):
def test_copy_abs(tmpdir):
src = tmpdir.join("source")
dst = tmpdir.join("destination")
with open(str(src), "wb") as f:
f.write(os.urandom(5 * 1024 * 1024))
f.write(os.urandom(_FILE_SIZE))
f.close()

shutil.copyfile(str(src), str(dst))

assert os.path.isfile(str(dst))


def test_copy_rel(tmpdir):
cwd = os.getcwd()
os.chdir(str(tmpdir))

try:
src = "source"
dst = "destination"
with open(str(src), "wb") as f:
f.write(os.urandom(_FILE_SIZE))
f.close()

shutil.copyfile(str(src), str(dst))

assert os.path.isfile(str(dst))
finally:
os.chdir(cwd)


def test_patch():
assert shutil.copyfile == speedcopy.copyfile

Expand Down

0 comments on commit 4b71ac8

Please sign in to comment.