1 |
Since hardlinks on sshfs do not have matching inode numbers, detect |
2 |
this behavior and use a simple stat call to detect if lock_path has |
3 |
been removed. |
4 |
|
5 |
Bug: https://bugs.gentoo.org/678218 |
6 |
Signed-off-by: Zac Medico <zmedico@g.o> |
7 |
--- |
8 |
lib/portage/locks.py | 27 +++++++++++++++++++++++++++ |
9 |
1 file changed, 27 insertions(+) |
10 |
|
11 |
diff --git a/lib/portage/locks.py b/lib/portage/locks.py |
12 |
index 74c2c086a..510925da0 100644 |
13 |
--- a/lib/portage/locks.py |
14 |
+++ b/lib/portage/locks.py |
15 |
@@ -340,6 +340,33 @@ def _lockfile_was_removed(lock_fd, lock_path): |
16 |
|
17 |
hardlink_stat = os.stat(hardlink_path) |
18 |
if hardlink_stat.st_ino != fstat_st.st_ino or hardlink_stat.st_dev != fstat_st.st_dev: |
19 |
+ # Create another hardlink in order to detect whether or not |
20 |
+ # hardlink inode numbers are expected to match. For example, |
21 |
+ # inode numbers are not expected to match for sshfs. |
22 |
+ inode_test = hardlink_path + '-inode-test' |
23 |
+ try: |
24 |
+ os.unlink(inode_test) |
25 |
+ except OSError as e: |
26 |
+ if e.errno not in (errno.ENOENT, errno.ESTALE): |
27 |
+ _raise_exc(e) |
28 |
+ try: |
29 |
+ os.link(hardlink_path, inode_test) |
30 |
+ except OSError as e: |
31 |
+ if e.errno not in (errno.ENOENT, errno.ESTALE): |
32 |
+ _raise_exc(e) |
33 |
+ return True |
34 |
+ else: |
35 |
+ if not os.path.samefile(hardlink_path, inode_test): |
36 |
+ # This implies that inode numbers are not expected |
37 |
+ # to match for this file system, so use a simple |
38 |
+ # stat call to detect if lock_path has been removed. |
39 |
+ return not os.path.exists(lock_path) |
40 |
+ finally: |
41 |
+ try: |
42 |
+ os.unlink(inode_test) |
43 |
+ except OSError as e: |
44 |
+ if e.errno not in (errno.ENOENT, errno.ESTALE): |
45 |
+ _raise_exc(e) |
46 |
return True |
47 |
finally: |
48 |
try: |
49 |
-- |
50 |
2.18.1 |