Skip to content

Commit

Permalink
fix: file executable permissions check error on macos in docker conta…
Browse files Browse the repository at this point in the history
…iner

 On macOS Sonoma v14.5, it was discovered that when using avocado in a Docker container to run scripts without execute permissions, they are considered to have executable permissions.

By directly reading the file's permission bits, the `stat` method can provide more accurate permission check results, especially in cases where user context and file system characteristics might affect the behavior of `os.access`. This method is closer to the underlying implementation of the file system, thus providing consistent results across different environments (such as inside and outside Docker containers). After entering the container using `docker exec -it container bash`, use the `stat` command to check the file permission bits.

 Reference: #5945
Signed-off-by:  Kui Li <[email protected]>
  • Loading branch information
eeslook committed Jun 1, 2024
1 parent 69d34a9 commit 6ef2807
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion avocado/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import glob
import os
import stat
from enum import Enum

from avocado.core.enabled_extension_manager import EnabledExtensionManager
Expand Down Expand Up @@ -196,7 +197,16 @@ def check_file(
info=f'File "{path}" does not exist or is not a {type_name}',
)

if not os.access(path, access_check):
st = os.stat(path)
access_flags = 0
if access_check & os.R_OK:
access_flags |= (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
if access_check & os.W_OK:
access_flags |= (stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
if access_check & os.X_OK:
access_flags |= (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

if not bool(st.st_mode & access_flags):
return ReferenceResolution(
reference,
ReferenceResolutionResult.NOTFOUND,
Expand Down

0 comments on commit 6ef2807

Please sign in to comment.