private bool FileOrDirectoryExistsInLayer()

in simpleProviderManaged/SimpleProvider.cs [287:324]


        private bool FileOrDirectoryExistsInLayer(string layerParentPath, string layerName, out ProjectedFileInfo fileInfo)
        {
            fileInfo = null;

            // Check whether the parent directory exists in the layer.
            DirectoryInfo dirInfo = new DirectoryInfo(layerParentPath);
            if (!dirInfo.Exists)
            {
                return false;
            }

            // Get the FileSystemInfo for the entry in the layer that matches the name, using ProjFS's
            // name matching rules.
            FileSystemInfo fileSystemInfo =
                dirInfo
                .GetFileSystemInfos()
                .FirstOrDefault(fsInfo => Utils.IsFileNameMatch(fsInfo.Name, layerName));

            if (fileSystemInfo == null)
            {
                return false;
            }

            bool isDirectory = ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory);

            fileInfo = new ProjectedFileInfo(
                name: fileSystemInfo.Name,
                fullName: fileSystemInfo.FullName,
                size: isDirectory ? 0 : new FileInfo(Path.Combine(layerParentPath, layerName)).Length,
                isDirectory: isDirectory,
                creationTime: fileSystemInfo.CreationTime,
                lastAccessTime: fileSystemInfo.LastAccessTime,
                lastWriteTime: fileSystemInfo.LastWriteTime,
                changeTime: fileSystemInfo.LastWriteTime,
                attributes: fileSystemInfo.Attributes);

            return true;
        }