Esempio n. 1
0
            public void Apply()
            {
                if (!_directoryFullPath.StartsWithIgnoreCase(_rootDirectory))
                {
                    return;
                }

                Queue <string> directories = new Queue <string>();

                directories.Enqueue(_directoryFullPath);

                while (directories.Count > 0)
                {
                    var directoryPath         = directories.Dequeue();
                    var directory             = _fileSystem.GetDirectoryInfo(directoryPath);
                    var relativeDirectoryPath = PathHelper.MakeRelative(_rootDirectory, directoryPath);

                    if (!directory.Exists)
                    {
                        continue;
                    }

                    // We don't want to add root directory
                    if (!string.IsNullOrEmpty(relativeDirectoryPath))
                    {
                        relativeDirectoryPath = PathHelper.EnsureTrailingSlash(relativeDirectoryPath);

                        // We don't add symlinks
                        if (directory.Attributes.HasFlag(FileAttributes.ReparsePoint))
                        {
                            continue;
                        }

                        if (!_fileSystemFilter.IsDirectoryAllowed(relativeDirectoryPath, directory.Attributes))
                        {
                            continue;
                        }

                        _entries.AddDirectory(relativeDirectoryPath);
                    }

                    foreach (var entry in directory.EnumerateFileSystemInfos())
                    {
                        if (entry is IDirectoryInfo)
                        {
                            directories.Enqueue(entry.FullName);
                        }
                        else
                        {
                            var relativeFilePath = PathHelper.MakeRelative(_rootDirectory, entry.FullName);

                            if (_fileSystemFilter.IsFileAllowed(relativeFilePath, entry.Attributes))
                            {
                                _entries.AddFile(relativeFilePath);
                            }
                        }
                    }
                }
            }
Esempio n. 2
0
 private static bool IsFileAllowed(string rootDirectory, string fullPath,
                                   IFileSystem fileSystem, IMsBuildFileSystemFilter filter,
                                   out string relativePath, out string shortRelativePath)
 {
     relativePath      = null;
     shortRelativePath = null;
     if (fullPath.StartsWithIgnoreCase(rootDirectory))
     {
         relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
         try {
             shortRelativePath = fileSystem.ToShortRelativePath(fullPath, rootDirectory);
             return(!string.IsNullOrEmpty(shortRelativePath) && filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath)));
         } catch (IOException) { } catch (UnauthorizedAccessException) { } // File isn't allowed if it isn't accessible
     }
     return(false);
 }
Esempio n. 3
0
        private static bool IsFileAllowed(string rootDirectory, string fullPath, IFileSystem fileSystem, IMsBuildFileSystemFilter filter, out string relativePath)
        {
            if (!fullPath.StartsWithIgnoreCase(rootDirectory))
            {
                relativePath = null;
                return(false);
            }

            relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
            try {
                return(filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath)));
            } catch (IOException) {
                // File isn't allowed if it isn't accessable
                return(false);
            }
        }
            public Delay50MsNoFiltering() {
                _fileSystem = Substitute.For<IFileSystem>();
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                _fileSystemFilter = Substitute.For<IMsBuildFileSystemFilter>();
                _fileSystemFilter.IsFileAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);
                _fileSystemFilter.IsDirectoryAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 50, 50, _fileSystem, _fileSystemFilter, Substitute.For<IActionLog>(), _taskScheduler);
                _taskScheduler.Link(_fileSystemWatcher.SourceBlock, c => { _changeset = c; });

                _fileSystemWatcher.Start();
                _fileWatcher = watchers.FileWatcher;
                _directoryWatcher = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
Esempio n. 5
0
            public Delay50MsNoFiltering()
            {
                _fileSystem = Substitute.For <IFileSystem>();
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                _fileSystemFilter = Substitute.For <IMsBuildFileSystemFilter>();
                _fileSystemFilter.IsFileAllowed(Arg.Any <string>(), Arg.Any <FileAttributes>()).ReturnsForAnyArgs(true);
                _fileSystemFilter.IsDirectoryAllowed(Arg.Any <string>(), Arg.Any <FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 50, 50, _fileSystem, _fileSystemFilter, Substitute.For <IActionLog>(), _taskScheduler);
                _taskScheduler.Link(_fileSystemWatcher.SourceBlock, c => { _changeset = c; });

                _fileSystemWatcher.Start();
                _fileWatcher       = watchers.FileWatcher;
                _directoryWatcher  = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
        private static bool IsFileAllowed(string rootDirectory, string fullPath, IFileSystem fileSystem, IMsBuildFileSystemFilter filter, out string relativePath) {
            if (!fullPath.StartsWithIgnoreCase(rootDirectory)) {
                relativePath = null;
                return false;
            }

            relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
            try {
                return filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath));
            } catch (IOException) {
                // File isn't allowed if it isn't accessable
                return false;
            }
        }
Esempio n. 7
0
 private static bool IsFileAllowed(string rootDirectory, string fullPath,
     IFileSystem fileSystem, IMsBuildFileSystemFilter filter,
     out string relativePath, out string shortRelativePath) {
     relativePath = null;
     shortRelativePath = null;
     if (fullPath.StartsWithIgnoreCase(rootDirectory)) {
         relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
          try {
             shortRelativePath = fileSystem.ToShortRelativePath(fullPath, rootDirectory);
             return !string.IsNullOrEmpty(shortRelativePath) && filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath));
         } catch (IOException) { } catch (UnauthorizedAccessException) { } // File isn't allowed if it isn't accessible
     }
     return false;
 }