<commit_before># Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import grp
import os
import stat
import sys
import errno
import hashlib
import tempfile
import getpass
from six import string_types
from six import iteritems
from six.moves.urllib.parse import urljoin

import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp, can_access, install, install_tree
from llnl.util.filesystem import remove_linked_tree

import spack.paths
import spack.caches
import spack.config
import spack.error
import spack.util.lock
import spack.fetch_strategy as fs
import spack.util.pattern as pattern
import spack.util.path as sup
from spack.util.crypto import prefix_bits, bit_length


# The well-known stage source subdirectory name.
_source_path_subdir = 'spack-src'

# The temporary stage name prefix.
_stage_prefix = 'spack-stage-'


def _first_accessible_path(paths):
    """Find the first path that is accessible, creating it if necessary."""
    for path in paths:
        try:
            # Ensure the user has access, creating the directory if necessary.
            path = sup.canonicalize_path(path)
            if os.path.exists(path):
                if can_access(path):
                    return path
            else:
                # The path doesn't exist so create it and adjust permissions
                # and group as needed (e.g., shared ``$tempdir``).
                prefix = os.path.sep
                parts = path.strip(os.path.sep).split(os.path.sep)
                for part in parts:
                    prefix = os.path.join(prefix, part)
                    if not os.path.exists(prefix):
                        break
                parent = os.path.dirname(prefix)
                group = grp.getgrgid(os.stat(parent).st_gid)[0]
                mkdirp(path, group=group, default_perms='parents')

                if can_access(path):
                    return path
<commit_msg>stage: avoid using group name in _first_accessible_path()<commit_after># Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os
import stat
import sys
import errno
import hashlib
import tempfile
import getpass
from six import string_types
from six import iteritems
from six.moves.urllib.parse import urljoin

import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp, can_access, install, install_tree
from llnl.util.filesystem import remove_linked_tree

import spack.paths
import spack.caches
import spack.config
import spack.error
import spack.util.lock
import spack.fetch_strategy as fs
import spack.util.pattern as pattern
import spack.util.path as sup
from spack.util.crypto import prefix_bits, bit_length


# The well-known stage source subdirectory name.
_source_path_subdir = 'spack-src'

# The temporary stage name prefix.
_stage_prefix = 'spack-stage-'


def _first_accessible_path(paths):
    """Find the first path that is accessible, creating it if necessary."""
    for path in paths:
        try:
            # Ensure the user has access, creating the directory if necessary.
            path = sup.canonicalize_path(path)
            if os.path.exists(path):
                if can_access(path):
                    return path
            else:
                # The path doesn't exist so create it and adjust permissions
                # and group as needed (e.g., shared ``$tempdir``).
                prefix = os.path.sep
                parts = path.strip(os.path.sep).split(os.path.sep)
                for part in parts:
                    prefix = os.path.join(prefix, part)
                    if not os.path.exists(prefix):
                        break
                parent = os.path.dirname(prefix)
                gid = os.stat(parent).st_gid
                mkdirp(path, group=gid, default_perms='parents')

                if can_access(path):
                    return path

{'fraction_non_alphanumeric': 0.07405614714424008, 'fraction_numerical': 0.005082284607938045, 'mean_word_length': 2.415702479338843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '738409', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1127, 'n_words': 382}