1
0
Fork 0
mirror of https://github.com/SlavikMIPT/tgcloud.git synced 2025-02-14 12:12:14 +00:00

hotfix - problem with download switched from pipe to NamedTemporaryFile

This commit is contained in:
Вячеслав Баженов 2019-07-08 12:01:30 +03:00
parent d67499a8b6
commit 73a569b9e2
2 changed files with 23 additions and 27 deletions

View file

@ -818,13 +818,13 @@ class DedupFS(fuse.Fuse): # {{{1
(inode, hash_id, block_nr))
else:
FIFO_PIPE = str('pipe_' + digest.encode('hex'))
FIFO_PIPE = str('upipe_' + digest.encode('hex'))
try:
os.mkfifo(FIFO_PIPE)
except OSError as oe:
if oe.errno != errno.EEXIST:
raise
process = Popen(["python3.6", "download_service.py", "upload", digest.encode('hex')], shell=False)
process = Popen(["python3.6", "download_service.py", "upload", digest.encode('hex')], bufsize=-1)
with open(FIFO_PIPE, 'wb') as pipe:
os.unlink(FIFO_PIPE)
pipe.write(self.compress(new_block))
@ -1173,17 +1173,12 @@ class DedupFS(fuse.Fuse): # {{{1
self.conn.rollback()
def __get_block_from_telegram(self, digest):
FIFO_PIPE = str('pipe_' + str(digest))
try:
os.mkfifo(FIFO_PIPE)
except OSError as oe:
if oe.errno != errno.EEXIST:
raise
process = Popen(["python3.6", "download_service.py", "download", str(digest)], shell=False)
with open(FIFO_PIPE, 'rb') as pipe:
# os.unlink(FIFO_PIPE)
block = pipe.read()
buf = tempfile.NamedTemporaryFile()
process = Popen(["python3.6", "download_service.py", "download", str(digest),str(buf.name)],bufsize=-1)
process.wait()
buf.seek(0)
block = buf.read()
buf.close()
return block
def __get_file_buffer(self, path): # {{{3

View file

@ -10,7 +10,7 @@ from telethon.tl.types import DocumentAttributeFilename
from telethon.telegram_client import TelegramClient
from telegram_client_x import TelegramClientX
from secret import *
from secret_my import *
path_home = './' # os.path.abspath('.')
client = TelegramClientX(entity, api_id, api_hash, update_workers=None, spawn_read_thread=True)
@ -46,7 +46,7 @@ def on_upload_progress(send_bytes, total_bytes):
#
def download_block(hash_uid):
def download_block(hash_uid, filename):
try:
hash_uid = str(hash_uid)
os.chdir(path_home)
@ -56,16 +56,17 @@ def download_block(hash_uid):
for i in range(len(messages)):
msg = messages[i]
if msg.message == hash_uid:
FIFO = f"pipe_{hash_uid}"
import errno
try:
os.mkfifo(FIFO)
except OSError as oe:
if oe.errno != errno.EEXIST:
raise
with open(FIFO, 'wb') as outbuf:
os.unlink(FIFO)
client.download_media(msg, file=outbuf, progress_callback=on_download_progress)
# FIFO = f"dpipe_{hash_uid}"
# import errno
# try:
# os.mkfifo(FIFO)
# except OSError as oe:
# if oe.errno != errno.EEXIST:
# raise
# outbuf = open(FIFO, "wb"):
# os.unlink(FIFO)
client.download_media(msg, file=filename, progress_callback=on_download_progress)
# outbuf.flush()
return 0
except Exception as e:
return -1
@ -78,7 +79,7 @@ def upload_block(hash_uid):
hash_uid = str(hash_uid)
os.chdir(path_home)
entity = client.get_entity(client.get_me())
FIFO = f"pipe_{hash_uid}"
FIFO = f"upipe_{hash_uid}"
import errno
try:
os.mkfifo(FIFO)
@ -94,7 +95,6 @@ def upload_block(hash_uid):
part_size_kb=512,
force_document=True,
progress_callback=on_upload_progress)
# message.id
return 0
except Exception:
return -1
@ -107,7 +107,8 @@ def main(argv):
service = str(argv[1])
if service == 'download':
uid = str(argv[2])
download_block(hash_uid=uid)
filename = str (argv[3])
download_block(hash_uid=uid,filename=filename)
return 0
elif service == 'upload':
uid = str(argv[2])