This file is indexed.

/usr/share/pyshared/desktopcouch/application/platform/windows/base_dirs.py is in python-desktopcouch-application 1.0.8-0ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
# Copyright 2011 Canonical Ltd.
#
# This file is part of desktopcouch.
#
#  desktopcouch is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# desktopcouch is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with desktopcouch.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Manuel de la Pena <manuel.delapena@canonical.com>
"""Base dir implementation on windows."""

import logging
import os
import sys

SHELL_FOLDERS_KEY = \
    r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'


# error W0702 is disable so that the tests can be ran on linux
# pylint: disable=W0702
def _get_special_folders(registry=None):
    """Grab all the windows shell folder locations from the registry."""
    if not registry:
        # pylint: disable=F0401
        import _winreg as registry
        # pylint: enable=F0401
    result = {}
    try:
        hive = registry.ConnectRegistry(None, registry.HKEY_CURRENT_USER)
    except:
        logging.warn('Cannot connect to registry hive HKEY_CURRENT_USER.')
        return {}
    # open the registry key where Windows stores the shell folder locations
    try:
        key = registry.OpenKey(hive, SHELL_FOLDERS_KEY)
    except:
        registry.CloseKey(hive)
        logging.warn('Cannot open registry key %s', SHELL_FOLDERS_KEY)
        return {}
    # go though the shell folder and add them to the result
    try:
        for folder_index in range(0, registry.QueryInfoKey(key)[1]):
            folder_data = registry.EnumValue(key, folder_index)
            result[folder_data[0]] = folder_data[1]
    except:
        # do not return a partial result, log error and return empty dict
        logging.warn('Error when retrieving shell folders info')
        result = {}
    finally:
        # close used resource
        registry.CloseKey(key)
        registry.CloseKey(hive)
    return result


def _assert_not_illegal_chars(resource):
    """Assert that the resource has not illegal windows chars."""
    for illegal in '<>:"/\\|?*':
        assert illegal not in resource

# ensure that we are running on windows
if sys.platform == 'win32':
    SPECIAL_FOLDERS = _get_special_folders()

    # point the cache and the config folders to the correct location
    CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME',
        SPECIAL_FOLDERS['Local AppData'])
    CACHE_HOME = os.environ.get('XDG_CACHE_HOME',
        os.path.join(SPECIAL_FOLDERS['Local AppData'], 'Temp'))
    DATA_HOME = os.environ.get('XDG_DATA_HOME',
        SPECIAL_FOLDERS['Local AppData'])


def save_config_path(resource):
    """$XDG_CONFIG_HOME/<resource>/ exists, and return its path."""
    _assert_not_illegal_chars(resource)
    path = os.path.join(CONFIG_HOME, resource)
    if not os.path.isdir(path):
        os.makedirs(path, 0700)
    return path


def save_data_path(resource):
    """Ensure $XDG_DATA_HOME/<resource>/ exists, and return its path."""
    _assert_not_illegal_chars(resource)
    path = os.path.join(DATA_HOME, resource)
    if not os.path.isdir(path):
        os.makedirs(path)
    return path


def load_config_paths(ctx):
    """Load config desktopcouch config path and given ctx."""
    yield ctx.config_dir
    for config_dir in os.environ.get('XDG_CONFIG_DIRS',
        os.path.join(CONFIG_HOME, 'xdg')).split(':'):
        path = os.path.join(config_dir, "desktop-couch")
        if os.path.exists(path):
            yield path