mark created mountpoints to remove them safely afterwards
This commit is contained in:
parent
8511ff9845
commit
3490be26ef
|
@ -11,16 +11,6 @@ import re
|
||||||
import logging
|
import logging
|
||||||
from cryptobox.core.exceptions import *
|
from cryptobox.core.exceptions import *
|
||||||
|
|
||||||
"""exceptions:
|
|
||||||
CBVolumeIsActive
|
|
||||||
CBNameActivelyUsed
|
|
||||||
CBInvalidName
|
|
||||||
CBInvalidPassword
|
|
||||||
CBInvalidType
|
|
||||||
CBCreateError
|
|
||||||
CBMountError
|
|
||||||
CBChangePasswordError
|
|
||||||
"""
|
|
||||||
|
|
||||||
ContainerTypes = {
|
ContainerTypes = {
|
||||||
"unused":0,
|
"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:
|
class CryptoBoxContainer:
|
||||||
|
|
||||||
__fsTypes = {
|
__fsTypes = {
|
||||||
|
@ -377,7 +372,7 @@ class CryptoBoxContainer:
|
||||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||||
self.__cleanMountDirs()
|
self.__cleanMountDirs()
|
||||||
if not os.path.exists(self.__getMountPoint()):
|
if not os.path.exists(self.__getMountPoint()):
|
||||||
os.mkdir(self.__getMountPoint())
|
self.__createMountDirectory(self.__getMountPoint())
|
||||||
if not os.path.exists(self.__getMountPoint()):
|
if not os.path.exists(self.__getMountPoint()):
|
||||||
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
||||||
self.log.error(errorMsg)
|
self.log.error(errorMsg)
|
||||||
|
@ -478,7 +473,7 @@ class CryptoBoxContainer:
|
||||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||||
self.__cleanMountDirs()
|
self.__cleanMountDirs()
|
||||||
if not os.path.exists(self.__getMountPoint()):
|
if not os.path.exists(self.__getMountPoint()):
|
||||||
os.mkdir(self.__getMountPoint())
|
self.__createMountDirectory(self.__getMountPoint())
|
||||||
if not os.path.exists(self.__getMountPoint()):
|
if not os.path.exists(self.__getMountPoint()):
|
||||||
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
||||||
self.log.error(errorMsg)
|
self.log.error(errorMsg)
|
||||||
|
@ -637,10 +632,31 @@ class CryptoBoxContainer:
|
||||||
""" remove all unnecessary subdirs of the mount parent directory
|
""" remove all unnecessary subdirs of the mount parent directory
|
||||||
this should be called for every (u)mount """
|
this should be called for every (u)mount """
|
||||||
subdirs = os.listdir(self.cbox.prefs["Locations"]["MountParentDir"])
|
subdirs = os.listdir(self.cbox.prefs["Locations"]["MountParentDir"])
|
||||||
for dir in subdirs:
|
for d in subdirs:
|
||||||
abs_dir = os.path.join(self.cbox.prefs["Locations"]["MountParentDir"], dir)
|
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)):
|
if (not os.path.islink(abs_dir)) \
|
||||||
os.rmdir(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):
|
def __getEventArgs(self):
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
'''
|
'''
|
||||||
This is the web interface for a fileserver managing encrypted filesystems.
|
This is the web interface for a fileserver managing encrypted filesystems.
|
||||||
|
|
||||||
It was originally written in bash/perl. Now a complete rewrite is in
|
|
||||||
progress. So things might be confusing here. Hopefully not for long.
|
|
||||||
:)
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# check python version
|
# check python version
|
||||||
|
@ -26,7 +22,7 @@ VERSION = "0.3~1"
|
||||||
class CryptoBox:
|
class CryptoBox:
|
||||||
'''this class rules them all!
|
'''this class rules them all!
|
||||||
|
|
||||||
put things like logging, conf and oter stuff in here,
|
put things like logging, conf and other stuff in here,
|
||||||
that might be used by more classes, it will be passed on to them'''
|
that might be used by more classes, it will be passed on to them'''
|
||||||
|
|
||||||
|
|
||||||
|
@ -186,7 +182,7 @@ class CryptoBoxProps(CryptoBox):
|
||||||
try:
|
try:
|
||||||
result = self.containers[:]
|
result = self.containers[:]
|
||||||
if filterType != None:
|
if filterType != None:
|
||||||
if filterType in range(len(cbxContainer.Types)):
|
if filterType in range(len(cbxContainer.ContainerTypes)):
|
||||||
return [e for e in self.containers if e.getType() == filterType]
|
return [e for e in self.containers if e.getType() == filterType]
|
||||||
else:
|
else:
|
||||||
self.log.info("invalid filterType (%d)" % filterType)
|
self.log.info("invalid filterType (%d)" % filterType)
|
||||||
|
|
Loading…
Reference in a new issue