public override int GetHashCode() { if (_parent == null) { return(0); } return(HashCode.Combine(_parent.GetHashCode(), SystemPathComparer.GetHashCode(_name))); }
public RelativeDirectoryName(DirectoryName parent, string name) { Invariants.CheckArgumentNotNull(parent, nameof(parent)); Invariants.CheckArgumentNotNull(name, nameof(name), "Directory name is empty"); Invariants.CheckArgument(PathHelpers.IsFileName(name), nameof(name), "Directory name contains one or more directory separator"); _parent = parent; _name = name; _hashCode = HashCode.Combine(_parent.GetHashCode(), SystemPathComparer.GetHashCode(_name)); }
public int CompareTo(FileName other) { var result = _parent.CompareTo(other._parent); if (result == 0) { result = SystemPathComparer.CompareNames(_name, other._name); } return(result); }
private DirectorySnapshot FindDirectorySnapshot(FullPath directoryPath, ProjectRootSnapshot projectSnapshot) { var splitPath = PathHelpers.SplitPrefix(directoryPath.Value, projectSnapshot.Project.RootPath.Value); var current = projectSnapshot.Directory; foreach (var name in PathHelpers.SplitPath(splitPath.Suffix)) { current = current.ChildDirectories .FirstOrDefault(x => SystemPathComparer.EqualsNames(name, x.DirectoryName.Name)); if (current == null) { return(null); } } return(current); }
public DirectoryMock AddDirectory(string name) { // Only the root directory can contain directory separators. if (!IsRoot) { if (name.IndexOf(Path.DirectorySeparatorChar) >= 0) { throw new ArgumentException(); } } var dir = _directories.FirstOrDefault(x => SystemPathComparer.EqualsNames(x.Name, name)); if (dir == null) { dir = new DirectoryMock(this, name); _directories.Add(dir); } return(dir); }
public int CompareSameDistance(DirectoryName x, DirectoryName y) { if (ReferenceEquals(x, y)) { return(0); } var xabs = x as AbsoluteDirectoryName; var yabs = y as AbsoluteDirectoryName; if (xabs != null || yabs != null) { Invariants.Assert(xabs != null && yabs != null); return(xabs.FullPath.CompareTo(yabs.FullPath)); } var result = CompareSameDistance(x.Parent, y.Parent); if (result == 0) { result = SystemPathComparer.CompareNames(x.Name, y.Name); } return(result); }
public bool Equals(DirectoryName x, DirectoryName y) { if (ReferenceEquals(x, y)) { return(true); } if (x == null || y == null) { return(false); } var xabs = x as AbsoluteDirectoryName; var yabs = y as AbsoluteDirectoryName; if (xabs != null || yabs != null) { if (xabs == null) { return(false); } if (yabs == null) { return(false); } return(xabs.FullPath.Equals(yabs.FullPath)); } var result = Equals(x.Parent, y.Parent); if (result) { result = SystemPathComparer.EqualsNames(x.Name, y.Name); } return(result); }
private static DirectorySnapshot FindDirectorySnapshot(ProjectRootSnapshot project, string relativePath) { if (project == null) { return(null); } var entry = project.Directory; foreach (var name in PathHelpers.SplitPath(relativePath)) { var child = entry.ChildDirectories.FirstOrDefault(x => SystemPathComparer.EqualsNames(x.DirectoryName.Name, name)); if (child == null) { entry = null; break; } entry = child; } return(entry); }
private DirectorySnapshot ApplyDirectorySnapshotDelta(DirectorySnapshot oldDirectory) { var oldDirectoryPath = oldDirectory.DirectoryName.RelativePath; // Create lists of created dirs and files. We have to access the file system to know // if each path is a file or a directory. List <IFileInfoSnapshot> createDirs = null; List <IFileInfoSnapshot> createdFiles = null; foreach (var path in _pathChanges.GetCreatedEntries(oldDirectoryPath).ToForeachEnum()) { _cancellationToken.ThrowIfCancellationRequested(); // cancellation var info = _fileSystem.GetFileInfoSnapshot(_project.RootPath.Combine(path)); if (info.IsDirectory) { if (createDirs == null) { createDirs = new List <IFileInfoSnapshot>(); } createDirs.Add(info); } else if (info.IsFile) { if (createdFiles == null) { createdFiles = new List <IFileInfoSnapshot>(); } createdFiles.Add(info); } } // Recursively create new directory entires for previous (non deleted) // entries. var childDirectories = oldDirectory.ChildDirectories .Where(dir => !_pathChanges.IsDeleted(dir.DirectoryName.RelativePath)) .Select(dir => ApplyDirectorySnapshotDelta(dir)) .ToList(); // Add created directories if (createDirs != null) { foreach (var info in createDirs.ToForeachEnum()) { _cancellationToken.ThrowIfCancellationRequested(); // cancellation var createdDirectoryName = _fileSystemNameFactory.CreateDirectoryName(oldDirectory.DirectoryName, info.Path.FileName); var childSnapshot = CreateDirectorySnapshot(createdDirectoryName, info.IsSymLink); // Note: File system change notifications are not always 100% // reliable. We may get a "create" event for directory we already know // about. var index = childDirectories.FindIndex(x => SystemPathComparer.EqualsNames(x.DirectoryName.Name, createdDirectoryName.Name)); if (index >= 0) { childDirectories.RemoveAt(index); } childDirectories.Add(childSnapshot); } // We need to re-sort the array since we added new entries childDirectories.Sort((x, y) => SystemPathComparer.Compare(x.DirectoryName.Name, y.DirectoryName.Name)); } // Match non deleted files // Sepcial case: if no file deleted or created, just re-use the list. IList <FileName> newFileList; if (_pathChanges.GetDeletedEntries(oldDirectoryPath).Count == 0 && createdFiles == null) { newFileList = oldDirectory.ChildFiles; } else { // Copy the list of previous children, minus deleted files. var newFileListTemp = oldDirectory.ChildFiles .Where(x => !_pathChanges.IsDeleted(x.RelativePath)) .ToList(); // Add created files if (createdFiles != null) { foreach (var info in createdFiles.ToForeachEnum()) { var name = _fileSystemNameFactory.CreateFileName(oldDirectory.DirectoryName, info.Path.FileName); newFileListTemp.Add(name); } // We need to re-sort the array since we added new entries newFileListTemp.Sort((x, y) => SystemPathComparer.Compare(x.Name, y.Name)); // Note: File system change notifications are not always 100% // reliable. We may get a "create" event for files we already know // about. ArrayUtilities.RemoveDuplicates(newFileListTemp, (x, y) => SystemPathComparer.EqualsNames(x.Name, y.Name)); } newFileList = newFileListTemp; } var newData = new DirectoryData(oldDirectory.DirectoryName, oldDirectory.IsSymLink); return(new DirectorySnapshot( newData, childDirectories.ToReadOnlyList(), newFileList.ToReadOnlyList())); }
public bool Equals(FileName other) { return(Equals(_parent, other._parent) && SystemPathComparer.EqualsNames(_name, other._name)); }