Skip to content

Commit fb6db40

Browse files
bonzinijpakkane
authored andcommitted
utils: make .wraplock optional
.wraplock is nice to have, but prevents Meson from operating on a read-only source directory. If the source directory is read-only, there is no possible conflict so in that case it is acceptable to return without any actual locking. Fixes: #14948 Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 191a315 commit fb6db40

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎mesonbuild/utils/platform.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ class DirectoryLockAction(enum.Enum):
2020
FAIL = 2
2121

2222
class DirectoryLockBase:
23-
def __init__(self, directory: str, lockfile: str, action: DirectoryLockAction, err: str) -> None:
23+
def __init__(self, directory: str, lockfile: str, action: DirectoryLockAction, err: str,
24+
optional: bool = False) -> None:
2425
self.action = action
2526
self.err = err
2627
self.lockpath = os.path.join(directory, lockfile)
28+
self.optional = optional
29+
self.lockfile: T.Optional[T.TextIO] = None
2730

2831
def __enter__(self) -> None:
2932
mlog.debug('Calling the no-op version of DirectoryLock')

‎mesonbuild/utils/posix.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
class DirectoryLock(DirectoryLockBase):
1818

1919
def __enter__(self) -> None:
20-
self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
20+
try:
21+
self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
22+
except (FileNotFoundError, IsADirectoryError):
23+
# For FileNotFoundError, there is nothing to lock.
24+
# For IsADirectoryError, something is seriously wrong.
25+
raise
26+
except OSError:
27+
if self.action == DirectoryLockAction.IGNORE or self.optional:
28+
return
29+
2130
try:
2231
flags = fcntl.LOCK_EX
2332
if self.action != DirectoryLockAction.WAIT:

‎mesonbuild/utils/win32.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
class DirectoryLock(DirectoryLockBase):
1818

1919
def __enter__(self) -> None:
20-
self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
20+
try:
21+
self.lockfile = open(self.lockpath, 'w+', encoding='utf-8')
22+
except (FileNotFoundError, IsADirectoryError):
23+
# For FileNotFoundError, there is nothing to lock.
24+
# For IsADirectoryError, something is seriously wrong.
25+
raise
26+
except OSError:
27+
if self.action == DirectoryLockAction.IGNORE or self.optional:
28+
return
29+
2130
try:
2231
mode = msvcrt.LK_LOCK
2332
if self.action != DirectoryLockAction.WAIT:

‎mesonbuild/wrap/wrap.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def resolve(self, packagename: str, force_method: T.Optional[Method] = None) ->
588588
try:
589589
with DirectoryLock(self.subdir_root, '.wraplock',
590590
DirectoryLockAction.WAIT,
591-
'Failed to lock subprojects directory'):
591+
'Failed to lock subprojects directory', optional=True):
592592
return self._resolve(packagename, force_method)
593593
except FileNotFoundError:
594594
raise WrapNotFoundException('Attempted to resolve subproject without subprojects directory present.')

0 commit comments

Comments
 (0)