Merge pull request #340 from ThomasWaldmann/fix-fuse-locking

fuse mount: fix unlocking of repository at umount time, fixes #331
This commit is contained in:
TW 2015-10-27 23:01:05 +01:00
commit b4535471f6
2 changed files with 22 additions and 16 deletions

View file

@ -348,18 +348,21 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
return self.exit_code
repository = self.open_repository(args.src)
manifest, key = Manifest.load(repository)
if args.src.archive:
archive = Archive(repository, key, manifest, args.src.archive)
else:
archive = None
operations = FuseOperations(key, repository, manifest, archive)
self.print_verbose("Mounting filesystem")
try:
operations.mount(args.mountpoint, args.options, args.foreground)
except RuntimeError:
# Relevant error message already printed to stderr by fuse
self.exit_code = EXIT_ERROR
manifest, key = Manifest.load(repository)
if args.src.archive:
archive = Archive(repository, key, manifest, args.src.archive)
else:
archive = None
operations = FuseOperations(key, repository, manifest, archive)
self.print_verbose("Mounting filesystem")
try:
operations.mount(args.mountpoint, args.options, args.foreground)
except RuntimeError:
# Relevant error message already printed to stderr by fuse
self.exit_code = EXIT_ERROR
finally:
repository.close()
return self.exit_code
def do_list(self, args):

View file

@ -2,7 +2,6 @@ import errno
import json
import os
import socket
import threading
import time
from borg.helpers import Error
@ -10,13 +9,17 @@ from borg.helpers import Error
ADD, REMOVE = 'add', 'remove'
SHARED, EXCLUSIVE = 'shared', 'exclusive'
# only determine the PID and hostname once.
# for FUSE mounts, we fork a child process that needs to release
# the lock made by the parent, so it needs to use the same PID for that.
_pid = os.getpid()
_hostname = socket.gethostname()
def get_id():
"""Get identification tuple for 'us'"""
hostname = socket.gethostname()
pid = os.getpid()
tid = threading.current_thread().ident & 0xffffffff
return hostname, pid, tid
thread_id = 0
return _hostname, _pid, thread_id
class TimeoutTimer: