mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
Merge pull request #7 from TerrorJack/master
Download to tmp file then move to dst.
This commit is contained in:
commit
fdd66bf953
11
stackage.py
11
stackage.py
@ -6,6 +6,7 @@
|
||||
import os
|
||||
import pathlib
|
||||
import requests
|
||||
import shutil
|
||||
import subprocess
|
||||
import yaml
|
||||
|
||||
@ -23,15 +24,13 @@ class StackageSession(object):
|
||||
print('{} exists, skipping'.format(file_path), flush=True)
|
||||
else:
|
||||
args = [
|
||||
'aria2c', url, '--dir={}'.format(dir_path),
|
||||
'--file-allocation=none', '--quiet=true',
|
||||
'aria2c', url, '--dir={}'.format(dir_path), '--out={}.tmp'.format(url.split('/')[-1]),
|
||||
'--file-allocation=none', '--quiet=true'
|
||||
]
|
||||
if sha1:
|
||||
args.append('--checksum=sha-1={}'.format(sha1))
|
||||
if subprocess.run(args).returncode != 0 and file_path.is_file():
|
||||
file_path.unlink()
|
||||
raise OSError('Download failed for {}'.format(url))
|
||||
else:
|
||||
subprocess.run(args, check=True)
|
||||
shutil.move('{}.tmp'.format(file_path), file_path)
|
||||
print('Downloaded {} to {}'.format(url, file_path), flush=True)
|
||||
|
||||
def load_stack_setup(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user