fix issue with file transfer

pull/342/head
vapao 2021-06-18 23:49:37 +08:00
parent 78928841d3
commit 889ebccb59
1 changed files with 8 additions and 7 deletions

View File

@ -96,7 +96,7 @@ def _ext2_deploy(req, helper, env):
if action.get('type') == 'transfer': if action.get('type') == 'transfer':
if action.get('src_mode') == '1': if action.get('src_mode') == '1':
break break
helper.send_info('local', f'{human_time()} 检测到来源为本地路径的数据传输动作,执行打包... ') helper.send_info('local', f'{human_time()} 检测到来源为本地路径的数据传输动作,执行打包... \r\n')
action['src'] = action['src'].rstrip('/ ') action['src'] = action['src'].rstrip('/ ')
action['dst'] = action['dst'].rstrip('/ ') action['dst'] = action['dst'].rstrip('/ ')
if not action['src'] or not action['dst']: if not action['src'] or not action['dst']:
@ -117,9 +117,9 @@ def _ext2_deploy(req, helper, env):
else: else:
excludes.append(f'--exclude={x}') excludes.append(f'--exclude={x}')
exclude = ' '.join(excludes) exclude = ' '.join(excludes)
tar_gz_file = f'{env.spug_version}.tar.gz' tar_gz_file = f'{req.spug_version}.tar.gz'
helper.local(f'cd {sp_dir} && tar zcf {tar_gz_file} {exclude} {contain}') helper.local(f'tar -C {sp_dir} -zcf {tar_gz_file} {exclude} {contain}')
helper.send_info('local', '完成\r\n') helper.send_info('local', f'{human_time()} 打包完成\r\n')
tmp_transfer_file = os.path.join(sp_dir, tar_gz_file) tmp_transfer_file = os.path.join(sp_dir, tar_gz_file)
break break
if host_actions: if host_actions:
@ -211,14 +211,15 @@ def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
continue continue
else: else:
sp_dir, sd_dst = os.path.split(action['src']) sp_dir, sd_dst = os.path.split(action['src'])
tar_gz_file = f'{env.SPUG_VERSION}.tar.gz' tar_gz_file = f'{spug_version}.tar.gz'
try: try:
ssh.put_file(os.path.join(sp_dir, tar_gz_file), f'/tmp/{tar_gz_file}') ssh.put_file(os.path.join(sp_dir, tar_gz_file), f'/tmp/{tar_gz_file}')
except Exception as e: except Exception as e:
helper.send_error(host.id, f'exception: {e}') helper.send_error(host.id, f'exception: {e}')
command = f'cd /tmp && tar xf {tar_gz_file} && rm -f {tar_gz_file} ' command = f'mkdir -p /tmp/{spug_version} && tar xf /tmp/{tar_gz_file} -C /tmp/{spug_version}/ '
command += f'&& rm -rf {action["dst"]} && mv /tmp/{sd_dst} {action["dst"]} && echo "transfer completed"' command += f'&& rm -rf {action["dst"]} && mv /tmp/{spug_version}/{sd_dst} {action["dst"]} '
command += f'&& rm -rf /tmp/{spug_version}* && echo "transfer completed"'
else: else:
command = f'cd /tmp ; {action["data"]}' command = f'cd /tmp ; {action["data"]}'
helper.remote(host.id, ssh, command, env) helper.remote(host.id, ssh, command, env)