1 |
commit: c446394e5b0e71a611ed5cfa0fb923e05802ef5f |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Oct 6 01:21:58 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Oct 6 01:35:09 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c446394e |
7 |
|
8 |
movefile: remove dest_tmp_bytes on failure |
9 |
|
10 |
Reported-by: Boleyn Su <boleyn.su <AT> gmail.com> |
11 |
Bug: https://bugs.gentoo.org/745588 |
12 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
13 |
|
14 |
lib/portage/util/movefile.py | 10 ++++++++-- |
15 |
1 file changed, 8 insertions(+), 2 deletions(-) |
16 |
|
17 |
diff --git a/lib/portage/util/movefile.py b/lib/portage/util/movefile.py |
18 |
index a251d369d..9c6054209 100644 |
19 |
--- a/lib/portage/util/movefile.py |
20 |
+++ b/lib/portage/util/movefile.py |
21 |
@@ -262,6 +262,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
22 |
dest_tmp = dest + "#new" |
23 |
dest_tmp_bytes = _unicode_encode(dest_tmp, encoding=encoding, |
24 |
errors='strict') |
25 |
+ success = False |
26 |
try: # For safety copy then move it over. |
27 |
_copyfile(src_bytes, dest_tmp_bytes) |
28 |
_apply_stat(sstat, dest_tmp_bytes) |
29 |
@@ -281,13 +282,18 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
30 |
raise |
31 |
_rename(dest_tmp_bytes, dest_bytes) |
32 |
_os.unlink(src_bytes) |
33 |
- except SystemExit as e: |
34 |
- raise |
35 |
+ success = True |
36 |
except Exception as e: |
37 |
writemsg("!!! %s\n" % _('copy %(src)s -> %(dest)s failed.') % |
38 |
{"src": src, "dest": dest}, noiselevel=-1) |
39 |
writemsg("!!! %s\n" % (e,), noiselevel=-1) |
40 |
return None |
41 |
+ finally: |
42 |
+ if not success: |
43 |
+ try: |
44 |
+ _os.unlink(dest_tmp_bytes) |
45 |
+ except OSError: |
46 |
+ pass |
47 |
else: |
48 |
#we don't yet handle special, so we need to fall back to /bin/mv |
49 |
a = spawn([MOVE_BINARY, '-f', src, dest], env=os.environ) |