mirror of
https://github.com/SlavikMIPT/tgcloud.git
synced 2025-02-15 04:32:14 +00:00
hotfix - problem with download switched from pipe to NamedTemporaryFile
This commit is contained in:
parent
d67499a8b6
commit
73a569b9e2
2 changed files with 23 additions and 27 deletions
|
@ -818,13 +818,13 @@ class DedupFS(fuse.Fuse): # {{{1
|
||||||
(inode, hash_id, block_nr))
|
(inode, hash_id, block_nr))
|
||||||
else:
|
else:
|
||||||
|
|
||||||
FIFO_PIPE = str('pipe_' + digest.encode('hex'))
|
FIFO_PIPE = str('upipe_' + digest.encode('hex'))
|
||||||
try:
|
try:
|
||||||
os.mkfifo(FIFO_PIPE)
|
os.mkfifo(FIFO_PIPE)
|
||||||
except OSError as oe:
|
except OSError as oe:
|
||||||
if oe.errno != errno.EEXIST:
|
if oe.errno != errno.EEXIST:
|
||||||
raise
|
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:
|
with open(FIFO_PIPE, 'wb') as pipe:
|
||||||
os.unlink(FIFO_PIPE)
|
os.unlink(FIFO_PIPE)
|
||||||
pipe.write(self.compress(new_block))
|
pipe.write(self.compress(new_block))
|
||||||
|
@ -1173,17 +1173,12 @@ class DedupFS(fuse.Fuse): # {{{1
|
||||||
self.conn.rollback()
|
self.conn.rollback()
|
||||||
|
|
||||||
def __get_block_from_telegram(self, digest):
|
def __get_block_from_telegram(self, digest):
|
||||||
FIFO_PIPE = str('pipe_' + str(digest))
|
buf = tempfile.NamedTemporaryFile()
|
||||||
try:
|
process = Popen(["python3.6", "download_service.py", "download", str(digest),str(buf.name)],bufsize=-1)
|
||||||
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()
|
|
||||||
process.wait()
|
process.wait()
|
||||||
|
buf.seek(0)
|
||||||
|
block = buf.read()
|
||||||
|
buf.close()
|
||||||
return block
|
return block
|
||||||
|
|
||||||
def __get_file_buffer(self, path): # {{{3
|
def __get_file_buffer(self, path): # {{{3
|
||||||
|
|
|
@ -10,7 +10,7 @@ from telethon.tl.types import DocumentAttributeFilename
|
||||||
|
|
||||||
from telethon.telegram_client import TelegramClient
|
from telethon.telegram_client import TelegramClient
|
||||||
from telegram_client_x import TelegramClientX
|
from telegram_client_x import TelegramClientX
|
||||||
from secret import *
|
from secret_my import *
|
||||||
|
|
||||||
path_home = './' # os.path.abspath('.')
|
path_home = './' # os.path.abspath('.')
|
||||||
client = TelegramClientX(entity, api_id, api_hash, update_workers=None, spawn_read_thread=True)
|
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:
|
try:
|
||||||
hash_uid = str(hash_uid)
|
hash_uid = str(hash_uid)
|
||||||
os.chdir(path_home)
|
os.chdir(path_home)
|
||||||
|
@ -56,16 +56,17 @@ def download_block(hash_uid):
|
||||||
for i in range(len(messages)):
|
for i in range(len(messages)):
|
||||||
msg = messages[i]
|
msg = messages[i]
|
||||||
if msg.message == hash_uid:
|
if msg.message == hash_uid:
|
||||||
FIFO = f"pipe_{hash_uid}"
|
# FIFO = f"dpipe_{hash_uid}"
|
||||||
import errno
|
# import errno
|
||||||
try:
|
# try:
|
||||||
os.mkfifo(FIFO)
|
# os.mkfifo(FIFO)
|
||||||
except OSError as oe:
|
# except OSError as oe:
|
||||||
if oe.errno != errno.EEXIST:
|
# if oe.errno != errno.EEXIST:
|
||||||
raise
|
# raise
|
||||||
with open(FIFO, 'wb') as outbuf:
|
# outbuf = open(FIFO, "wb"):
|
||||||
os.unlink(FIFO)
|
# os.unlink(FIFO)
|
||||||
client.download_media(msg, file=outbuf, progress_callback=on_download_progress)
|
client.download_media(msg, file=filename, progress_callback=on_download_progress)
|
||||||
|
# outbuf.flush()
|
||||||
return 0
|
return 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return -1
|
return -1
|
||||||
|
@ -78,7 +79,7 @@ def upload_block(hash_uid):
|
||||||
hash_uid = str(hash_uid)
|
hash_uid = str(hash_uid)
|
||||||
os.chdir(path_home)
|
os.chdir(path_home)
|
||||||
entity = client.get_entity(client.get_me())
|
entity = client.get_entity(client.get_me())
|
||||||
FIFO = f"pipe_{hash_uid}"
|
FIFO = f"upipe_{hash_uid}"
|
||||||
import errno
|
import errno
|
||||||
try:
|
try:
|
||||||
os.mkfifo(FIFO)
|
os.mkfifo(FIFO)
|
||||||
|
@ -94,7 +95,6 @@ def upload_block(hash_uid):
|
||||||
part_size_kb=512,
|
part_size_kb=512,
|
||||||
force_document=True,
|
force_document=True,
|
||||||
progress_callback=on_upload_progress)
|
progress_callback=on_upload_progress)
|
||||||
# message.id
|
|
||||||
return 0
|
return 0
|
||||||
except Exception:
|
except Exception:
|
||||||
return -1
|
return -1
|
||||||
|
@ -107,7 +107,8 @@ def main(argv):
|
||||||
service = str(argv[1])
|
service = str(argv[1])
|
||||||
if service == 'download':
|
if service == 'download':
|
||||||
uid = str(argv[2])
|
uid = str(argv[2])
|
||||||
download_block(hash_uid=uid)
|
filename = str (argv[3])
|
||||||
|
download_block(hash_uid=uid,filename=filename)
|
||||||
return 0
|
return 0
|
||||||
elif service == 'upload':
|
elif service == 'upload':
|
||||||
uid = str(argv[2])
|
uid = str(argv[2])
|
||||||
|
|
Loading…
Reference in a new issue