1 |
commit: b0c535b7310e7724d8feb0570b827d38c5d17fc3 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Jul 31 21:40:53 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jul 31 22:00:21 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b0c535b7 |
7 |
|
8 |
HardlinkRcuRepoStorage: handle removed sync-rcu-store-dir (bug 734990) |
9 |
|
10 |
If SyncManager.pre_sync creates an empty directory where |
11 |
self._latest_symlink is suppose to be (which is normal if |
12 |
sync-rcu-store-dir has been removed), then we need to remove |
13 |
the directory or else rename will raise IsADirectoryError |
14 |
when we try to replace the directory with a symlink. |
15 |
|
16 |
Bug: https://bugs.gentoo.org/734990 |
17 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
18 |
|
19 |
lib/portage/repository/storage/hardlink_rcu.py | 13 ++++++++++++- |
20 |
lib/portage/tests/sync/test_sync_local.py | 10 ++++++++-- |
21 |
2 files changed, 20 insertions(+), 3 deletions(-) |
22 |
|
23 |
diff --git a/lib/portage/repository/storage/hardlink_rcu.py b/lib/portage/repository/storage/hardlink_rcu.py |
24 |
index 80cdbb0d7..bb2c8496b 100644 |
25 |
--- a/lib/portage/repository/storage/hardlink_rcu.py |
26 |
+++ b/lib/portage/repository/storage/hardlink_rcu.py |
27 |
@@ -1,4 +1,4 @@ |
28 |
-# Copyright 2018 Gentoo Foundation |
29 |
+# Copyright 2018-2020 Gentoo Authors |
30 |
# Distributed under the terms of the GNU General Public License v2 |
31 |
|
32 |
import datetime |
33 |
@@ -204,6 +204,17 @@ class HardlinkRcuRepoStorage(RepoStorageInterface): |
34 |
except OSError: |
35 |
pass |
36 |
os.symlink('snapshots/{}'.format(new_id), new_symlink) |
37 |
+ |
38 |
+ # If SyncManager.pre_sync creates an empty directory where |
39 |
+ # self._latest_symlink is suppose to be (which is normal if |
40 |
+ # sync-rcu-store-dir has been removed), then we need to remove |
41 |
+ # the directory or else rename will raise IsADirectoryError |
42 |
+ # when we try to replace the directory with a symlink. |
43 |
+ try: |
44 |
+ os.rmdir(self._latest_symlink) |
45 |
+ except OSError: |
46 |
+ pass |
47 |
+ |
48 |
os.rename(new_symlink, self._latest_symlink) |
49 |
|
50 |
try: |
51 |
|
52 |
diff --git a/lib/portage/tests/sync/test_sync_local.py b/lib/portage/tests/sync/test_sync_local.py |
53 |
index 08dd4fe57..efd61aac8 100644 |
54 |
--- a/lib/portage/tests/sync/test_sync_local.py |
55 |
+++ b/lib/portage/tests/sync/test_sync_local.py |
56 |
@@ -1,4 +1,4 @@ |
57 |
-# Copyright 2014-2015 Gentoo Foundation |
58 |
+# Copyright 2014-2020 Gentoo Authors |
59 |
# Distributed under the terms of the GNU General Public License v2 |
60 |
|
61 |
import datetime |
62 |
@@ -71,6 +71,7 @@ class SyncLocalTestCase(TestCase): |
63 |
distdir = os.path.join(eprefix, "distdir") |
64 |
repo = settings.repositories["test_repo"] |
65 |
metadata_dir = os.path.join(repo.location, "metadata") |
66 |
+ rcu_store_dir = os.path.join(eprefix, 'var/repositories/test_repo_rcu_storedir') |
67 |
|
68 |
cmds = {} |
69 |
for cmd in ("emerge", "emaint"): |
70 |
@@ -191,6 +192,10 @@ class SyncLocalTestCase(TestCase): |
71 |
(homedir, lambda: os.mkdir(repo.user_location)), |
72 |
) |
73 |
|
74 |
+ delete_rcu_store_dir = ( |
75 |
+ (homedir, lambda: shutil.rmtree(rcu_store_dir)), |
76 |
+ ) |
77 |
+ |
78 |
revert_rcu_layout = ( |
79 |
(homedir, lambda: os.rename(repo.user_location, repo.user_location + '.bak')), |
80 |
(homedir, lambda: os.rename(os.path.realpath(repo.user_location + '.bak'), repo.user_location)), |
81 |
@@ -289,7 +294,8 @@ class SyncLocalTestCase(TestCase): |
82 |
for cwd, cmd in rename_repo + sync_cmds_auto_sync + sync_cmds + \ |
83 |
rsync_opts_repos + rsync_opts_repos_default + \ |
84 |
rsync_opts_repos_default_ovr + rsync_opts_repos_default_cancel + \ |
85 |
- bump_timestamp_cmds + sync_rsync_rcu + sync_cmds + revert_rcu_layout + \ |
86 |
+ bump_timestamp_cmds + sync_rsync_rcu + sync_cmds + delete_rcu_store_dir + \ |
87 |
+ sync_cmds + revert_rcu_layout + \ |
88 |
delete_repo_location + sync_cmds + sync_cmds + \ |
89 |
bump_timestamp_cmds + sync_cmds + revert_rcu_layout + \ |
90 |
delete_sync_repo + git_repo_create + sync_type_git + \ |