Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion oscfs/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import errno
import os
import sys
import threading
import time

# third party modules
import fuse
Expand Down Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the thread is started only if its actually needed, in the init() method as well.

Currently there is also a race, because the self._keepalive flag might be unset when the thread enters its loop.


def _setupParser(self):

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions oscfs/obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down