@ -52,22 +52,46 @@ class CryptoBoxContainer:
return self . name
def __setAttributes ( self ) :
try :
## is there already an entry in the database?
self . attributes = self . cbox . prefs . volumesDB [ self . getName ( ) ]
self . attributes [ " uuid " ] = self . uuid
except KeyError :
## set default values
self . attributes = { " uuid " : self . uuid }
self . cbox . prefs . volumesDB [ self . getName ( ) ] = self . attributes
def setName ( self , new_name ) :
old_name = self . getName ( )
if new_name == self . name : return
# TODO: check why the following test was/is (?) necessary - side effects?
#if self.isMounted():
# raise CBVolumeIsActive("the container must be inactive during renaming")
## renaming is not possible, if the volume is active, as the mountpoint name
## is the same as the volume name
if self . isMounted ( ) :
raise CBVolumeIsActive ( " the container must not be active during renaming " )
if not re . search ( r ' ^[a-zA-Z0-9_ \ . \ - ]+$ ' , new_name ) :
raise CBInvalidName ( " the supplied new name contains illegal characters " )
" check for active partitions with the same name "
prev_name_owner = self . cbox . getContainerList ( filterName = new_name )
if prev_name_owner :
for a in prev_name_owner :
if a . isMounted ( ) :
raise CBNameActivelyUsed ( " the supplied new name is already in use for an active partition " )
if not self . cbox . setNameForUUID ( self . uuid , new_name ) :
raise CBContainerError ( " failed to change the volume name for unknown reasons " )
## check for another partitions with the same name
if self . cbox . getContainerList ( filterName = new_name ) :
raise CBNameIsInUse ( " the supplied new name is already in use for anonther partition " )
## maybe there a is an entry in the volumes database (but the partition is not active
try :
## remove possibly existing inactive database item
del self . cbox . prefs . volumesDB [ new_name ]
except KeyError :
## no entry - so nothing happens
pass
## set new name
self . name = new_name
## remove old database entry
try :
del self . cbox . prefs . volumesDB [ old_name ]
except KeyError :
pass
## set new volumes database entry
self . cbox . prefs . volumesDB [ new_name ] = self . attributes
self . cbox . prefs . volumesDB . write ( )
def getDevice ( self ) :
@ -112,6 +136,7 @@ class CryptoBoxContainer:
self . uuid = self . __getUUID ( )
self . type = self . __getTypeOfPartition ( )
self . name = self . __getNameOfContainer ( )
self . __setAttributes ( )
if self . type == self . Types [ " luks " ] :
self . mount = self . __mountLuks
self . umount = self . __umountLuks
@ -201,20 +226,23 @@ class CryptoBoxContainer:
" ****************** internal stuff ********************* "
def __getNameOfContainer ( self ) :
" retrieve the name of the container by querying the database "
def_name = self . cbox . getNameForUUID ( self . uuid )
if def_name : return def_name
" there is no name defined for this uuid - we will propose a good one "
""" retrieve the name of the container by querying the database
call this function only for the initial setup of the container object """
found_name = None
for key in self . cbox . prefs . volumesDB . keys ( ) :
if self . cbox . prefs . volumesDB [ key ] [ " uuid " ] == self . uuid :
found_name = key
if found_name : return found_name
## there is no name defined for this uuid - we will propose a good one
prefix = self . cbox . prefs [ " Main " ] [ " DefaultVolumePrefix " ]
unused_found = False
counter = 1
while not unused_found :
guess = prefix + str ( counter )
if self . cbox . getUUIDForName ( guess ) :
if self . cbox . prefs. volumesDB . has_key ( guess ) :
counter + = 1
else :
unused_found = True
self . cbox . setNameForUUID ( self . uuid , guess )
return guess