python类W_OK的实例源码

filesystem.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
base.py 文件源码 项目:polyaxon-cli 作者: polyaxon 项目源码 文件源码 阅读 60 收藏 0 点赞 0 评论 0
def get_config_file_path(cls):
        if not cls.IS_GLOBAL:
            # local to this directory
            base_path = os.path.join('.')
        else:
            base_path = os.path.expanduser('~')
            if not os.access(base_path, os.W_OK):
                base_path = '/tmp'

            base_path = os.path.join(base_path, '.polyaxon')

            if not os.path.exists(base_path):
                try:
                    os.makedirs(base_path)
                except OSError:
                    # Except permission denied and potential race conditions
                    # in multi-threaded environments.
                    logger.error('Could not create config directory `{}`'.format(base_path))

        return os.path.join(base_path, cls.CONFIG_FILE_NAME)
update.py 文件源码 项目:factotum 作者: Denubis 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def safeInstall():
    FACTORIOPATH = getFactorioPath()

    try:
        if not os.path.isdir("%s" % (FACTORIOPATH) ):       

            if os.access("%s/.." % (FACTORIOPATH), os.W_OK):
                os.mkdir(FACTORIOPATH, 0o777)
            else:
                subprocess.call(['sudo', 'mkdir', '-p', FACTORIOPATH])
                subprocess.call(['sudo', 'chown', getpass.getuser(), FACTORIOPATH])


            os.mkdir(os.path.join(FACTORIOPATH, "saves"))
            os.mkdir(os.path.join(FACTORIOPATH, "config"))
            with open("%s/.bashrc" % (os.path.expanduser("~")), "r+") as bashrc:
                lines = bashrc.read()

                if lines.find("eval \"$(_FACTOTUM_COMPLETE=source factotum)\"\n") == -1:
                    bashrc.write("eval \"$(_FACTOTUM_COMPLETE=source factotum)\"\n")
                    print("You'll want to restart your shell for command autocompletion. Tab is your friend.")
        updateFactorio()
    except IOError as e:
        print("Cannot make %s. Please check permissions. Error %s" % (FACTORIOPATH, e))
        sys.exit(1)
filesystem.py 文件源码 项目:pip-update-requirements 作者: alanhamlett 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
client_api_test.py 文件源码 项目:TACTIC-Handler 作者: listyque 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def _test_resource_paths(my):
        path = my.server.get_resource_path('admin')
        # not a very accurate test
        my.assertEquals(True, 'etc/admin.tacticrc' in  path)

        paths = my.server.create_resource_paths()
        sys_login = getpass.getuser()
        dir = my.server.get_home_dir()
        is_dir_writeable = os.access(dir, os.W_OK) and os.path.isdir(dir)
        if dir and is_dir_writeable:
            dir = "%s/.tactic/etc" % dir
        else:
            if os.name == 'nt':
                dir = 'C:/sthpw/etc'
            else:
                dir = '/tmp/sthpw/etc'
        compared = '%s/%s.tacticrc' %(dir, sys_login) in paths
        my.assertEquals(True, compared)

        # since we use admin to get resource path , my.login should also be admin
        my.assertEquals('admin', my.server.get_login())
filesystem.py 文件源码 项目:swjtu-pyscraper 作者: Desgard 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 46 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
tools.py 文件源码 项目:sc-controller 作者: kozec 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def check_access(filename, write_required=True):
    """
    Checks if user has read and optionaly write access to specified file.
    Uses acl first and possix file permisions if acl cannot be used.
    Returns true only if user has both required access rights.
    """
    if HAVE_POSIX1E:
        for pset in posix1e.ACL(file=filename):
            if pset.tag_type == posix1e.ACL_USER and pset.qualifier == os.geteuid():
                if pset.permset.test(posix1e.ACL_READ) and (not write_required or pset.permset.test(posix1e.ACL_WRITE)):
                    return True
            if pset.tag_type == posix1e.ACL_GROUP and pset.qualifier in os.getgroups():
                if pset.permset.test(posix1e.ACL_READ) and (not write_required or pset.permset.test(posix1e.ACL_WRITE)):
                    return True
    if write_required:
        return os.access(filename, os.R_OK | os.W_OK)
    return os.access(filename, os.R_OK)
recorder.py 文件源码 项目:esys-pbi 作者: fsxfreak 项目源码 文件源码 阅读 151 收藏 0 点赞 0 评论 0
def verify_path(self, val):
        try:
            n_path = os.path.expanduser(val)
            logger.debug("Expanded user path.")
        except:
            n_path = val
        if not n_path:
            logger.warning("Please specify a path.")
            return False
        elif not os.path.isdir(n_path):
            logger.warning("This is not a valid path.")
            return False
        # elif not os.access(n_path, os.W_OK):
        elif not writable_dir(n_path):
            logger.warning("Do not have write access to '{}'.".format(n_path))
            return False
        else:
            return n_path
filesystem.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
preferences.py 文件源码 项目:software-boutique 作者: ubuntu-mate 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def save_to_disk(self):
        """
        Commit the data from memory to disk.
        Returns True or False depending on success/failure.
        """
        # Create file if it doesn't exist.
        if not os.path.exists(self.file_path):
            open(self.file_path, "w").close()

        # Write new data to specified file.
        if os.access(self.file_path, os.W_OK):
            f = open(self.file_path, "w+")
            f.write(json.dumps(self.data, sort_keys=True, indent=4))
            f.close()
            return True
        else:
            return False
filesystem.py 文件源码 项目:ascii-art-py 作者: blinglnav 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
test_path.py 文件源码 项目:scarlett_os 作者: bossjones 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def test_dir_isWritable(self, path_mocker_stopall):
        # mock
        mock_os_access = path_mocker_stopall.MagicMock(name="mock_os_access")
        mock_os_path_isdir = path_mocker_stopall.MagicMock(name="mock_os_path_isdir")
        # patch
        path_mocker_stopall.patch.object(scarlett_os.internal.path.os, 'access', mock_os_access)
        path_mocker_stopall.patch.object(scarlett_os.internal.path.os.path, 'isdir', mock_os_path_isdir)

        path = 'file:///tmp'

        # patch return values
        mock_os_path_isdir.return_value = True
        mock_os_access.return_value = True

        # run test
        result = s_path.isWritable(path)

        # tests
        mock_os_path_isdir.assert_called_once_with('file:///tmp')
        mock_os_access.assert_called_once_with('file:///tmp', os.W_OK)
        assert result == True
path.py 文件源码 项目:scarlett_os 作者: bossjones 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def isWritable(path):
    """Returns whether the file/path is writable."""
    try:
        if os.path.isdir(path):
            # The given path is an existing directory.
            # To properly check if it is writable, you need to use os.access.
            return os.access(path, os.W_OK)
        else:
            # The given path is supposed to be a file.
            # Avoid using open(path, "w"), as it might corrupt existing files.
            # And yet, even if the parent directory is actually writable,
            # open(path, "rw") will IOError if the file doesn't already exist.
            # Therefore, simply check the directory permissions instead:

            # path = 'file:///etc/fstab'
            # In [22]: os.path.dirname(path)
            # Out[22]: 'file:///etc'
            return os.access(os.path.dirname(path), os.W_OK)
            # In [23]: os.access(os.path.dirname(path), os.W_OK)
            # Out[23]: False
    except UnicodeDecodeError:
        unicode_error_dialog()
whoosh_cn_backend.py 文件源码 项目:dream_blog 作者: fanlion 项目源码 文件源码 阅读 64 收藏 0 点赞 0 评论 0
def setup(self):
        """
        Defers loading until needed.
        """
        from haystack import connections
        new_index = False

        # Make sure the index is there.
        if self.use_file_storage and not os.path.exists(self.path):
            os.makedirs(self.path)
            new_index = True

        if self.use_file_storage and not os.access(self.path, os.W_OK):
            raise IOError("The path to your Whoosh index '%s' is not writable for the current user/group." % self.path)

        if self.use_file_storage:
            self.storage = FileStorage(self.path)
        else:
            global LOCALS

            if getattr(LOCALS, 'RAM_STORE', None) is None:
                LOCALS.RAM_STORE = RamStorage()

            self.storage = LOCALS.RAM_STORE

        self.content_field_name, self.schema = self.build_schema(connections[self.connection_alias].get_unified_index().all_searchfields())
        self.parser = QueryParser(self.content_field_name, schema=self.schema)

        if new_index is True:
            self.index = self.storage.create_index(self.schema)
        else:
            try:
                self.index = self.storage.open_index(schema=self.schema)
            except index.EmptyIndexError:
                self.index = self.storage.create_index(self.schema)

        self.setup_complete = True
tool_wrapper.py 文件源码 项目:nojs 作者: chrisdickinson 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def ExecRecursiveMirror(self, source, dest):
    """Emulation of rm -rf out && cp -af in out."""
    if os.path.exists(dest):
      if os.path.isdir(dest):
        def _on_error(fn, path, dummy_excinfo):
          # The operation failed, possibly because the file is set to
          # read-only. If that's why, make it writable and try the op again.
          if not os.access(path, os.W_OK):
            os.chmod(path, stat.S_IWRITE)
          fn(path)
        shutil.rmtree(dest, onerror=_on_error)
      else:
        if not os.access(dest, os.W_OK):
          # Attempt to make the file writable before deleting it.
          os.chmod(dest, stat.S_IWRITE)
        os.unlink(dest)

    if os.path.isdir(source):
      shutil.copytree(source, dest)
    else:
      shutil.copy2(source, dest)
      # Try to diagnose crbug.com/741603
      if not os.path.exists(dest):
        raise Exception("Copying of %s to %s failed" % (source, dest))
iOSAppIconGenerator.py 文件源码 项目:iOSAppIconGenerator 作者: dorukgezici 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def run():
    if Data.image_path == "":
        output_label["text"] = "Choose the image file first."
        return
    if os.access("{}/AppIcon.appiconset".format(Data.save_path), os.W_OK) == False:
        os.mkdir("{}/AppIcon.appiconset".format(Data.save_path))
    file = open("{}/AppIcon.appiconset/Contents.json".format(Data.save_path), mode="w")
    json.dump(json_data, file, indent=4, sort_keys=True, separators=(',', ':'))
    file.close()

    with open("{}/AppIcon.appiconset/Contents.json".format(Data.save_path), mode="r") as data_file:
        data = json.load(data_file)
        images = data["images"]
        try:
            im = Image.open(Data.image_path)
            output_label["text"] = "Image specs: {} {} {}\n{}\n".format(im.format, im.size, im.mode, "-"*35)
            for image in images:
                size = get_size(image)
                out = im.resize(size, Image.ANTIALIAS)
                out.save("{}/AppIcon.appiconset/{}".format(Data.save_path, image["filename"]), format="PNG")
                output_label["text"] += "Image generated: {}\n".format(size)
            open_saved_button.grid(row=1, column=0, columnspan=2, sticky=tk.W+tk.E)
        except IOError:
            output_label["text"] = "Please select a supported image file."
filesystem.py 文件源码 项目:ivaochdoc 作者: ivaoch 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 73 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
merger.py 文件源码 项目:i3config_patcher 作者: David96 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def apply(self, software, theme):
        new_files = theme.files[software]
        files = self.get_supported_software()[software]
        for name, theme_path in new_files.items():
            if name in files:
                for orig_path in files[name]:
                    filename = os.path.expanduser(orig_path)
                    if os.access(filename, os.W_OK):
                        theme.themes.backup_if_necessary(software, name, filename)
                        # reload orig files because the original theme might have
                        # changed (in case a backup was necessary)
                        orig_files = theme.themes.original.files[software]
                        with open(filename, "w") as f:
                            logging.debug("Merging %s with %s" %
                                    (orig_files[name], theme_path))
                            f.writelines(self.merge(software, name,
                                        orig_files[name], theme_path))
                        break
cgroup.py 文件源码 项目:jd4 作者: vijos 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def try_init_cgroup():
    euid = geteuid()
    cgroups_to_init = list()
    if not (path.isdir(CPUACCT_CGROUP_ROOT) and access(CPUACCT_CGROUP_ROOT, W_OK)):
        cgroups_to_init.append(CPUACCT_CGROUP_ROOT)
    if not (path.isdir(MEMORY_CGROUP_ROOT) and access(MEMORY_CGROUP_ROOT, W_OK)):
        cgroups_to_init.append(MEMORY_CGROUP_ROOT)
    if not (path.isdir(PIDS_CGROUP_ROOT) and access(PIDS_CGROUP_ROOT, W_OK)):
        cgroups_to_init.append(PIDS_CGROUP_ROOT)
    if cgroups_to_init:
        if euid == 0:
            logger.info('Initializing cgroup: %s', ', '.join(cgroups_to_init))
            for cgroup_to_init in cgroups_to_init:
                makedirs(cgroup_to_init, exist_ok=True)
        elif __stdin__.isatty():
            logger.info('Initializing cgroup: %s', ', '.join(cgroups_to_init))
            call(['sudo', 'sh', '-c', 'mkdir -p "{1}" && chown -R "{0}" "{1}"'.format(
                euid, '" "'.join(cgroups_to_init))])
        else:
            logger.error('Cgroup not initialized')
filesystem.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)
filesystem.py 文件源码 项目:isni-reconcile 作者: cmh2166 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path)


问题


面经


文章

微信
公众号

扫码关注公众号