* reinstall, install, remove paths:

- if there are changes in the config file, keep them, store
    new config file with ".new" prefix in that case. don't ask 
    me why it took this many changes. all tested well.
This commit is contained in:
Eray Özkural
2006-06-15 14:06:41 +00:00
parent 7bfc634b8a
commit ab979f8765
3 changed files with 60 additions and 21 deletions
+8 -3
View File
@@ -1,10 +1,15 @@
Authors: Authors and contributors
------------------------
Eray Özkural <eray [at] pardus.org.tr> Eray Özkural <eray [at] pardus.org.tr>
Barış Metin <baris [at] pardus.org.tr> Barış Metin <baris [at] pardus.org.tr>
A. Murat Eren <meren [at] pardus.org.tr>
S. Çağlar Onur <caglar [at] pardus.org.tr> S. Çağlar Onur <caglar [at] pardus.org.tr>
A. Murat Eren <meren [at] pardus.org.tr>
Faik Uygur <faik [at] pardus.org.tr>
Gürer Özen <gurer [at] pardus.org.tr> Gürer Özen <gurer [at] pardus.org.tr>
İsmail Dönmez <ismail [at] pardus.org.tr> İsmail Dönmez <ismail [at] pardus.org.tr>
Faik Uygur <faik [at] pardus.org.tr> Görkem Çetin <gorkem [at] pardus.org.tr>
Bahadır Kandemir <bahadir [at] pardus.org.tr> Bahadır Kandemir <bahadir [at] pardus.org.tr>
Ahmet Aygun <ahmet.aygun [at] pardus.org.tr>
Onur Küçük <onur [at] pardus.org.tr>
Furkan Duman <fduman [at] pardus.org.tr>
+50 -16
View File
@@ -27,13 +27,11 @@ import pisi.packagedb as packagedb
import pisi.dependency as dependency import pisi.dependency as dependency
import pisi.util as util import pisi.util as util
from pisi.specfile import * from pisi.specfile import *
#from pisi.package import Package
from pisi.metadata import MetaData from pisi.metadata import MetaData
from pisi.files import Files from pisi.files import Files
from pisi.uri import URI from pisi.uri import URI
import pisi.ui import pisi.ui
from pisi.version import Version from pisi.version import Version
#import conflicts
class Error(pisi.Error): class Error(pisi.Error):
pass pass
@@ -268,6 +266,7 @@ class Install(AtomicOperation):
ctx.ui.notify(pisi.ui.extracting, package = self.pkginfo, files = self.files) ctx.ui.notify(pisi.ui.extracting, package = self.pkginfo, files = self.files)
config_changed = []
if self.reinstall: if self.reinstall:
# remove left over files # remove left over files
new = set(map(lambda x: str(x.path), self.files.list)) new = set(map(lambda x: str(x.path), self.files.list))
@@ -276,12 +275,47 @@ class Install(AtomicOperation):
old_fileinfo = {} old_fileinfo = {}
for fileinfo in self.old_files.list: for fileinfo in self.old_files.list:
old_fileinfo[str(fileinfo.path)] = fileinfo old_fileinfo[str(fileinfo.path)] = fileinfo
for path in old: for path in leftover:
if path in leftover or old_fileinfo[path].type == ctx.const.conf:
Remove.remove_file( old_fileinfo[path] ) Remove.remove_file( old_fileinfo[path] )
# handle special cases for upgrades
overlap = old & new
self.files.list.sort(key=lambda x:x.path)
self.old_files.list.sort(key=lambda x:x.path)
def get_upgrades(list):
return filter(lambda x : str(x.path) in overlap, list)
(upgrade_new, upgrade_old) = map(get_upgrades, [self.files.list, self.old_files.list])
for newf, oldf in zip(upgrade_new, upgrade_old):
assert newf.path == oldf.path
if newf.type == 'config' and oldf.type == 'config': # config upgrade
fpath = pisi.util.join_path(ctx.config.dest_dir(), oldf.path)
if os.path.exists(fpath) and pisi.util.sha1_file(fpath) != oldf.hash:
# old config file changed, don't overwrite
config_changed.append(fpath)
if os.path.exists(fpath + '.old'):
os.unlink(fpath + '.old')
os.rename(fpath, fpath + '.old')
else:
# old config file not changed, overwrite
pass
else:
for file in self.files.list:
if file.type == 'config':
fpath = pisi.util.join_path(ctx.config.dest_dir(), file.path)
if os.path.exists(fpath): # there is an old config file lying around
config_changed.append(fpath)
if os.path.exists(fpath + '.old'):
os.unlink(fpath + '.old')
os.rename(fpath, fpath + '.old')
self.package.extract_install(ctx.config.dest_dir()) self.package.extract_install(ctx.config.dest_dir())
for path in config_changed:
if os.path.exists(path + '.new'):
os.unlink(path + '.new')
os.rename(path, path + '.new')
os.rename(path + '.old', path)
def store_pisi_files(self): def store_pisi_files(self):
"""put files.xml, metadata.xml, actions.py and COMAR scripts """put files.xml, metadata.xml, actions.py and COMAR scripts
somewhere in the file system. We'll need these in future...""" somewhere in the file system. We'll need these in future..."""
@@ -415,14 +449,19 @@ class Remove(AtomicOperation):
ctx.ui.notify(pisi.ui.removed, package = self.package, files = self.files) ctx.ui.notify(pisi.ui.removed, package = self.package, files = self.files)
def check_dependencies(self): def check_dependencies(self):
#FIXME: why is this not implemented? -- exa
#we only have to check the dependencies to ensure the #we only have to check the dependencies to ensure the
#system will be consistent after this removal #system will be consistent after this removal
pass pass
# is there any package who depends on this package? # is there any package who depends on this package?
@staticmethod
def remove_file(fileinfo): def remove_file(fileinfo):
fpath = pisi.util.join_path(ctx.config.dest_dir(), fileinfo.path) fpath = pisi.util.join_path(ctx.config.dest_dir(), fileinfo.path)
# FIXME: the following is obsolete becuase --ignore-file-conflicts
# is just a workaround that will be removed soon. --exa
# we should check if the file is also provided by another # we should check if the file is also provided by another
# package (this is clearly the package's fault but we # package (this is clearly the package's fault but we
# shouldn't left system in an inconsistent state). # shouldn't left system in an inconsistent state).
@@ -432,17 +471,14 @@ class Remove(AtomicOperation):
ctx.ui.warning(_('Not removing conflicted file : %s') % fpath) ctx.ui.warning(_('Not removing conflicted file : %s') % fpath)
return return
# TODO: We have to store configuration files for futher
# usage. Currently we'are doing it like rpm does, saving
# with a prefix and leaving the user to edit it. In the future
# we'll have a plan for these configuration files.
if fileinfo.permanent: if fileinfo.permanent:
# do not remove precious files :) # do not remove precious files :)
# just write anything permanent="true" for instance pass
return elif fileinfo.type == ctx.const.conf:
if fileinfo.type == ctx.const.conf: # config files are precious, leave them as they are
if os.path.isfile(fpath): # unless they are the same as provided by package.
os.rename(fpath, fpath + ".oldconfig") if os.path.exists(fpath) and pisi.util.sha1_file(fpath) == fileinfo.hash:
os.unlink(fpath)
else: else:
if os.path.isfile(fpath) or os.path.islink(fpath): if os.path.isfile(fpath) or os.path.islink(fpath):
os.unlink(fpath) os.unlink(fpath)
@@ -458,8 +494,6 @@ class Remove(AtomicOperation):
os.rmdir(dpath) os.rmdir(dpath)
dpath = os.path.dirname(dpath) dpath = os.path.dirname(dpath)
remove_file = staticmethod(remove_file)
def run_preremove(self): def run_preremove(self):
if ctx.comar and self.package.providesComar: if ctx.comar and self.package.providesComar:
import pisi.comariface as comariface import pisi.comariface as comariface
@@ -471,7 +505,7 @@ class Remove(AtomicOperation):
else: else:
raise e raise e
else: else:
# TODO: store this somewhere # FIXME: store this somewhere
pass pass
def remove_pisi_files(self): def remove_pisi_files(self):
+2 -2
View File
@@ -58,8 +58,8 @@ def read_env_d(envdir):
# skip backup and version control files # skip backup and version control files
if name.endswith("~") or name.endswith(".bak") or name.endswith(",v"): if name.endswith("~") or name.endswith(".bak") or name.endswith(",v"):
continue continue
# skip pisi's .oldconfig files # skip pisi's new config files
if name.endswith(".oldconfig"): if name.endswith(".new"):
continue continue
paths.append(path) paths.append(path)
paths.sort() paths.sort()