private static void InternalCopyTo(this RootedDirectory source, RootedDirectory destination) { destination.Create(); foreach (var file in source.Files()) { file.CopyTo(destination + file.FileName()); } foreach (var directory in source.Directories()) { directory.InternalCopyTo(destination + directory.LeafFolder()); } }
public void Setup() { _fileSystem = new MemoryFileSystem().WithDrives("c:", "d:"); _emptyDrive = _fileSystem.DriveDescribing("d:"); _nonExistingDrive = _fileSystem.DriveDescribing("e:"); _nonExistingDirectory = _fileSystem.DirectoryDescribing(@"c:\nonExistingDirectory"); var populate = new FileSystemBuilder(_fileSystem); _emptyDirectory = populate.WithDir(@"c:\emptyDirectory"); _nonEmptyDirectory = populate.WithDir(@"c:\crowdedDirectory"); populate.WithDir(@"c:\crowdedDirectory\first"); populate.WithDir(@"c:\crowdedDirectory\first\first"); populate.WithDir(@"c:\crowdedDirectory\second"); }
/// <summary> /// NOTE: Experimental. Subject to change. /// Copies the directory and all its contents to a new location. The new copy will have the name specified by /// the destination parameter. /// This operation is not atomic. This means that if the operation fails halfways (e.g. out of disk space) half /// of the destination files and directories will exist. /// </summary> /// TODO: Exceptions public static void CopyTo(this RootedDirectory me, RootedDirectory destination) { // TODO: Shouldn't me be IRootedDirectory? // TODO: Isn't it ok if destination exists? What if you want to copy c: to d:? me.VerifyOnSameFileSystemAs(destination); me.VerifyIsNotAFile(ThrowHelper.DirectoryNotFoundException("Can't copy the directory '{0}' since it denotes a file.", me)); me.VerifyIsADirectory(ThrowHelper.DirectoryNotFoundException("Can't copy the directory '{0}' since it does not exist.", me)); destination.Parent().VerifyIsADirectory(ThrowHelper.DirectoryNotFoundException("Can't copy the directory since the destination's parent directory '{0}' does not exist.", destination.Parent())); destination.VerifyIsNotAFile(ThrowHelper.IOException("Can't copy the directory to the destination '{0}' since a file with that name already exists.", destination)); destination.VerifyIsNotADirectory(ThrowHelper.IOException("Can't copy the directory to the destination '{0}' since a directory with that name already exists.", destination)); me.VerifyIsNotTheSameAs(destination, ThrowHelper.IOException("Can't copy the directory '{0}' since the source and destination denotes the same directory.", destination)); me.VerifyIsNotAParentOf(destination, ThrowHelper.IOException("Can't copy the directory to the destination '{0}' since it is located inside the source directory.", destination)); me.InternalCopyTo(destination); }
public void PopulateFileSystem() { FileSystem = CreateFileSystem(); _tempDir = FileSystem.DirectoryDescribingTemporaryDirectory() + RelativeDirectory.FromString("PopulatedFileSystem"); // Note: Must create file system from leaf to root since modifications to an item might modify the parent as well var populateFileSystem = new FileSystemBuilder(FileSystem, _tempDir); ExistingFile = populateFileSystem .WithFile(@"path\to\file.txt") .Containing(ExistingFileContents) .LastModifiedAt(ExistingFileLastWriteTime) .LastAccessedAt(ExistingFileLastAccessTime) .CreatedAt(ExistingFileCreationTime); ExistingEmptyFile = populateFileSystem .WithFile(@"path\to\file2.txt"); NonExistingFile = FileSystem.FileDescribing(InTemp(@"path\to\another.txt")); ExistingLeafDirectory = populateFileSystem .WithDir(@"path\to") .LastModifiedAt(ExistingLeafDirectoryLastWriteTime) .LastAccessedAt(ExistingLeafDirectoryLastAccessTime) .CreatedAt(ExistingLeafDirectoryCreationTime); ParentOfExistingLeafDirectory = populateFileSystem .WithDir(@"path") .LastModifiedAt(ParentOfExistingLeafDirectoryLastWriteTime) .LastAccessedAt(ParentOfExistingLeafDirectoryLastAccessTime) .CreatedAt(ParentOfExistingLeafDirectoryCreationTime); ExistingEmptyDirectory = populateFileSystem .WithDir(@"my\path"); ExistingEmptyDirectory2 = populateFileSystem .WithDir(@"my\other"); NonExistingDirectory = FileSystem.DirectoryDescribing(InTemp(@"another\path\to")); NonExistingDrive = FileSystem.DriveDescribing("z:"); }
private static void AssertEqualityEquals(RootedDirectory left, object right) { Assert.That(left.Equals(right), Is.True, string.Format("'{0}'.Equals('{1}')", left, right)); Assert.That(left.GetHashCode(), Is.EqualTo(right.GetHashCode()), string.Format("'{0}'.GetHashCode() == '{1}'.GetHashCode()", left, right)); }
private static void AssertOperatorNotEquals(RootedDirectory left, RootedDirectory right) { Assert.That(left == right, Is.False, string.Format("! '{0}' == '{1}'", left, right)); Assert.That(left != right, Is.True, string.Format("! '{0}' != '{1}'", left, right)); }
public FileSystemBuilder(IFileSystem fileSystem, RootedDirectory rootDir) { _fileSystem = fileSystem; _rootDir = rootDir; }
public FileSystemBuilder(IFileSystem fileSystem) { _fileSystem = fileSystem; _rootDir = null; }