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