Skip to content

Commit

Permalink
Better detection of mounted sshfs filesystems.
Browse files Browse the repository at this point in the history
We used to look for /usr/bin/sshfs process instances
to see if something is mounted, but that's not very realiable,
because it may tell you that something is mounted
even though it hasn't fully completed the mounting process.

This new method uses mount -l, which is more reliable, faster and simpler.
  • Loading branch information
spantaleev committed Jun 23, 2011
1 parent 0a070a8 commit 29a19d0
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions sftpman/model.py
Expand Up @@ -47,20 +47,11 @@ def get_available_ids(self):
return [file_name[0:-3] for file_name in cfg_files if file_name.endswith('.js')]

def get_mounted_ids(self):
# Looking for /mnt/sshfs/{id}
regex = re.compile("/usr/bin/sshfs(?:.+?)%s(\w+)$" %
re.escape(self.mount_path_base))

processes = shell_exec("/bin/ps ux | /bin/grep '/usr/bin/sshfs'")
ids = []
for line in processes.split("\n"):
if self.mount_path_base not in line:
continue
match_object = re.search(regex, line)
if (match_object is None):
continue
ids.append(match_object.group(1))
return ids
# Looking for /mnt/sshfs/{id} in output that looks like this:
# user@host:/remote/path on /mnt/sshfs/id type fuse.sshfs ...
regex = re.compile(' %s(\w+) ' % self.mount_path_base)
mounted = shell_exec('mount -l -t fuse.sshfs')
return regex.findall(mounted)

def get_unmounted_ids(self):
ids_mounted = self.get_mounted_ids()
Expand Down

0 comments on commit 29a19d0

Please sign in to comment.