Commit 01c6cd7e authored by Marco Mariani's avatar Marco Mariani

SlapObject: cleaner handling of sr_symlink

parent a84d4b79
...@@ -367,14 +367,25 @@ class Partition(object): ...@@ -367,14 +367,25 @@ class Partition(object):
'USER': pwd.getpwuid(uid).pw_name, 'USER': pwd.getpwuid(uid).pw_name,
} }
def updateSymlink(self, sr_symlink, software_path): @property
if os.path.lexists(sr_symlink): def software_release_link(self):
if not os.path.islink(sr_symlink): return os.path.join(self.instance_path, 'software_release')
self.logger.debug('Not a symlink: %s, has been ignored' % sr_symlink)
def update_link_to_sr(self):
link = self.software_release_link
if os.path.lexists(link):
if not os.path.islink(link):
self.logger.debug('Not a symlink: %s, has been ignored', link)
return return
os.unlink(sr_symlink) os.unlink(link)
os.symlink(software_path, sr_symlink) os.symlink(self.software_path, link)
os.lchown(sr_symlink, *self.getUserGroupId()) uid, gid = self.getUserGroupId()
os.lchown(link, uid, gid)
def remove_link_to_sr(self):
link = self.software_release_link
if os.path.islink(link):
os.unlink(link)
def install(self): def install(self):
""" Creates configuration file from template in software_path, then """ Creates configuration file from template in software_path, then
...@@ -388,8 +399,7 @@ class Partition(object): ...@@ -388,8 +399,7 @@ class Partition(object):
raise PathDoesNotExistError('Please create partition directory %s' raise PathDoesNotExistError('Please create partition directory %s'
% self.instance_path) % self.instance_path)
sr_symlink = os.path.join(self.instance_path, 'software_release') self.update_link_to_sr()
self.updateSymlink(sr_symlink, self.software_path)
instance_stat_info = os.stat(self.instance_path) instance_stat_info = os.stat(self.instance_path)
permission = stat.S_IMODE(instance_stat_info.st_mode) permission = stat.S_IMODE(instance_stat_info.st_mode)
...@@ -599,9 +609,7 @@ class Partition(object): ...@@ -599,9 +609,7 @@ class Partition(object):
os.unlink(f) os.unlink(f)
# better to manually remove symlinks because rmtree might choke on them # better to manually remove symlinks because rmtree might choke on them
sr_symlink = os.path.join(self.instance_path, 'software_release') self.remove_link_to_sr()
if os.path.islink(sr_symlink):
os.unlink(sr_symlink)
for root, dirs, file_list in os.walk(self.instance_path): for root, dirs, file_list in os.walk(self.instance_path):
for directory in dirs: for directory in dirs:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment