mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-22 15:57:15 +00:00
Merge remote-tracking branch 'tw/fix_pipe'
This commit is contained in:
commit
8227e4788a
1 changed files with 11 additions and 10 deletions
|
@ -30,17 +30,19 @@ def __init__(self, restrict_to_paths):
|
||||||
self.restrict_to_paths = restrict_to_paths
|
self.restrict_to_paths = restrict_to_paths
|
||||||
|
|
||||||
def serve(self):
|
def serve(self):
|
||||||
|
stdin_fd = sys.stdin.fileno()
|
||||||
|
stdout_fd = sys.stdout.fileno()
|
||||||
# Make stdin non-blocking
|
# Make stdin non-blocking
|
||||||
fl = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL)
|
fl = fcntl.fcntl(stdin_fd, fcntl.F_GETFL)
|
||||||
fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
fcntl.fcntl(stdin_fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
||||||
# Make stdout blocking
|
# Make stdout blocking
|
||||||
fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
|
fl = fcntl.fcntl(stdout_fd, fcntl.F_GETFL)
|
||||||
fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl & ~os.O_NONBLOCK)
|
fcntl.fcntl(stdout_fd, fcntl.F_SETFL, fl & ~os.O_NONBLOCK)
|
||||||
unpacker = msgpack.Unpacker(use_list=False)
|
unpacker = msgpack.Unpacker(use_list=False)
|
||||||
while True:
|
while True:
|
||||||
r, w, es = select.select([sys.stdin], [], [], 10)
|
r, w, es = select.select([stdin_fd], [], [], 10)
|
||||||
if r:
|
if r:
|
||||||
data = os.read(sys.stdin.fileno(), BUFSIZE)
|
data = os.read(stdin_fd, BUFSIZE)
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
unpacker.feed(data)
|
unpacker.feed(data)
|
||||||
|
@ -53,10 +55,9 @@ def serve(self):
|
||||||
f = getattr(self.repository, method)
|
f = getattr(self.repository, method)
|
||||||
res = f(*args)
|
res = f(*args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.stdout.buffer.write(msgpack.packb((1, msgid, e.__class__.__name__, e.args)))
|
os.write(stdout_fd, msgpack.packb((1, msgid, e.__class__.__name__, e.args)))
|
||||||
else:
|
else:
|
||||||
sys.stdout.buffer.write(msgpack.packb((1, msgid, None, res)))
|
os.write(stdout_fd, msgpack.packb((1, msgid, None, res)))
|
||||||
sys.stdout.flush()
|
|
||||||
if es:
|
if es:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -312,4 +313,4 @@ def get_many(self, keys):
|
||||||
def cache_if_remote(repository):
|
def cache_if_remote(repository):
|
||||||
if isinstance(repository, RemoteRepository):
|
if isinstance(repository, RemoteRepository):
|
||||||
return RepositoryCache(repository)
|
return RepositoryCache(repository)
|
||||||
return repository
|
return repository
|
||||||
|
|
Loading…
Reference in a new issue