Пример #1
0
        public string GetCacheFilePath(string filePath)
        {
            var name = PathUtils.GetFileName(filePath);

            if (!PathEqualityComparer.IsValidPath(name))
            {
                _log?.Log(TraceEventType.Warning, $"Invalid cache name: {name}");
                return(null);
            }
            try {
                var candidate = Path.ChangeExtension(Path.Combine(StubCacheFolder, name), ".pyi");
                if (_fs.FileExists(candidate))
                {
                    return(candidate);
                }
            } catch (ArgumentException) {
                return(null);
            }

            var dir = Path.GetDirectoryName(filePath) ?? string.Empty;

            if (_fs.StringComparison == StringComparison.OrdinalIgnoreCase)
            {
                dir = dir.ToLowerInvariant();
            }

            var dirHash  = CacheFolders.FileNameFromContent(dir);
            var stubFile = Path.Combine(StubCacheFolder, Path.Combine(dirHash, name));

            return(Path.ChangeExtension(stubFile, ".pyi"));
        }
Пример #2
0
        public StubCache(IServiceContainer services, string cacheRootFolder = null)
        {
            _fs  = services.GetService <IFileSystem>();
            _log = services.GetService <ILogger>();

            cacheRootFolder = cacheRootFolder ?? CacheFolders.GetCacheFolder(services);
            StubCacheFolder = Path.Combine(cacheRootFolder, $"stubs.v{_stubCacheFormatVersion}");
        }