Repository: antirotor/speedcopy

Issue:
Copying doesn't work if non-absolute filenames supplied
```
speedcopy.copyfile("C:/Temp/asdf", "C:/Temp/fdsa")
```
should work exactly the same as
```
os.chdir("C:/Temp")
speedcopy.copyfile("asdf", "fdsa")
```


Discussion:

Patch:
diff --git a/speedcopy/__init__.py b/speedcopy/__init__.py
index c7b2c99..e681fd7 100644
--- a/speedcopy/__init__.py
+++ b/speedcopy/__init__.py
@@ -144,8 +144,8 @@ if not sys.platform.startswith("win32"):
             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))
@@ -218,8 +218,8 @@ else:
                                  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('\\\\'):


Test patch:
diff --git a/tests/test_speedcopy.py b/tests/test_speedcopy.py
index bea8ba4..ec69756 100644
--- a/tests/test_speedcopy.py
+++ b/tests/test_speedcopy.py
@@ -3,6 +3,7 @@ import speedcopy
 import os
 
 speedcopy.SPEEDCOPY_DEBUG = True
+_FILE_SIZE = 5 * 1024 * 1024
 
 
 def setup_function(function):
@@ -13,11 +14,11 @@ 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))
@@ -25,6 +26,24 @@ def test_copy(tmpdir):
     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