|
|
|
@ -11,16 +11,6 @@ import re
|
|
|
|
|
import logging
|
|
|
|
|
from cryptobox.core.exceptions import *
|
|
|
|
|
|
|
|
|
|
"""exceptions:
|
|
|
|
|
CBVolumeIsActive
|
|
|
|
|
CBNameActivelyUsed
|
|
|
|
|
CBInvalidName
|
|
|
|
|
CBInvalidPassword
|
|
|
|
|
CBInvalidType
|
|
|
|
|
CBCreateError
|
|
|
|
|
CBMountError
|
|
|
|
|
CBChangePasswordError
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
ContainerTypes = {
|
|
|
|
|
"unused":0,
|
|
|
|
@ -30,6 +20,11 @@ ContainerTypes = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## we use this marker to make sure, that we do not remove a non-cryptobox directory
|
|
|
|
|
## below the mount directory
|
|
|
|
|
MOUNT_DIR_MARKER = '_cryptobox_mount_dir_'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CryptoBoxContainer:
|
|
|
|
|
|
|
|
|
|
__fsTypes = {
|
|
|
|
@ -377,7 +372,7 @@ class CryptoBoxContainer:
|
|
|
|
|
self.log.warn("Could not open %s" % (os.devnull, ))
|
|
|
|
|
self.__cleanMountDirs()
|
|
|
|
|
if not os.path.exists(self.__getMountPoint()):
|
|
|
|
|
os.mkdir(self.__getMountPoint())
|
|
|
|
|
self.__createMountDirectory(self.__getMountPoint())
|
|
|
|
|
if not os.path.exists(self.__getMountPoint()):
|
|
|
|
|
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
|
|
|
|
self.log.error(errorMsg)
|
|
|
|
@ -478,7 +473,7 @@ class CryptoBoxContainer:
|
|
|
|
|
self.log.warn("Could not open %s" % (os.devnull, ))
|
|
|
|
|
self.__cleanMountDirs()
|
|
|
|
|
if not os.path.exists(self.__getMountPoint()):
|
|
|
|
|
os.mkdir(self.__getMountPoint())
|
|
|
|
|
self.__createMountDirectory(self.__getMountPoint())
|
|
|
|
|
if not os.path.exists(self.__getMountPoint()):
|
|
|
|
|
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
|
|
|
|
self.log.error(errorMsg)
|
|
|
|
@ -637,11 +632,32 @@ class CryptoBoxContainer:
|
|
|
|
|
""" remove all unnecessary subdirs of the mount parent directory
|
|
|
|
|
this should be called for every (u)mount """
|
|
|
|
|
subdirs = os.listdir(self.cbox.prefs["Locations"]["MountParentDir"])
|
|
|
|
|
for dir in subdirs:
|
|
|
|
|
abs_dir = os.path.join(self.cbox.prefs["Locations"]["MountParentDir"], dir)
|
|
|
|
|
if (not os.path.islink(abs_dir)) and os.path.isdir(abs_dir) and (not os.path.ismount(abs_dir)):
|
|
|
|
|
os.rmdir(abs_dir)
|
|
|
|
|
for d in subdirs:
|
|
|
|
|
abs_dir = os.path.join(self.cbox.prefs["Locations"]["MountParentDir"], d)
|
|
|
|
|
if (not os.path.islink(abs_dir)) \
|
|
|
|
|
and os.path.isdir(abs_dir) \
|
|
|
|
|
and (not os.path.ismount(abs_dir)) \
|
|
|
|
|
and (os.path.isfile(os.path.join(abs_dir,MOUNT_DIR_MARKER))) \
|
|
|
|
|
and (len(os.listdir(abs_dir)) == 1):
|
|
|
|
|
try:
|
|
|
|
|
os.remove(os.path.join(abs_dir,MOUNT_DIR_MARKER))
|
|
|
|
|
os.rmdir(abs_dir)
|
|
|
|
|
except OSError,errMsg:
|
|
|
|
|
## we do not care too much about unclean cleaning ...
|
|
|
|
|
self.log.info("failed to clean a mountpoint (%s): %s" % (abs_dir,str(errMsg)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __createMountDirectory(self,dirname):
|
|
|
|
|
"""create and mark a mount directory
|
|
|
|
|
this marking helps to remove old mountdirs safely"""
|
|
|
|
|
os.mkdir(dirname)
|
|
|
|
|
try:
|
|
|
|
|
f = file(os.path.join(dirname,MOUNT_DIR_MARKER),"w")
|
|
|
|
|
f.close()
|
|
|
|
|
except OSError,errMsg:
|
|
|
|
|
## we do not care too much about the marking
|
|
|
|
|
self.log.info("failed to mark a mountpoint (%s): %s" % (dirname,str(errMsg)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __getEventArgs(self):
|
|
|
|
|
"""return an array of arguments for event scripts handling pre/post-mount/umount
|
|
|
|
|