Downloading using a tempory filename is safer. The tempory filename provide enouth information to show who (megapy) when and what is downloaded

This commit is contained in:
gissehel 2013-04-19 20:10:52 +02:00
parent 09c4b14c97
commit 89a40306a2

View file

@ -7,6 +7,8 @@ import os
import random import random
import binascii import binascii
import requests import requests
import time
import shutil
from .errors import ValidationError, RequestError from .errors import ValidationError, RequestError
from .crypto import * from .crypto import *
@ -401,6 +403,7 @@ class Mega(object):
attribs = base64_url_decode(file_data['at']) attribs = base64_url_decode(file_data['at'])
attribs = decrypt_attr(attribs, k) attribs = decrypt_attr(attribs, k)
file_name = attribs['n'] file_name = attribs['n']
file_name_tmp = '.megapy-%s-%s' % (int(time.time()*1000), filename)
# print("downloading {0} (size: {1}), url = {2}".format(attribs['n'].encode("utf8"), # print("downloading {0} (size: {1}), url = {2}".format(attribs['n'].encode("utf8"),
# file_size, # file_size,
@ -411,7 +414,7 @@ class Mega(object):
if dest_path: if dest_path:
output_file = open(dest_path + '/' + file_name, 'wb') output_file = open(dest_path + '/' + file_name, 'wb')
else: else:
output_file = open(file_name, 'wb') output_file = open(file_name_tmp, 'wb')
counter = Counter.new( counter = Counter.new(
128, initial_value=((iv[0] << 32) + iv[1]) << 64) 128, initial_value=((iv[0] << 32) + iv[1]) << 64)
@ -448,6 +451,8 @@ class Mega(object):
if (file_mac[0] ^ file_mac[1], file_mac[2] ^ file_mac[3]) != meta_mac: if (file_mac[0] ^ file_mac[1], file_mac[2] ^ file_mac[3]) != meta_mac:
raise ValueError('Mismatched mac') raise ValueError('Mismatched mac')
shutil.move(file_name_tmp, file_name)
########################################################################## ##########################################################################
# UPLOAD # UPLOAD
def upload(self, filename, dest=None): def upload(self, filename, dest=None):