Commit a7eb9b1f by rfkelly0

fs.expose.fuse: * more robust unmounting

                 * properly encode unicode pathnames 
parent 076bef55
...@@ -69,7 +69,7 @@ Operations = fuse.Operations ...@@ -69,7 +69,7 @@ Operations = fuse.Operations
fuse_get_context = fuse.fuse_get_context fuse_get_context = fuse.fuse_get_context
STARTUP_TIME = time.time() STARTUP_TIME = time.time()
NATIVE_ENCODING = sys.getfilesystemencoding()
def handle_fs_errors(func): def handle_fs_errors(func):
"""Method decorator to report FS errors in the appropriate way. """Method decorator to report FS errors in the appropriate way.
...@@ -220,7 +220,8 @@ class FSOperations(Operations): ...@@ -220,7 +220,8 @@ class FSOperations(Operations):
@handle_fs_errors @handle_fs_errors
def readdir(self,path,fh=None): def readdir(self,path,fh=None):
return ['.', '..'] + self.fs.listdir(path) entries = [e.encode(NATIVE_ENCODING) for e in self.fs.listdir(path)]
return ['.', '..'] + entries
@handle_fs_errors @handle_fs_errors
def readlink(self,path): def readlink(self,path):
...@@ -292,7 +293,7 @@ class FSOperations(Operations): ...@@ -292,7 +293,7 @@ class FSOperations(Operations):
return len(data) return len(data)
def mount(fs,path,foreground=False,ready_callback=None,**kwds): def mount(fs,path,foreground=False,ready_callback=None,unmount_callback=None,**kwds):
"""Mount the given FS at the given path, using FUSE. """Mount the given FS at the given path, using FUSE.
By default, this function spawns a new background process to manage the By default, this function spawns a new background process to manage the
...@@ -313,12 +314,18 @@ def mount(fs,path,foreground=False,ready_callback=None,**kwds): ...@@ -313,12 +314,18 @@ def mount(fs,path,foreground=False,ready_callback=None,**kwds):
""" """
if foreground: if foreground:
ops = FSOperations(fs,on_init=ready_callback) op = FSOperations(fs,on_init=ready_callback,on_destroy=unmount_callback)
return FUSE(ops,path,foreground=foreground,**kwds) return FUSE(op,path,foreground=foreground,**kwds)
else: else:
mp = MountProcess(fs,path,kwds) mp = MountProcess(fs,path,kwds)
if ready_callback: if ready_callback:
ready_callback() ready_callback()
if unmount_callback:
orig_unmount = mp.unmount
def new_unmount():
orig_unmount()
unmount_callback()
mp.unmount = new_unmount
return mp return mp
...@@ -395,13 +402,17 @@ class MountProcess(subprocess.Popen): ...@@ -395,13 +402,17 @@ class MountProcess(subprocess.Popen):
self.terminate() self.terminate()
else: else:
os.kill(self.pid,signal.SIGTERM) os.kill(self.pid,signal.SIGTERM)
self.wait() self.communicate()
@staticmethod @staticmethod
def _do_mount_nowait(data): def _do_mount_nowait(data):
"""Perform the specified mount, return without waiting.""" """Perform the specified mount, return without waiting."""
(fs,path,opts) = pickle.loads(data) (fs,path,opts) = pickle.loads(data)
opts["foreground"] = True opts["foreground"] = True
if hasattr(fs,"close"):
def unmount_callback():
fs.close()
opts["unmount_callback"] = unmount_callback
mount(fs,path,*opts) mount(fs,path,*opts)
@staticmethod @staticmethod
...@@ -416,6 +427,10 @@ class MountProcess(subprocess.Popen): ...@@ -416,6 +427,10 @@ class MountProcess(subprocess.Popen):
os.write(w,"S") os.write(w,"S")
os.close(w) os.close(w)
opts["ready_callback"] = ready_callback opts["ready_callback"] = ready_callback
if hasattr(fs,"close"):
def unmount_callback():
fs.close()
opts["unmount_callback"] = unmount_callback
try: try:
mount(fs,path,**opts) mount(fs,path,**opts)
except Exception: except Exception:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment