Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r14485 - main/trunk/pym/portage/dbapi
Date: Sat, 03 Oct 2009 22:27:21
Message-Id: E1MuD4N-00013p-8O@stork.gentoo.org
1 Author: zmedico
2 Date: 2009-10-03 22:27:11 +0000 (Sat, 03 Oct 2009)
3 New Revision: 14485
4
5 Modified:
6 main/trunk/pym/portage/dbapi/vartree.py
7 Log:
8 Generate an eerror message in dblink.mergeme when a file has to be renamed in
9 order to merge a directory to the same path.
10
11
12 Modified: main/trunk/pym/portage/dbapi/vartree.py
13 ===================================================================
14 --- main/trunk/pym/portage/dbapi/vartree.py 2009-10-03 21:07:27 UTC (rev 14484)
15 +++ main/trunk/pym/portage/dbapi/vartree.py 2009-10-03 22:27:11 UTC (rev 14485)
16 @@ -3963,6 +3963,26 @@
17
18 return os.EX_OK
19
20 + def _new_backup_path(self, p):
21 + """
22 + The works for any type path, such as a regular file, symlink,
23 + or directory. The parent directory is assumed to exist.
24 + The returned filename is of the form p + '.backup.' + x, where
25 + x guarantees that the returned path does not exist yet.
26 + """
27 + os = _os_merge
28 +
29 + x = -1
30 + while True:
31 + x += 1
32 + backup_p = p + '.backup.' + str(x).rjust(4, '0')
33 + try:
34 + os.lstat(backup_p)
35 + except OSError:
36 + break
37 +
38 + return backup_p
39 +
40 def mergeme(self, srcroot, destroot, outfile, secondhand, stufftomerge, cfgfiledict, thismtime):
41 """
42
43 @@ -4120,7 +4140,16 @@
44 bsd_chflags.lchflags(mydest, dflags)
45 else:
46 # a non-directory and non-symlink-to-directory. Won't work for us. Move out of the way.
47 - if movefile(mydest, mydest+".backup",
48 + backup_dest = self._new_backup_path(mydest)
49 + msg = []
50 + msg.append("")
51 + msg.append("Installation of a directory is blocked by a file:")
52 + msg.append(" '%s'" % mydest)
53 + msg.append("This file will be renamed to a different name:")
54 + msg.append(" '%s'" % backup_dest)
55 + msg.append("")
56 + self._eerror("preinst", msg)
57 + if movefile(mydest, backup_dest,
58 mysettings=self.settings,
59 encoding=_encodings['merge']) is None:
60 return 1
61 @@ -4164,7 +4193,7 @@
62
63 if stat.S_ISDIR(mydmode):
64 # install of destination is blocked by an existing directory with the same name
65 - newdest = new_protect_filename(mydest, newmd5=mymd5)
66 + newdest = self._new_backup_path(mydest)
67 msg = []
68 msg.append("")
69 msg.append("Installation of a regular file is blocked by a directory:")