public override void Copy(string sourceFileName, string destFileName, bool overwrite) { if (sourceFileName == null) { throw new ArgumentNullException("sourceFileName", StringResources.Manager.GetString("FILENAME_CANNOT_BE_NULL")); } if (destFileName == null) { throw new ArgumentNullException("destFileName", StringResources.Manager.GetString("FILENAME_CANNOT_BE_NULL")); } VirtualFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, "sourceFileName"); VirtualFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, "destFileName"); var directoryNameOfDestination = VirtualPath.GetDirectoryName(destFileName); if (!VirtualFileDataAccessor.Directory.Exists(directoryNameOfDestination)) { throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("COULD_NOT_FIND_PART_OF_PATH_EXCEPTION"), destFileName)); } var fileExists = VirtualFileDataAccessor.FileExists(destFileName); if (fileExists) { if (!overwrite) { throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName)); } VirtualFileDataAccessor.RemoveFile(destFileName); } var sourceFile = VirtualFileDataAccessor.GetFile(sourceFileName); VirtualFileDataAccessor.AddFile(destFileName, sourceFile); }
public override void Delete(string path, bool recursive) { path = EnsurePathEndsWithDirectorySeparator(VirtualFileDataAccessor.Path.GetFullPath(path)); var affectedPaths = VirtualFileDataAccessor .AllPaths .Where(p => p.StartsWith(path, StringComparison.OrdinalIgnoreCase)) .ToList(); if (!affectedPaths.Any()) { throw new DirectoryNotFoundException(path + " does not exist or could not be found."); } if (!recursive && affectedPaths.Count > 1) { throw new IOException("The directory specified by " + path + " is read-only, or recursive is false and " + path + " is not an empty directory."); } foreach (var affectedPath in affectedPaths) { VirtualFileDataAccessor.RemoveFile(affectedPath); } }
public override void Delete() { VirtualFileSystem.RemoveFile(path); }