summaryrefslogtreecommitdiffstats
path: root/pym/portage_util.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-07-21 06:25:16 +0000
committerZac Medico <zmedico@gentoo.org>2006-07-21 06:25:16 +0000
commitb14f667e022812a69b1354d1d9612cf36e7ff1a7 (patch)
tree10f9cf7bc5804c06d895423fde0aa08433bd51b3 /pym/portage_util.py
parente5998321056d36efdc0f8c4d554f166c3516c438 (diff)
downloadportage-b14f667e022812a69b1354d1d9612cf36e7ff1a7.tar.gz
portage-b14f667e022812a69b1354d1d9612cf36e7ff1a7.tar.bz2
portage-b14f667e022812a69b1354d1d9612cf36e7ff1a7.zip
Move new_protect_filename from the core portage module to portage_util.
svn path=/main/trunk/; revision=3978
Diffstat (limited to 'pym/portage_util.py')
-rw-r--r--pym/portage_util.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/pym/portage_util.py b/pym/portage_util.py
index 8fa62c5a2..cf115d1e9 100644
--- a/pym/portage_util.py
+++ b/pym/portage_util.py
@@ -6,6 +6,7 @@ from portage_exception import PortageException, FileNotFound, \
OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem
import portage_exception
from portage_dep import isvalidatom
+import portage_checksum
import sys,string,shlex,os,errno
try:
@@ -853,3 +854,53 @@ class ConfigProtect(object):
#skip, it's in the mask
masked = len(pmpath)
return protected > masked
+
+def new_protect_filename(mydest, newmd5=None):
+ """Resolves a config-protect filename for merging, optionally
+ using the last filename if the md5 matches.
+ (dest,md5) ==> 'string' --- path_to_target_filename
+ (dest) ==> ('next', 'highest') --- next_target and most-recent_target
+ """
+
+ # config protection filename format:
+ # ._cfg0000_foo
+ # 0123456789012
+ prot_num = -1
+ last_pfile = ""
+
+ if len(mydest) == 0:
+ raise ValueError, "Empty path provided where a filename is required"
+ if mydest[-1] == os.path.sep: # XXX add better directory checking
+ raise ValueError, "Directory provided but this function requires a filename"
+ if not os.path.exists(mydest):
+ return mydest
+
+ real_filename = os.path.basename(mydest)
+ real_dirname = os.path.dirname(mydest)
+ for pfile in os.listdir(real_dirname):
+ if pfile[0:5] != "._cfg":
+ continue
+ if pfile[10:] != real_filename:
+ continue
+ try:
+ new_prot_num = int(pfile[5:9])
+ if new_prot_num > prot_num:
+ prot_num = new_prot_num
+ last_pfile = pfile
+ except ValueError:
+ continue
+ prot_num = prot_num + 1
+
+ new_pfile = normalize_path(os.path.join(real_dirname,
+ "._cfg" + str(prot_num).zfill(4) + "_" + real_filename))
+ old_pfile = normalize_path(os.path.join(real_dirname, last_pfile))
+ if last_pfile and newmd5:
+ if portage_checksum.perform_md5(
+ os.path.join(real_dirname, last_pfile)) == newmd5:
+ return old_pfile
+ else:
+ return new_pfile
+ elif newmd5:
+ return new_pfile
+ else:
+ return (new_pfile, old_pfile)