diff --git a/oscfs/fs.py b/oscfs/fs.py index 8e73ef9..20c152c 100644 --- a/oscfs/fs.py +++ b/oscfs/fs.py @@ -2,6 +2,8 @@ import errno import os import sys +import threading +import time # third party modules import fuse @@ -32,6 +34,7 @@ def __init__(self): # unallocated file handles self.m_free_handles = list(range(1024)) self._setupParser() + self._keepalive_timer = threading.Thread(target=self._keepalive_thread) def _setupParser(self): @@ -84,6 +87,14 @@ def _setupParser(self): seconds. Set to zero to disable caching.""" ) + self.m_parser.add_argument( + "--keepalive-interval", type=int, + default=0, + help=f"""Specifies the time in seconds a keepalive request will be + issued towards the OBS backend. Default: 0 + seconds. Set to zero to disable keepalive.""" + ) + def _checkAuth(self): """Check for correct authentication at the remote server.""" # simply fetch the root entries, this will also benefit the @@ -139,8 +150,13 @@ def _setupLogfile(self): sys.stdout = lf sys.stderr = lf - def run(self): + def _keepalive_thread(self): + while self._keepalive: + time.sleep(self.m_args.keepalive_interval) + # send a request to keep the connection alive + self.m_obs.about() + def run(self): self.m_args = self.m_parser.parse_args() self._setupLogfile() self.m_obs.configure(self.m_args.apiurl) @@ -164,6 +180,9 @@ def run(self): nonempty=True ) + self._keepalive = False + self._keepalive_timer.join() + def init(self, path): """This is called upon file system initialization.""" if self.m_args.f: @@ -173,6 +192,9 @@ def init(self, path): print("file system initialized") sys.stdout.flush() + self._keepalive = self.m_args.keepalive_interval > 0 + self._keepalive_timer.start() + # global file system methods def getattr(self, path, fh=None): diff --git a/oscfs/obs.py b/oscfs/obs.py index 8194637..38ca24c 100644 --- a/oscfs/obs.py +++ b/oscfs/obs.py @@ -198,6 +198,17 @@ def _download(self, urlcomps, query=dict()): return f.read() + @transparent_retry() + def about(self): + url = osc.core.makeurl( + self.m_apiurl, + ['about'] + ) + + f = osc.core.http_GET(url) + + return f.read() + @transparent_retry() def _getPackageRevisions(self, project, package, fmt): """Returns the list of revisions for the given project/package