From 8f8ef8d5d838cf52130076e88a880ed49f1a911c Mon Sep 17 00:00:00 2001 From: Martin Turoci Date: Wed, 11 Jan 2023 13:51:44 +0100 Subject: [PATCH] feat: Make sure local copy works on Windows as well. #982 --- py/h2o_wave/core.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/py/h2o_wave/core.py b/py/h2o_wave/core.py index ae4a1f8a8c..7724e86cdc 100644 --- a/py/h2o_wave/core.py +++ b/py/h2o_wave/core.py @@ -17,6 +17,7 @@ import json import platform import secrets +import shutil import subprocess from urllib.parse import urlparse from uuid import uuid4 @@ -684,11 +685,13 @@ def upload(self, files: List[str]) -> List[str]: dst = os.path.join(_waved_dir, _data_dir, 'f', uuid) os.makedirs(dst, exist_ok=True) - args = [cp_command, f, dst] - if is_windows: - args.append('/K/O/X') + if is_windows and shutil.which('robocopy'): + src = os.path.dirname(f) or os.getcwd() + args = ['robocopy', src, dst, os.path.basename(f), '/J/W:0'] + else: + args = [cp_command, f, dst] - _, err = subprocess.Popen(args, stderr=subprocess.PIPE).communicate() + _, err = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.DEVNULL).communicate() if err: raise ValueError(err.decode()) uploaded_files.append(f'{_base_url}_f/{uuid}/{os.path.basename(f)}') @@ -966,11 +969,13 @@ async def upload(self, files: List[str]) -> List[str]: dst = os.path.join(_waved_dir, _data_dir, 'f', uuid) os.makedirs(dst, exist_ok=True) - args = [cp_command, f, dst] - if is_windows: - args.append('/K/O/X') + if is_windows and shutil.which('robocopy'): + src = os.path.dirname(f) or os.getcwd() + args = ['robocopy', src, dst, os.path.basename(f), '/J/W:0'] + else: + args = [cp_command, f, dst] - _, err = subprocess.Popen(args, stderr=subprocess.PIPE).communicate() + _, err = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.DEVNULL).communicate() if err: raise ValueError(err.decode()) uploaded_files.append(f'{_base_url}_f/{uuid}/{os.path.basename(f)}')