def dump_static_file(uploaded_file, filelocation): """ @param uploadedfile: uploaded_file @return: a relationship dict linking the filename with the random filename saved in the disk """ if os.path.exists(filelocation): log.err("Path %s exists and would be overwritten with %d bytes" % (filelocation, uploaded_file['body_len'])) else: log.debug("Creating %s with %d bytes" % (filelocation, uploaded_file['body_len'])) with open(filelocation, 'w+') as fd: uploaded_file['body'].seek(0, 0) data = uploaded_file['body'].read(4000) # 4kb while data != "": os.write(fd.fileno(), data) data = uploaded_file['body'].read(4000) # 4kb return get_file_info(uploaded_file, filelocation)
def dump_static_file(uploaded_file, filelocation): """ @param uploadedfile: uploaded_file @return: a relationship dict linking the filename with the random filename saved in the disk """ try: if os.path.exists(filelocation): log.err('Overwriting file %s with %d bytes' % (filelocation, uploaded_file['body_len'])) else: log.debug('Creating file %s with %d bytes' % (filelocation, uploaded_file['body_len'])) with open(filelocation, 'w+') as fd: uploaded_file['body'].seek(0, 0) data = uploaded_file['body'].read(4000) while data != '': os.write(fd.fileno(), data) data = uploaded_file['body'].read(4000) finally: uploaded_file['body'].close() return get_file_info(uploaded_file, filelocation)
def dump_static_file(uploaded_file, filelocation): """ @param uploadedfile: uploaded_file @return: a relationship dict linking the filename with the random filename saved in the disk """ if os.path.exists(filelocation): log.err("Path %s exists and would be overwritten with %d bytes" % (filelocation, uploaded_file['body_len'] )) else: log.debug("Creating %s with %d bytes" % (filelocation, uploaded_file['body_len'] )) with open(filelocation, 'w+') as fd: uploaded_file['body'].seek(0, 0) data = uploaded_file['body'].read(4000) # 4kb while data != "": os.write(fd.fileno(), data) data = uploaded_file['body'].read(4000) # 4kb return get_file_info(uploaded_file, filelocation)
def dump_file_fs(uploaded_file): """ @param files: a file @return: three variables: #0 a filepath linking the filename with the random filename saved in the disk #1 SHA256 checksum of the file #3 size in bytes of the files """ from Crypto.Random import atfork atfork() saved_name = rstr.xeger(r"[A-Za-z]{26}") filelocation = os.path.join(GLSetting.submission_path, saved_name) log.debug( "Start saving %d bytes from file [%s]" % (uploaded_file["body_len"], uploaded_file["filename"].encode("utf-8")) ) # checksum is computed here, because don't slow down the operation # enough to postpone in a scheduled job. # https://github.com/globaleaks/GlobaLeaks/issues/600 sha = SHA256.new() with open(filelocation, "w+") as fd: uploaded_file["body"].seek(0, 0) data = uploaded_file["body"].read() # 4kb total_length = 0 while data != "": total_length = total_length + len(data) sha.update(data) os.write(fd.fileno(), data) data = uploaded_file["body"].read(4096) # 4kb return (saved_name, sha.hexdigest(), total_length)