public void Configure(IBuilder app, ILibraryManager libManager, IApplicationShutdown shutdown) { var web = libManager.GetLibraryInformation("Runt.Web"); Console.WriteLine("Path: " + web.Path); Console.WriteLine("Name: " + web.Name); var fileSystem = new PhysicalFileSystem(Path.GetDirectoryName(web.Path)); app.UseServices(services => { services.AddSignalR(); services.AddSingleton<IEditor, Editor>(); }); app.UseSignalR("/io", typeof(RuntConnection), new ConnectionConfiguration { EnableJSONP = false }); app.UseDefaultFiles(new DefaultFilesOptions { FileSystem = fileSystem }); app.UseStaticFiles(new StaticFileOptions { FileSystem = fileSystem, ContentTypeProvider = contentTypeProvider, ServeUnknownFileTypes = true }); app.UseDirectoryBrowser(new DirectoryBrowserOptions { FileSystem = fileSystem }); }
public ExpiringFileInfoCache(IApplicationEnvironment env, IOptionsAccessor<MvcOptions> optionsAccessor) { // TODO: Inject the IFileSystem but only when we get it from the host _fileSystem = new PhysicalFileSystem(env.ApplicationBasePath); _offset = optionsAccessor.Options.ViewEngineOptions.ExpirationBeforeCheckingFilesOnDisk; }
public void MissingFilesReturnFalse() { var provider = new PhysicalFileSystem("."); IFileInfo info; provider.TryGetFileInfo("File5.txt", out info).ShouldBe(false); info.ShouldBe(null); }
private void GetPackageLocally(string packageId, string version, string workDirectory) { //Add the default source if there are none present var workingFileSystem = new PhysicalFileSystem(workDirectory); foreach (string source in Sources) { Uri uri; if (Uri.TryCreate(source, UriKind.Absolute, out uri)) { AggregateRepository repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(PackageRepositoryFactory.Default, CreateSourceProvider(new[] {source}), new[] {source}); IPackage package; if (repository.TryFindPackage(packageId, new Version(version), out package)) { Console.WriteLine("Attempting to download package {0}.{1} via {2}", packageId, version, uri.ToString()); try { string filepath = Path.Combine(workDirectory, package.Id + "-" + package.Version + ".nupkg"); workingFileSystem.AddFile(filepath, package.GetStream()); break; } catch (Exception e) { Console.WriteError(e); } } } } }
public void SubPathActsAsRoot() { var provider = new PhysicalFileSystem("sub"); IFileInfo info; provider.TryGetFileInfo("File2.txt", out info).ShouldBe(true); info.ShouldNotBe(null); }
public void ExistingFilesReturnTrue() { var provider = new PhysicalFileSystem("."); IFileInfo info; provider.TryGetFileInfo("File.txt", out info).ShouldBe(true); info.ShouldNotBe(null); }
private IEnumerable<ITaskItem> ResolvePackage(ITaskItem package) { string id = package.ItemSpec; string version = package.GetMetadata("Version"); Log.LogMessage(MessageImportance.Normal, "Resolving Package Reference {0} {1}...", id, version); // Initial version just searches a machine-level repository var localFs = new PhysicalFileSystem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Lib")); var defaultResolver = new DefaultPackagePathResolver(localFs); var machineRepo = new LocalPackageRepository(defaultResolver, localFs); var buildRepo = new BuildPackageRepository(); var remoteRepo = new DataServicePackageRepository(new Uri("https://nuget.org/api/v2")); var project = new BuildProjectSystem(ProjectDirectory, new FrameworkName(TargetFramework), CurrentReferences); var manager = new PackageManager(remoteRepo, defaultResolver, localFs, machineRepo); var projectManager = new ProjectManager(remoteRepo, defaultResolver, project, buildRepo); // Install the package var ver = new SemanticVersion(version); manager.PackageInstalling += manager_PackageInstalling; manager.InstallPackage(id, ver); projectManager.AddPackageReference(id, ver); return project.OutputReferences.Select(item => { var name = AssemblyName.GetAssemblyName(item); return new TaskItem(name.FullName, new Dictionary<string, string>() { {"HintPath", item }, {"Private", "true"} }); }); }
public void AddFileThrowsArgumentNullExceptionIfWriteToStreamIsNull() { // Arrange var root = Path.GetRandomFileName(); var target = new PhysicalFileSystem(root); // Act and Assert ExceptionAssert.ThrowsArgNull(() => target.AddFile(Path.GetRandomFileName(), writeToStream: null), "writeToStream"); }
public void ConstructorInitializesInstance() { // Arrange var root = @"X:\MyRoot\MyDir"; // Act var target = new PhysicalFileSystem(root); // Assert Assert.Equal(root, target.Root); }
public void GetFullPathReturnsRootIfPathIsNullOrEmpty(string path) { // Arrange var root = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var target = new PhysicalFileSystem(root); // Act var fullPath = target.GetFullPath(path); // Assert Assert.Equal(root, fullPath); }
public void GetFullPathCombinesRootAndSpecifiedPath() { // Arrange var root = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var path = Path.GetRandomFileName(); var target = new PhysicalFileSystem(root); // Act string result = target.GetFullPath(path); // Assert Assert.Equal(Path.Combine(root, path), result, StringComparer.Ordinal); }
public void FindPackageReturnsPackageWithUnVersionedFileNameWhenUsingVersionlessPathResolver(string id, string version, string packageName) { // Arrange var repositoryRoot = CreatePackage(id, version, packageName); var fileSystem = new PhysicalFileSystem(repositoryRoot); var pathResolver = new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false); var repository = new LocalPackageRepository(pathResolver, fileSystem); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
public void RestorePackages(Project project) { string packageReferenceFileFullPath; Tuple<string, string> packageReferenceFiles = VsUtility.GetPackageReferenceFileFullPaths(project); if (File.Exists(packageReferenceFiles.Item1)) { packageReferenceFileFullPath = packageReferenceFiles.Item1; } else if (File.Exists(packageReferenceFiles.Item2)) { packageReferenceFileFullPath = packageReferenceFiles.Item2; } else { return; } var packageReferenceFile = new PackageReferenceFile(packageReferenceFileFullPath); var packages = packageReferenceFile.GetPackageReferences().ToList(); if (packages.Count == 0) { return; } var repoSettings = ServiceLocator.GetInstance<IRepositorySettings>(); var fileSystem = new PhysicalFileSystem(repoSettings.RepositoryPath); var activePackageSourceRepository = ServiceLocator.GetInstance<IPackageRepository>(); var repository = new PriorityPackageRepository(NuGet.MachineCache.Default, activePackageSourceRepository); IVsPackageManagerFactory packageManagerFactory = ServiceLocator.GetInstance<IVsPackageManagerFactory>(); var packageManager = packageManagerFactory.CreatePackageManager(repository, useFallbackForDependencies: false); foreach (var package in packages) { if (IsPackageInstalled(fileSystem, package.Id, package.Version)) { continue; } using (packageManager.SourceRepository.StartOperation(RepositoryOperationNames.Restore, package.Id, package.Version.ToString())) { var resolvedPackage = PackageHelper.ResolvePackage( packageManager.SourceRepository, package.Id, package.Version); NuGet.Common.PackageExtractor.InstallPackage(packageManager, resolvedPackage); } } }
/// <summary> /// Executes the command. /// </summary> public override void ExecuteCommand() { string inputPackagesConfigPath = GetLatestPackagesConfigPath(); string outputPackagesConfigPath = GetPackagesConfigPath(); if (String.IsNullOrEmpty(inputPackagesConfigPath) || String.IsNullOrEmpty(outputPackagesConfigPath)) { throw new CommandLineException(); } if (!File.Exists(inputPackagesConfigPath)) { throw new CommandLineException(); } TryCreateAllDirectories(Path.GetDirectoryName(outputPackagesConfigPath)); if(!File.Exists(outputPackagesConfigPath)) { File.WriteAllText(outputPackagesConfigPath, @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> </packages>"); } PhysicalFileSystem outputFileSystem = new PhysicalFileSystem(Path.GetDirectoryName(outputPackagesConfigPath)); PackageReferenceFile outputFile = new PackageReferenceFile(outputFileSystem, Path.GetFileName(outputPackagesConfigPath)); // Remove all existing references from output file Dictionary<string, SemanticVersion> existingReferences = new Dictionary<string,SemanticVersion>(); foreach (PackageReference packageReference in outputFile.GetPackageReferences()) { existingReferences.Add(packageReference.Id, packageReference.Version); } foreach (KeyValuePair<string, SemanticVersion> pair in existingReferences) { outputFile.DeleteEntry(pair.Key, pair.Value); } PhysicalFileSystem inputFileSystem = new PhysicalFileSystem(Path.GetDirectoryName(inputPackagesConfigPath)); PackageReferenceFile inputFile = new PackageReferenceFile(inputFileSystem, Path.GetFileName(inputPackagesConfigPath)); foreach (PackageReference packageReference in inputFile.GetPackageReferences()) { IPackage package = GetLatestPackage(packageReference.Id); outputFile.AddEntry(packageReference.Id, package.Version, false, packageReference.TargetFramework); } }
public IPackageInstaller CreatePackageInstaller(string installationPath, string configurationPath) { var packagePath = this.configurationManager.PackagePath; var sourceRepository = this.source.CreatePackageRepository(); var logger = new PackageLogger(); var packagePathResolver = new DefaultPackagePathResolver(packagePath); var fileSystem = new PhysicalFileSystem(installationPath ?? this.directorySystem.CurrentDirectory) { Logger = logger }; var destinationRepository = new LocalPackageRepository(packagePath); var manager = new PackageManager( sourceRepository, packagePathResolver, fileSystem, destinationRepository) { Logger = logger }; var powerShellPackageFile = new PowerShellPackageFile( new BackgroundProcess(), manager, new PhysicalFileSystem(this.directorySystem.TemporaryPath), configurationPath); return new DefaultPackageInstaller(manager, powerShellPackageFile, logger); }
public void RelativeOrAbsolutePastRootNotAllowed() { var provider = new PhysicalFileSystem("sub"); IFileInfo info; provider.TryGetFileInfo("..\\File.txt", out info).ShouldBe(false); info.ShouldBe(null); provider.TryGetFileInfo(".\\..\\File.txt", out info).ShouldBe(false); info.ShouldBe(null); var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; var file1 = Path.Combine(applicationBase, "File.txt"); var file2 = Path.Combine(applicationBase, "sub", "File2.txt"); provider.TryGetFileInfo(file1, out info).ShouldBe(false); info.ShouldBe(null); provider.TryGetFileInfo(file2, out info).ShouldBe(true); info.ShouldNotBe(null); info.PhysicalPath.ShouldBe(file2); }
public ServerPackageRepository CreateServerPackageRepository(string path, Action<ExpandedPackageRepository> setupRepository = null, Func<string, bool, bool> getSetting = null) { var fileSystem = new PhysicalFileSystem(path); var expandedPackageRepository = new ExpandedPackageRepository(fileSystem); if (setupRepository != null) { setupRepository(expandedPackageRepository); } var serverRepository = new ServerPackageRepository( fileSystem, runBackgroundTasks: false, innerRepository: expandedPackageRepository, logger: new Logging.NullLogger(), getSetting: getSetting); serverRepository.GetPackages(); // caches the files return serverRepository; }
public IFileSystem GetFileSystem(string path) { // Get the source control providers var physicalFileSystem = new PhysicalFileSystem(path); if (_settings.IsSourceControlDisabled()) { return physicalFileSystem; } var providers = _componentModel.GetExtensions<ISourceControlFileSystemProvider>(); // Get the repository path IFileSystem fileSystem = null; var sourceControl = (SourceControl2)_dte.SourceControl; if (providers.Any() && sourceControl != null) { SourceControlBindings binding = null; try { // Get the binding for this solution binding = sourceControl.GetBindings(_dte.Solution.FullName); } catch (NotImplementedException) { // Some source control providers don't bother to implement this. // TFS might be the only one using it } if (binding != null) { fileSystem = providers.Select(provider => GetFileSystemFromProvider(provider, path, binding)) .Where(fs => fs != null) .FirstOrDefault(); } } return fileSystem ?? physicalFileSystem; }
public void Initialize() { var packagePathResolver = CreatePackagePathResolver(); var fileSystem = new PhysicalFileSystem(PackagePath); var hashProvider = new CryptoHashProvider(PackageHashAlgorithm); CreateDirectories(); InitializeLucene(); PackageIndexer = new PackageIndexer { FileSystem = fileSystem, Provider = Provider, Writer = Provider.IndexWriter }; var repository = new LucenePackageRepository(packagePathResolver, fileSystem) { HashProvider = hashProvider, HashAlgorithm = PackageHashAlgorithm, PathResolver = packagePathResolver, Indexer = PackageIndexer, LuceneDataProvider = Provider, LucenePackages = Provider.AsQueryable(() => new LucenePackage(fileSystem)), LucenePackageSource = string.Format("{0} (with Lucene.Net index in {1})", PackagePath, LuceneIndexPath) }; // TODO: circular reference PackageIndexer.PackageRepository = repository; PackageIndexer.Initialize(); repository.Initialize(); Repository = repository; InitializeFileSystemWatcher(fileSystem, repository); }
public void Execute() { if (Help) { HelpCommand.ViewHelpForCommand(CommandAttribute.CommandName); } else { if (String.IsNullOrEmpty(ConfigFile)) { Settings = NuGet.Settings.LoadDefaultSettings(FileSystem); } else { var directory = Path.GetDirectoryName(Path.GetFullPath(ConfigFile)); var configFileName = Path.GetFileName(ConfigFile); var configFileSystem = new PhysicalFileSystem(directory); Settings = NuGet.Settings.LoadDefaultSettings( configFileSystem, configFileName); } SourceProvider = PackageSourceBuilder.CreateSourceProvider(Settings); // Register an additional provider for the console specific application so that the user // will be prompted if a proxy is set and credentials are required var credentialProvider = new SettingsCredentialProvider( new ConsoleCredentialProvider(Console), SourceProvider, Console); HttpClient.DefaultCredentialProvider = credentialProvider; RepositoryFactory = new NuGet.Common.CommandLineRepositoryFactory(Console); ExecuteCommand(); } }
public void ShadowScopeComplete() { var logger = Mock.Of <ILogger>(); var path = IOHelper.MapPath("FileSysTests"); var shadowfs = IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); Directory.CreateDirectory(shadowfs); var scopedFileSystems = false; var phy = new PhysicalFileSystem(path, "ignore"); var container = Mock.Of <IFactory>(); var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem <FS>(phy); var sw = (ShadowWrapper)fs.InnerFileSystem; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f1.txt", ms); Assert.IsTrue(phy.FileExists("sub/f1.txt")); string id; // explicit shadow without scope does not work sw.Shadow(id = ShadowWrapper.CreateShadowId()); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); Assert.IsTrue(phy.FileExists("sub/f2.txt")); sw.UnShadow(true); Assert.IsTrue(phy.FileExists("sub/f2.txt")); Assert.IsFalse(Directory.Exists(shadowfs + "/" + id)); // shadow with scope but no complete does not complete scopedFileSystems = true; // pretend we have a scope var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f3.txt", ms); Assert.IsFalse(phy.FileExists("sub/f3.txt")); var dirs = Directory.GetDirectories(shadowfs); Assert.AreEqual(1, dirs.Length); Assert.AreEqual((shadowfs + "/" + id).Replace('\\', '/'), dirs[0].Replace('\\', '/')); dirs = Directory.GetDirectories(dirs[0]); var typedDir = dirs.FirstOrDefault(x => x.Replace('\\', '/').EndsWith("/x")); Assert.IsNotNull(typedDir); dirs = Directory.GetDirectories(typedDir); var suid = fileSystems.Paths[typeof(FS)]; var scopedDir = dirs.FirstOrDefault(x => x.Replace('\\', '/').EndsWith("/" + suid)); // this is where files go Assert.IsNotNull(scopedDir); scope.Dispose(); scopedFileSystems = false; Assert.IsFalse(phy.FileExists("sub/f3.txt")); TestHelper.TryAssert(() => Assert.IsFalse(Directory.Exists(shadowfs + "/" + id))); // shadow with scope and complete does complete scopedFileSystems = true; // pretend we have a scope scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f4.txt", ms); Assert.IsFalse(phy.FileExists("sub/f4.txt")); Assert.AreEqual(1, Directory.GetDirectories(shadowfs).Length); scope.Complete(); scope.Dispose(); scopedFileSystems = false; TestHelper.TryAssert(() => Assert.AreEqual(0, Directory.GetDirectories(shadowfs).Length)); Assert.IsTrue(phy.FileExists("sub/f4.txt")); Assert.IsFalse(Directory.Exists(shadowfs + "/" + id)); // test scope for "another thread" scopedFileSystems = true; // pretend we have a scope scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f5.txt", ms); Assert.IsFalse(phy.FileExists("sub/f5.txt")); // pretend we're another thread w/out scope scopedFileSystems = false; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f6.txt", ms); scopedFileSystems = true; // pretend we have a scope Assert.IsTrue(phy.FileExists("sub/f6.txt")); // other thread has written out to fs scope.Complete(); scope.Dispose(); scopedFileSystems = false; Assert.IsTrue(phy.FileExists("sub/f5.txt")); TestHelper.TryAssert(() => Assert.IsFalse(Directory.Exists(shadowfs + "/" + id))); }
public async Task <bool> ExecuteCommand() { if (string.IsNullOrEmpty(_addCommand.Name)) { Reports.Error.WriteLine("Name of dependency to install is required.".Red()); return(false); } SemanticVersion version = null; if (!string.IsNullOrEmpty(_addCommand.Version)) { version = SemanticVersion.Parse(_addCommand.Version); } // Create source provider from solution settings _addCommand.ProjectDir = _addCommand.ProjectDir ?? Directory.GetCurrentDirectory(); var rootDir = ProjectResolver.ResolveRootDirectory(_addCommand.ProjectDir); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); var settings = SettingsUtils.ReadSettings(solutionDir: rootDir, nugetConfigFile: null, fileSystem: fileSystem, machineWideSettings: new CommandLineMachineWideSettings()); var sourceProvider = PackageSourceBuilder.CreateSourceProvider(settings); var effectiveSources = PackageSourceUtils.GetEffectivePackageSources(sourceProvider, _restoreCommand.FeedOptions.Sources, _restoreCommand.FeedOptions.FallbackSources); var packageFeeds = new List <IPackageFeed>(); foreach (var source in effectiveSources) { var feed = PackageSourceUtils.CreatePackageFeed( source, _restoreCommand.FeedOptions.NoCache, _restoreCommand.FeedOptions.IgnoreFailedSources, Reports); if (feed != null) { packageFeeds.Add(feed); } } PackageInfo result = null; if (version == null) { result = await PackageSourceUtils.FindLatestPackage(packageFeeds, _addCommand.Name); } else { result = await PackageSourceUtils.FindBestMatchPackage(packageFeeds, _addCommand.Name, new SemanticVersionRange(version)); } if (result == null) { Reports.Error.WriteLine("Unable to locate {0} >= {1}", _addCommand.Name.Red().Bold(), _addCommand.Version); return(false); } if (string.IsNullOrEmpty(_addCommand.Version)) { _addCommand.Version = result.Version.ToString(); } return(_addCommand.ExecuteCommand() && (await _restoreCommand.Execute())); }
private ProjectNugetifier CreateProjectNugetifier(IVsProject projectAdapter) { var projectFileSystem = new PhysicalFileSystem(projectAdapter.ProjectDirectory.ToString()); var repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source); repository.Logger = Console; var hintPathGenerator = new HintPathGenerator(); return new ProjectNugetifier(projectAdapter, repository, projectFileSystem, Console, hintPathGenerator); }
public async Task GivenThatIRemoveAllPackagesWithTheCatalogDisabledVerifyItSucceeds() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; context.SourceSettings.CatalogEnabled = false; var testPackage1 = new TestNupkg("packageA", "1.0.1"); var testPackage2 = new TestNupkg("packageA", "1.0.2"); var testPackage3 = new TestNupkg("packageA", "1.0.3"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); var zipFile3 = testPackage3.Save(packagesFolder.Root); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile3.FullName }, false, false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.3", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.1", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.2", "", false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var regPackages = await registration.GetPackagesByIdAsync("packageA"); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEmpty("all packages were removed"); indexPackages.Should().BeEmpty("all packages were removed"); searchPackages.Should().BeEmpty("all packages were removed"); autoCompletePackages.Should().BeEmpty("all packages were removed"); } }
public async Task GivenThatIAddAPackageWithTheCatalogDisabledVerifyItSucceeds() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; context.SourceSettings.CatalogEnabled = false; var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); var catalogEntry = await registration.GetCatalogEntryFromPackageBlob(input.Identity); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEquivalentTo(new[] { input.Identity }); indexPackages.Should().BeEquivalentTo(new[] { input.Identity }); searchPackages.Should().BeEquivalentTo(new[] { input.Identity }); autoCompletePackages.Should().BeEquivalentTo(new[] { input.Identity.Id }); catalogLatest.Should().BeNull(); catalogEntry["version"].ToString().Should().Be("1.0.0"); catalogEntry["sleet:operation"].ToString().Should().Be("add"); } } }
private void PackageRestore(Project project) { var repoSettings = ServiceLocator.GetInstance<IRepositorySettings>(); var fileSystem = new PhysicalFileSystem(repoSettings.RepositoryPath); var projectFullPath = VsUtility.GetFullPath(project); WriteLine(VerbosityLevel.Normal, Resources.RestoringPackagesOfProject, projectFullPath); try { var packageReferenceFileName = Path.Combine( Path.GetDirectoryName(projectFullPath), PackageReferenceFile); RestorePackages(packageReferenceFileName, fileSystem); } catch (Exception ex) { var message = String.Format(CultureInfo.CurrentCulture, Resources.PackageRestoreFailedForProject, projectFullPath, ex.Message); WriteLine(VerbosityLevel.Quiet, message); ActivityLog.LogError(LogEntrySource, message); } finally { WriteLine(VerbosityLevel.Normal, Resources.PackageRestoreFinishedForProject, projectFullPath); } }
private void HandleAllDirectoryOperations() { DiffTreeResult treeOp; while (this.diff.DirectoryOperations.TryDequeue(out treeOp)) { if (this.HasFailures) { return; } switch (treeOp.Operation) { case DiffTreeResult.Operations.Modify: case DiffTreeResult.Operations.Add: try { Directory.CreateDirectory(treeOp.TargetFilename); } catch (Exception ex) { EventMetadata metadata = new EventMetadata(); metadata.Add("Operation", "CreateDirectory"); metadata.Add("Path", treeOp.TargetFilename); metadata.Add("ErrorMessage", ex.Message); this.tracer.RelatedError(metadata); this.HasFailures = true; } break; case DiffTreeResult.Operations.Delete: try { if (Directory.Exists(treeOp.TargetFilename)) { PhysicalFileSystem.RecursiveDelete(treeOp.TargetFilename); } } catch (Exception ex) { // We are deleting directories and subdirectories in parallel if (Directory.Exists(treeOp.TargetFilename)) { EventMetadata metadata = new EventMetadata(); metadata.Add("Operation", "DeleteDirectory"); metadata.Add("Path", treeOp.TargetFilename); metadata.Add("ErrorMessage", ex.Message); this.tracer.RelatedError(metadata); this.HasFailures = true; } } break; case DiffTreeResult.Operations.RenameEdit: try { // If target is file, just delete the source. if (!treeOp.TargetIsDirectory) { if (Directory.Exists(treeOp.SourceFilename)) { PhysicalFileSystem.RecursiveDelete(treeOp.SourceFilename); } } else { // If target is directory, delete any source file and add if (!treeOp.SourceIsDirectory) { if (File.Exists(treeOp.SourceFilename)) { File.Delete(treeOp.SourceFilename); } goto case DiffTreeResult.Operations.Add; } else { // Source and target are directory, do a move and let later steps handle any sub-edits. Directory.Move(treeOp.SourceFilename, treeOp.TargetFilename); } } } catch (Exception ex) { EventMetadata metadata = new EventMetadata(); metadata.Add("Operation", "RenameDirectory"); metadata.Add("Path", treeOp.TargetFilename); metadata.Add("ErrorMessage", ex.Message); this.tracer.RelatedError(metadata); this.HasFailures = true; } break; default: this.tracer.RelatedError("Ignoring unexpected Tree Operation {0}: {1}", treeOp.TargetFilename, treeOp.Operation); continue; } if (Interlocked.Increment(ref this.directoryOpCount) % NumOperationsPerStatus == 0) { EventMetadata metadata = new EventMetadata(); metadata.Add("DirectoryOperationsQueued", this.diff.DirectoryOperations.Count); metadata.Add("DirectoryOperationsCompleted", this.directoryOpCount); this.tracer.RelatedEvent(EventLevel.Informational, "CheckoutStatus", metadata); } } }
private void EnsureLocalCacheIsHealthy( ITracer tracer, GVFSEnlistment enlistment, RetryConfig retryConfig, ServerGVFSConfig serverGVFSConfig, CacheServerInfo cacheServer) { if (!Directory.Exists(enlistment.LocalCacheRoot)) { try { tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Local cache root: {enlistment.LocalCacheRoot} missing, recreating it"); Directory.CreateDirectory(enlistment.LocalCacheRoot); } catch (Exception e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Exception", e.ToString()); metadata.Add("enlistment.LocalCacheRoot", enlistment.LocalCacheRoot); tracer.RelatedError(metadata, $"{nameof(this.EnsureLocalCacheIsHealthy)}: Exception while trying to create local cache root"); this.ReportErrorAndExit(tracer, "Failed to create local cache: " + enlistment.LocalCacheRoot); } } // Validate that the GitObjectsRoot directory is on disk, and that the GVFS repo is configured to use it. // If the directory is missing (and cannot be found in the mapping file) a new key for the repo will be added // to the mapping file and used for BOTH the GitObjectsRoot and BlobSizesRoot PhysicalFileSystem fileSystem = new PhysicalFileSystem(); if (Directory.Exists(enlistment.GitObjectsRoot)) { bool gitObjectsRootInAlternates = false; string alternatesFilePath = this.GetAlternatesPath(enlistment); if (File.Exists(alternatesFilePath)) { try { using (Stream stream = fileSystem.OpenFileStream( alternatesFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, callFlushFileBuffers: false)) { using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { string alternatesLine = reader.ReadLine(); if (string.Equals(alternatesLine, enlistment.GitObjectsRoot, StringComparison.OrdinalIgnoreCase)) { gitObjectsRootInAlternates = true; } } } } } catch (Exception e) { EventMetadata exceptionMetadata = new EventMetadata(); exceptionMetadata.Add("Exception", e.ToString()); tracer.RelatedError(exceptionMetadata, $"{nameof(this.EnsureLocalCacheIsHealthy)}: Exception while trying to validate alternates file"); this.ReportErrorAndExit(tracer, $"Failed to validate that alternates file includes git objects root: {e.Message}"); } } else { tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Alternates file not found"); } if (!gitObjectsRootInAlternates) { tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: GitObjectsRoot ({enlistment.GitObjectsRoot}) missing from alternates files, recreating alternates"); string error; if (!this.TryCreateAlternatesFile(fileSystem, enlistment, out error)) { this.ReportErrorAndExit(tracer, $"Failed to update alternates file to include git objects root: {error}"); } } } else { tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: GitObjectsRoot ({enlistment.GitObjectsRoot}) missing, determining new root"); if (cacheServer == null) { cacheServer = CacheServerResolver.GetCacheServerFromConfig(enlistment); } string error; if (serverGVFSConfig == null) { if (retryConfig == null) { if (!RetryConfig.TryLoadFromGitConfig(tracer, enlistment, out retryConfig, out error)) { this.ReportErrorAndExit(tracer, "Failed to determine GVFS timeout and max retries: " + error); } } serverGVFSConfig = this.QueryGVFSConfig(tracer, enlistment, retryConfig); } string localCacheKey; LocalCacheResolver localCacheResolver = new LocalCacheResolver(enlistment); if (!localCacheResolver.TryGetLocalCacheKeyFromLocalConfigOrRemoteCacheServers( tracer, serverGVFSConfig, cacheServer, enlistment.LocalCacheRoot, localCacheKey: out localCacheKey, errorMessage: out error)) { this.ReportErrorAndExit(tracer, $"Previous git objects root ({enlistment.GitObjectsRoot}) not found, and failed to determine new local cache key: {error}"); } EventMetadata metadata = new EventMetadata(); metadata.Add("localCacheRoot", enlistment.LocalCacheRoot); metadata.Add("localCacheKey", localCacheKey); metadata.Add(TracingConstants.MessageKey.InfoMessage, "Initializing and persisting updated paths"); tracer.RelatedEvent(EventLevel.Informational, "GVFSVerb_EnsureLocalCacheIsHealthy_InitializePathsFromKey", metadata); enlistment.InitializeCachePathsFromKey(enlistment.LocalCacheRoot, localCacheKey); tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Creating GitObjectsRoot ({enlistment.GitObjectsRoot}), GitPackRoot ({enlistment.GitPackRoot}), and BlobSizesRoot ({enlistment.BlobSizesRoot})"); try { Directory.CreateDirectory(enlistment.GitObjectsRoot); Directory.CreateDirectory(enlistment.GitPackRoot); } catch (Exception e) { EventMetadata exceptionMetadata = new EventMetadata(); exceptionMetadata.Add("Exception", e.ToString()); exceptionMetadata.Add("enlistment.LocalCacheRoot", enlistment.LocalCacheRoot); exceptionMetadata.Add("enlistment.GitObjectsRoot", enlistment.GitObjectsRoot); exceptionMetadata.Add("enlistment.GitPackRoot", enlistment.GitPackRoot); exceptionMetadata.Add("enlistment.BlobSizesRoot", enlistment.BlobSizesRoot); tracer.RelatedError(exceptionMetadata, $"{nameof(this.InitializeLocalCacheAndObjectsPaths)}: Exception while trying to create objects, pack, and sizes folders"); this.ReportErrorAndExit(tracer, "Failed to create objects, pack, and sizes folders"); } tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Creating new alternates file"); if (!this.TryCreateAlternatesFile(fileSystem, enlistment, out error)) { this.ReportErrorAndExit(tracer, $"Failed to update alterates file with new objects path: {error}"); } tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Saving git objects root ({enlistment.GitObjectsRoot}) in repo metadata"); RepoMetadata.Instance.SetGitObjectsRoot(enlistment.GitObjectsRoot); tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Saving blob sizes root ({enlistment.BlobSizesRoot}) in repo metadata"); RepoMetadata.Instance.SetBlobSizesRoot(enlistment.BlobSizesRoot); } // Validate that the BlobSizesRoot folder is on disk. // Note that if a user performed an action that resulted in the entire .gvfscache being deleted, the code above // for validating GitObjectsRoot will have already taken care of generating a new key and setting a new enlistment.BlobSizesRoot path if (!Directory.Exists(enlistment.BlobSizesRoot)) { tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: BlobSizesRoot ({enlistment.BlobSizesRoot}) not found, re-creating"); try { Directory.CreateDirectory(enlistment.BlobSizesRoot); } catch (Exception e) { EventMetadata exceptionMetadata = new EventMetadata(); exceptionMetadata.Add("Exception", e.ToString()); exceptionMetadata.Add("enlistment.BlobSizesRoot", enlistment.BlobSizesRoot); tracer.RelatedError(exceptionMetadata, $"{nameof(this.InitializeLocalCacheAndObjectsPaths)}: Exception while trying to create blob sizes folder"); this.ReportErrorAndExit(tracer, "Failed to create blob sizes folder"); } } }
public UpgradeVerb() { this.fileSystem = new PhysicalFileSystem(); this.processLauncher = new ProcessLauncher(); this.Output = Console.Out; }
private Result CreateClone( ITracer tracer, GVFSEnlistment enlistment, GitObjectsHttpRequestor objectRequestor, GitRefs refs, string branch) { Result initRepoResult = this.TryInitRepo(tracer, refs, enlistment); if (!initRepoResult.Success) { return(initRepoResult); } PhysicalFileSystem fileSystem = new PhysicalFileSystem(); string errorMessage; if (!this.TryCreateAlternatesFile(fileSystem, enlistment, out errorMessage)) { return(new Result("Error configuring alternate: " + errorMessage)); } GitRepo gitRepo = new GitRepo(tracer, enlistment, fileSystem); GVFSContext context = new GVFSContext(tracer, fileSystem, gitRepo, enlistment); GVFSGitObjects gitObjects = new GVFSGitObjects(context, objectRequestor); if (!this.TryDownloadCommit( refs.GetTipCommitId(branch), enlistment, objectRequestor, gitObjects, gitRepo, out errorMessage)) { return(new Result(errorMessage)); } if (!GVFSVerb.TrySetRequiredGitConfigSettings(enlistment) || !GVFSVerb.TrySetOptionalGitConfigSettings(enlistment)) { return(new Result("Unable to configure git repo")); } CacheServerResolver cacheServerResolver = new CacheServerResolver(tracer, enlistment); if (!cacheServerResolver.TrySaveUrlToLocalConfig(objectRequestor.CacheServer, out errorMessage)) { return(new Result("Unable to configure cache server: " + errorMessage)); } GitProcess git = new GitProcess(enlistment); string originBranchName = "origin/" + branch; GitProcess.Result createBranchResult = git.CreateBranchWithUpstream(branch, originBranchName); if (createBranchResult.ExitCodeIsFailure) { return(new Result("Unable to create branch '" + originBranchName + "': " + createBranchResult.Errors + "\r\n" + createBranchResult.Output)); } File.WriteAllText( Path.Combine(enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Head), "ref: refs/heads/" + branch); if (!this.TryDownloadRootGitAttributes(enlistment, gitObjects, gitRepo, out errorMessage)) { return(new Result(errorMessage)); } this.CreateGitScript(enlistment); string installHooksError; if (!HooksInstaller.InstallHooks(context, out installHooksError)) { tracer.RelatedError(installHooksError); return(new Result(installHooksError)); } GitProcess.Result forceCheckoutResult = git.ForceCheckout(branch); if (forceCheckoutResult.ExitCodeIsFailure && forceCheckoutResult.Errors.IndexOf("unable to read tree") > 0) { // It is possible to have the above TryDownloadCommit() fail because we // already have the commit and root tree we intend to check out, but // don't have a tree further down the working directory. If we fail // checkout here, its' because we don't have these trees and the // read-object hook is not available yet. Force downloading the commit // again and retry the checkout. if (!this.TryDownloadCommit( refs.GetTipCommitId(branch), enlistment, objectRequestor, gitObjects, gitRepo, out errorMessage, checkLocalObjectCache: false)) { return(new Result(errorMessage)); } forceCheckoutResult = git.ForceCheckout(branch); } if (forceCheckoutResult.ExitCodeIsFailure) { string[] errorLines = forceCheckoutResult.Errors.Split('\n'); StringBuilder checkoutErrors = new StringBuilder(); foreach (string gitError in errorLines) { if (IsForceCheckoutErrorCloneFailure(gitError)) { checkoutErrors.AppendLine(gitError); } } if (checkoutErrors.Length > 0) { string error = "Could not complete checkout of branch: " + branch + ", " + checkoutErrors.ToString(); tracer.RelatedError(error); return(new Result(error)); } } if (!RepoMetadata.TryInitialize(tracer, enlistment.DotGVFSRoot, out errorMessage)) { tracer.RelatedError(errorMessage); return(new Result(errorMessage)); } try { RepoMetadata.Instance.SaveCloneMetadata(tracer, enlistment); this.LogEnlistmentInfoAndSetConfigValues(tracer, git, enlistment); } catch (Exception e) { tracer.RelatedError(e.ToString()); return(new Result(e.Message)); } finally { RepoMetadata.Shutdown(); } // Prepare the working directory folder for GVFS last to ensure that gvfs mount will fail if gvfs clone has failed Exception exception; string prepFileSystemError; if (!GVFSPlatform.Instance.KernelDriver.TryPrepareFolderForCallbacks(enlistment.WorkingDirectoryBackingRoot, out prepFileSystemError, out exception)) { EventMetadata metadata = new EventMetadata(); metadata.Add(nameof(prepFileSystemError), prepFileSystemError); if (exception != null) { metadata.Add("Exception", exception.ToString()); } tracer.RelatedError(metadata, $"{nameof(this.CreateClone)}: TryPrepareFolderForCallbacks failed"); return(new Result(prepFileSystemError)); } return(new Result(true)); }
public override bool TryUpgrade(ITracer tracer, string enlistmentRoot) { ModifiedPathsDatabase modifiedPaths = null; try { PhysicalFileSystem fileSystem = new PhysicalFileSystem(); string modifiedPathsDatabasePath = Path.Combine(enlistmentRoot, GVFSConstants.DotGVFS.Root, GVFSConstants.DotGVFS.Databases.ModifiedPaths); string error; if (!ModifiedPathsDatabase.TryLoadOrCreate(tracer, modifiedPathsDatabasePath, fileSystem, out modifiedPaths, out error)) { tracer.RelatedError($"Unable to create the modified paths database. {error}"); return(false); } string sparseCheckoutPath = Path.Combine(enlistmentRoot, GVFSConstants.WorkingDirectoryRootName, GVFSConstants.DotGit.Info.SparseCheckoutPath); IEnumerable <string> sparseCheckoutLines = fileSystem.ReadAllText(sparseCheckoutPath).Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); bool isRetryable; foreach (string entry in sparseCheckoutLines) { bool isFolder = entry.EndsWith(GVFSConstants.GitPathSeparatorString); if (!modifiedPaths.TryAdd(entry.Trim(GVFSConstants.GitPathSeparator), isFolder, out isRetryable)) { tracer.RelatedError("Unable to add to the modified paths database."); return(false); } } string alwaysExcludePath = Path.Combine(enlistmentRoot, GVFSConstants.WorkingDirectoryRootName, GVFSConstants.DotGit.Info.AlwaysExcludePath); if (fileSystem.FileExists(alwaysExcludePath)) { string[] alwaysExcludeLines = fileSystem.ReadAllText(alwaysExcludePath).Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = alwaysExcludeLines.Length - 1; i >= 0; i--) { string entry = alwaysExcludeLines[i]; if (entry.EndsWith("*")) { // This is the first entry using the old format and we don't want to process old entries // because we would need folder entries since there isn't a file and that would cause sparse-checkout to // recursively clear skip-worktree bits for everything under that folder break; } entry = entry.TrimStart('!'); bool isFolder = entry.EndsWith(GVFSConstants.GitPathSeparatorString); if (!isFolder) { if (!modifiedPaths.TryAdd(entry.Trim(GVFSConstants.GitPathSeparator), isFolder, out isRetryable)) { tracer.RelatedError("Unable to add to the modified paths database."); return(false); } } } } modifiedPaths.ForceFlush(); fileSystem.WriteAllText(sparseCheckoutPath, "/.gitattributes" + Environment.NewLine); fileSystem.DeleteFile(alwaysExcludePath); } catch (IOException ex) { tracer.RelatedError($"IOException: {ex.ToString()}"); return(false); } finally { if (modifiedPaths != null) { modifiedPaths.Dispose(); modifiedPaths = null; } } if (!this.TryIncrementMajorVersion(tracer, enlistmentRoot)) { return(false); } return(true); }
/// <summary> /// Generates the PInvoke layer from Monocypher C header files. /// - Raw functions /// - The same functions using Span<T> when possible /// </summary> public void GeneratePInvoke() { var srcFolder = Path.Combine(MonocypherFolder, "src"); var destFolder = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\Monocypher")); if (!Directory.Exists(srcFolder)) { throw new DirectoryNotFoundException($"The source folder `{srcFolder}` doesn't exist"); } if (!Directory.Exists(destFolder)) { throw new DirectoryNotFoundException($"The destination folder `{destFolder}` doesn't exist"); } var marshalNoFreeNative = new CSharpMarshalAttribute(CSharpUnmanagedKind.CustomMarshaler) { MarshalTypeRef = "typeof(UTF8MarshallerNoFree)" }; var csOptions = new CSharpConverterOptions() { DefaultClassLib = "Monocypher", DefaultNamespace = "Monocypher", DefaultOutputFilePath = "/Monocypher.generated.cs", DefaultDllImportNameAndArguments = "MonocypherDll", GenerateAsInternal = false, DispatchOutputPerInclude = false, MappingRules = { e => e.Map <CppField>("crypto_blake2b_vtable").Discard(), e => e.Map <CppField>("crypto_sha512_vtable").Discard(), } }; csOptions.Plugins.Insert(0, new FixedArrayTypeConverter()); csOptions.IncludeFolders.Add(srcFolder); var files = new List <string>() { Path.Combine(srcFolder, "monocypher.h"), Path.Combine(srcFolder, "optional", "monocypher-ed25519.h"), }; var csCompilation = CSharpConverter.Convert(files, csOptions); if (csCompilation.HasErrors) { foreach (var message in csCompilation.Diagnostics.Messages) { Console.Error.WriteLine(message); } Console.Error.WriteLine("Unexpected parsing errors"); Environment.Exit(1); } var monocypher = csCompilation.Members.OfType <CSharpGeneratedFile>().First().Members.OfType <CSharpNamespace>().First().Members.OfType <CSharpClass>().First(); ProcessInvokeFunctions(monocypher); var fs = new PhysicalFileSystem(); { var subfs = new SubFileSystem(fs, fs.ConvertPathFromInternal(destFolder)); var codeWriter = new CodeWriter(new CodeWriterOptions(subfs)); csCompilation.DumpTo(codeWriter); } }
private void OwinBuilder(IAppBuilder app) { IFileSystem outputFolder = new PhysicalFileSystem(LocalPath); if (LiveReloadClients != null) { // Inject LiveReload script tags to HTML documents, needs to run first as it overrides output stream app.UseScriptInjection($"{VirtualDirectory ?? string.Empty}/livereload.js?host=localhost&port={Port}"); // Host ws:// (this also needs to go early in the pipeline so WS can return before virtual directory, etc.) app.MapFleckRoute <ReloadClient>("/livereload", connection => { ReloadClient reloadClient = (ReloadClient)connection; reloadClient.Logger = _loggerProvider?.CreateLogger("LiveReload"); LiveReloadClients.Add(reloadClient); }); } // Support for virtual directory if (!string.IsNullOrEmpty(VirtualDirectory)) { app.UseVirtualDirectory(VirtualDirectory); } // Disable caching app.Use((c, t) => { c.Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate"); c.Response.Headers.Append("Pragma", "no-cache"); c.Response.Headers.Append("Expires", "0"); return(t()); }); // Support for extensionless URLs if (Extensionless) { app.UseExtensionlessUrls(new ExtensionlessUrlsOptions { FileSystem = outputFolder }); } // Serve up all static files app.UseDefaultFiles(new DefaultFilesOptions { RequestPath = PathString.Empty, FileSystem = outputFolder, DefaultFileNames = new List <string> { "index.html", "index.htm", "home.html", "home.htm", "default.html", "default.html" } }); app.UseStaticFiles(new StaticFileOptions { RequestPath = PathString.Empty, FileSystem = outputFolder, ServeUnknownFileTypes = true }); if (LiveReloadClients != null) { // Host livereload.js (do this last so virtual directory rewriting applies) Assembly liveReloadAssembly = typeof(ReloadClient).Assembly; string rootNamespace = typeof(ReloadClient).Namespace; IFileSystem reloadFilesystem = new EmbeddedResourceFileSystem(liveReloadAssembly, $"{rootNamespace}"); app.UseStaticFiles(new StaticFileOptions { RequestPath = PathString.Empty, FileSystem = reloadFilesystem, ServeUnknownFileTypes = true }); } }
public override bool TryUpgrade(ITracer tracer, string enlistmentRoot) { ModifiedPathsDatabase modifiedPaths = null; try { PhysicalFileSystem fileSystem = new PhysicalFileSystem(); string modifiedPathsDatabasePath = Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot, GVFSConstants.DotGVFS.Databases.ModifiedPaths); string error; if (!ModifiedPathsDatabase.TryLoadOrCreate(tracer, modifiedPathsDatabasePath, fileSystem, out modifiedPaths, out error)) { tracer.RelatedError($"Unable to create the modified paths database. {error}"); return(false); } string sparseCheckoutPath = Path.Combine(enlistmentRoot, GVFSConstants.WorkingDirectoryRootName, GVFSConstants.DotGit.Info.SparseCheckoutPath); bool isRetryable; using (FileStream fs = File.OpenRead(sparseCheckoutPath)) using (StreamReader reader = new StreamReader(fs)) { string entry = reader.ReadLine(); while (entry != null) { entry = entry.Trim(); if (!string.IsNullOrWhiteSpace(entry)) { bool isFolder = entry.EndsWith(GVFSConstants.GitPathSeparatorString); if (!modifiedPaths.TryAdd(entry.Trim(GVFSConstants.GitPathSeparator), isFolder, out isRetryable)) { tracer.RelatedError("Unable to add to the modified paths database."); return(false); } } entry = reader.ReadLine(); } } string alwaysExcludePath = Path.Combine(enlistmentRoot, GVFSConstants.WorkingDirectoryRootName, GVFSConstants.DotGit.Info.AlwaysExcludePath); if (fileSystem.FileExists(alwaysExcludePath)) { string alwaysExcludeData = fileSystem.ReadAllText(alwaysExcludePath); char[] carriageReturnOrLineFeed = new[] { '\r', '\n' }; int endPosition = alwaysExcludeData.Length; while (endPosition > 0) { int startPosition = alwaysExcludeData.LastIndexOfAny(carriageReturnOrLineFeed, endPosition - 1); if (startPosition < 0) { startPosition = 0; } string entry = alwaysExcludeData.Substring(startPosition, endPosition - startPosition).Trim(); if (entry.EndsWith("*")) { // This is the first entry using the old format and we don't want to process old entries // because we would need folder entries since there isn't a file and that would cause sparse-checkout to // recursively clear skip-worktree bits for everything under that folder break; } // Substring will not return a null and the Trim will get rid of all the whitespace // if there is a length it will be a valid path that we need to process if (entry.Length > 0) { entry = entry.TrimStart('!'); bool isFolder = entry.EndsWith(GVFSConstants.GitPathSeparatorString); if (!isFolder) { if (!modifiedPaths.TryAdd(entry.Trim(GVFSConstants.GitPathSeparator), isFolder, out isRetryable)) { tracer.RelatedError("Unable to add to the modified paths database."); return(false); } } } endPosition = startPosition; } } modifiedPaths.ForceFlush(); fileSystem.WriteAllText(sparseCheckoutPath, "/.gitattributes" + Environment.NewLine); fileSystem.DeleteFile(alwaysExcludePath); } catch (IOException ex) { tracer.RelatedError($"IOException: {ex.ToString()}"); return(false); } finally { if (modifiedPaths != null) { modifiedPaths.Dispose(); modifiedPaths = null; } } if (!this.TryIncrementMajorVersion(tracer, enlistmentRoot)) { return(false); } return(true); }
public void CallingEnableCurrentSolutionWillAddPackagesToMachineCache() { // Arrange string tempSolutionPath = CreateTempFolder(); // setup SolutionManager var solutionManager = new Mock<ISolutionManager>(); solutionManager.Setup(p => p.IsSolutionOpen).Returns(true); solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath); // setup file system var fileSystem = new PhysicalFileSystem(tempSolutionPath); var fileSystemProvider = new Mock<IFileSystemProvider>(); fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem); var nugetFolderFileSystem = new PhysicalFileSystem(tempSolutionPath + "\\.nuget"); fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath + "\\.nuget")).Returns(nugetFolderFileSystem); // setup DTE var dte = new Mock<DTE>(); var projectItems = new Mock<ProjectItems>(); var solutionFolder = new Mock<Project>(); solutionFolder.Setup(s => s.Name).Returns(".nuget"); solutionFolder.SetupGet(s => s.ProjectItems).Returns(projectItems.Object); var solution = new Mock<Solution>(); solution.As<Solution2>().Setup(p => p.AddSolutionFolder(".nuget")).Returns(solutionFolder.Object); var projects = new MockProjects(new Project[0]); solution.As<Solution2>().Setup(s => s.Projects).Returns(projects); dte.SetupGet(p => p.Solution).Returns(solution.Object); // setup package repository var packageRepository = new MockPackageRepository(); packageRepository.Add(PackageUtility.CreatePackage( "NuGet.Build", version: "1.0", tools: new string[] { "NuGet.targets" }, dependencies: new PackageDependency[] { new PackageDependency("NuGet.CommandLine") })); packageRepository.Add(PackageUtility.CreatePackage( "NuGet.CommandLine", version: "2.0", tools: new string[] { "NuGet.exe" })); var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>(); packageRepositoryFactory.Setup(p => p.CreateRepository("x:\\nugetsource")).Returns(packageRepository); var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(p => p.LoadPackageSources()).Returns(new[] { new PackageSource("x:\\nugetsource") }); var localCache = new MockPackageRepository(); var packageRestore = CreateInstance( dte.Object, solutionManager.Object, fileSystemProvider.Object, packageRepositoryFactory.Object, localCache: localCache, packageSourceProvider: packageSourceProvider.Object); // Act packageRestore.EnableCurrentSolutionForRestore(fromActivation: false); // Assert var cachePackages = localCache.GetPackages().ToList(); Assert.Equal(2, cachePackages.Count); Assert.Equal("NuGet.Build", cachePackages[0].Id); Assert.Equal(new SemanticVersion("1.0"), cachePackages[0].Version); Assert.Equal("NuGet.CommandLine", cachePackages[1].Id); Assert.Equal(new SemanticVersion("2.0"), cachePackages[1].Version); }
public MockPhysicalGitObjects(ITracer tracer, PhysicalFileSystem fileSystem, Enlistment enlistment, GitObjectsHttpRequestor objectRequestor) : base(tracer, enlistment, objectRequestor, fileSystem) { }
public void CallingEnableCurrentSolutionDownloadPrereleasePackagesButDoNotUnlistedPackage() { // Arrange string tempSolutionPath = CreateTempFolder(); // setup SolutionManager var solutionManager = new Mock<ISolutionManager>(); solutionManager.Setup(p => p.IsSolutionOpen).Returns(true); solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath); // setup file system var fileSystem = new PhysicalFileSystem(tempSolutionPath); var fileSystemProvider = new Mock<IFileSystemProvider>(); fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem); var nugetFolderFileSystem = new PhysicalFileSystem(tempSolutionPath + "\\.nuget"); fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath + "\\.nuget")).Returns(nugetFolderFileSystem); // default app settings var defaultAppSettings = new Mock<ISettings>(); defaultAppSettings.Setup(s => s.GetValue("packageRestore", "enabled")).Returns("false"); // setup DTE var dte = new Mock<DTE>(); var projectItems = new Mock<ProjectItems>(); var solutionFolder = new Mock<Project>(); solutionFolder.Setup(s => s.Name).Returns(".nuget"); solutionFolder.SetupGet(s => s.ProjectItems).Returns(projectItems.Object); var solution = new Mock<Solution>(); solution.As<Solution2>().Setup(p => p.AddSolutionFolder(".nuget")).Returns(solutionFolder.Object); var projects = new MockProjects(new Project[0]); solution.As<Solution2>().Setup(s => s.Projects).Returns(projects); dte.SetupGet(p => p.Solution).Returns(solution.Object); // setup package repository var packageRepository = new MockPackageRepository(); packageRepository.Add(PackageUtility.CreatePackage( "NuGet.Build", version: "1.0", tools: new string[] { "NuGet.targets" }, dependencies: new PackageDependency[] { new PackageDependency("NuGet.CommandLine") })); // this package contains 'invalid.targets' in the tools folder. // it shouldn't be installed because it is unlisted. packageRepository.Add(PackageUtility.CreatePackage( "NuGet.Build", version: "2.0", tools: new string[] { "invalid.targets" }, dependencies: new PackageDependency[] { new PackageDependency("NuGet.CommandLine") }, listed: false)); // this verify that we accepts prerelease packages packageRepository.Add(PackageUtility.CreatePackage( "NuGet.CommandLine", version: "1.0-alpha", tools: new string[] { "NuGet.exe" })); var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>(); packageRepositoryFactory.Setup(p => p.CreateRepository(NuGetConstants.DefaultFeedUrl)).Returns(packageRepository); var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(p => p.LoadPackageSources()).Returns(new[] { new PackageSource(NuGetConstants.DefaultFeedUrl) }); var packageRestore = CreateInstance( dte.Object, solutionManager.Object, fileSystemProvider.Object, packageRepositoryFactory.Object, packageSourceProvider: packageSourceProvider.Object, settings: defaultAppSettings.Object); // Act packageRestore.EnableCurrentSolutionForRestore(fromActivation: false); // Assert // verify that the files are copied to the .nuget sub folder under solution Assert.True(Directory.Exists(Path.Combine(tempSolutionPath, ".nuget"))); Assert.True(File.Exists(Path.Combine(tempSolutionPath, ".nuget\\NuGet.exe"))); Assert.True(File.Exists(Path.Combine(tempSolutionPath, ".nuget\\NuGet.targets"))); // verify that solution folder 'nuget' is added to solution solution.As<Solution2>().Verify(p => p.AddSolutionFolder(".nuget")); projectItems.Verify(p => p.AddFromFile(tempSolutionPath + "\\.nuget\\NuGet.exe")); projectItems.Verify(p => p.AddFromFile(tempSolutionPath + "\\.nuget\\NuGet.targets")); // verify that the Source Control mode is disabled var settings = new Settings(nugetFolderFileSystem); Assert.True(settings.IsSourceControlDisabled()); // verify that package restore consent is not set defaultAppSettings.Verify( s => s.SetValue("packageRestore", "enabled", It.Is<string>(v => v == "true" || v == "1")), Times.Never()); }
private PlaceholderListDatabase(ITracer tracer, PhysicalFileSystem fileSystem, string dataFilePath) : base(tracer, fileSystem, dataFilePath, collectionAppendsDirectlyToFile: true) { }
/// <summary> /// Get the config value give a setting name /// </summary> /// <param name="settingName">The name of the config setting</param> /// <param name="forceOutsideEnlistment"> /// If false, will run the call from inside the enlistment if the working dir found, /// otherwise it will run it from outside the enlistment. /// </param> /// <returns>The value found for the setting.</returns> public virtual Result GetFromConfig(string settingName, bool forceOutsideEnlistment = false, PhysicalFileSystem fileSystem = null) { string command = string.Format("config {0}", settingName); fileSystem = fileSystem ?? new PhysicalFileSystem(); // This method is called at clone time, so the physical repo may not exist yet. return (fileSystem.DirectoryExists(this.workingDirectoryRoot) && !forceOutsideEnlistment ? this.InvokeGitAgainstDotGitFolder(command) : this.InvokeGitOutsideEnlistment(command)); }
public void CatalogTest_CreatePackageDetails() { using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { // Arrange var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new SourceSettings() }; var catalog = new Catalog(context); var testPackage = new TestPackageContext() { Nuspec = new TestNuspecContext() { Id = "packageA", Version = "1.0.0-alpha.1", Authors = "authorA, authorB", Copyright = "Copyright info", Description = "Package A", IconUrl = "http://tempuri.org/icon.png", LicenseUrl = "http://tempuri.org/license.html", Language = "en-us", MinClientVersion = "3.3.0", DevelopmentDependency = "true", Owners = "ownerA, ownerB", ProjectUrl = "http://tempuri.org/project.html", ReleaseNotes = "release 1.0", RequireLicenseAcceptance = "true", Summary = "package summary.", Tags = "tagA tagB tagC", Title = "packageA title", Dependencies = new List <PackageDependencyGroup>() { new PackageDependencyGroup(NuGetFramework.AnyFramework, new List <PackageDependency>() { new PackageDependency("packageB", VersionRange.Parse("1.0.0")) }), new PackageDependencyGroup(NuGetFramework.Parse("net46"), new List <PackageDependency>()), new PackageDependencyGroup(NuGetFramework.Parse("net45"), new List <PackageDependency>() { new PackageDependency("packageAll"), new PackageDependency("packageExact", VersionRange.Parse("[2.0.0]")), }), }, FrameworkAssemblies = new List <KeyValuePair <string, List <NuGetFramework> > >() { new KeyValuePair <string, List <NuGetFramework> >("System.IO.Compression", new List <NuGetFramework>() { NuGetFramework.Parse("net45"), NuGetFramework.Parse("win8") }), new KeyValuePair <string, List <NuGetFramework> >("System.Threading", new List <NuGetFramework>() { NuGetFramework.Parse("net40") }), new KeyValuePair <string, List <NuGetFramework> >("System.All", new List <NuGetFramework>() { }) }, } }; var zipFile = testPackage.Create(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = new PackageInput() { Identity = new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0-alpha.1")), NupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0-alpha.1/packageA.1.0.0-alpha.1.nupkg"), Zip = zip, Package = new PackageArchiveReader(zip), PackagePath = zipFile.FullName }; // Act var actual = catalog.CreatePackageDetails(input); var dependencyGroups = actual["dependencyGroups"] as JArray; var frameworkAssemblyGroups = actual["frameworkAssemblyGroup"] as JArray; // Assert Assert.True(actual["@id"].ToString().EndsWith(".json")); Assert.Contains("/catalog/data/", actual["@id"].ToString()); Assert.Equal(testPackage.Nuspec.Authors, actual["authors"].ToString()); Assert.Equal(testPackage.Nuspec.Copyright, actual["copyright"].ToString()); Assert.Equal(testPackage.Nuspec.Description, actual["description"].ToString()); Assert.Equal(testPackage.Nuspec.IconUrl, actual["iconUrl"].ToString()); Assert.Equal(testPackage.Nuspec.LicenseUrl, actual["licenseUrl"].ToString()); Assert.Equal(testPackage.Nuspec.MinClientVersion, actual["minClientVersion"].ToString()); Assert.Equal(testPackage.Nuspec.ProjectUrl, actual["projectUrl"].ToString()); Assert.True(actual["requireLicenseAcceptance"].ToObject <bool>()); Assert.Equal(testPackage.Nuspec.Title, actual["title"].ToString()); Assert.Equal(testPackage.Nuspec.Id, actual["id"].ToString()); Assert.Equal(testPackage.Nuspec.Version, actual["version"].ToString()); Assert.Equal("tagA", ((JArray)actual["tags"])[0].ToString()); Assert.Equal("tagB", ((JArray)actual["tags"])[1].ToString()); Assert.Equal("tagC", ((JArray)actual["tags"])[2].ToString()); Assert.True(actual["packageContent"].ToString().EndsWith(".nupkg")); Assert.Null(dependencyGroups[0]["targetFramework"]); Assert.Equal("packageB", ((JArray)dependencyGroups[0]["dependencies"]).Single()["id"]); Assert.Equal("[1.0.0, )", ((JArray)dependencyGroups[0]["dependencies"]).Single()["range"]); Assert.Equal("net45", dependencyGroups[1]["targetFramework"]); Assert.NotNull(dependencyGroups[1]["dependencies"]); Assert.Equal("net46", dependencyGroups[2]["targetFramework"]); Assert.Null(dependencyGroups[2]["dependencies"]); Assert.Null(frameworkAssemblyGroups[0]["targetFramework"]); Assert.Equal("net40", frameworkAssemblyGroups[1]["targetFramework"]); Assert.Equal("net45", frameworkAssemblyGroups[2]["targetFramework"]); Assert.Equal("win8", frameworkAssemblyGroups[3]["targetFramework"]); Assert.Equal("System.All", ((JArray)frameworkAssemblyGroups[0]["assembly"]).Single()); Assert.Equal("System.Threading", ((JArray)frameworkAssemblyGroups[1]["assembly"]).Single()); Assert.Equal("System.IO.Compression", ((JArray)frameworkAssemblyGroups[2]["assembly"]).Single()); Assert.Equal("System.IO.Compression", ((JArray)frameworkAssemblyGroups[3]["assembly"]).Single()); } } }
public async Task AddRemove_AddTwoPackagesOfUniqueIds() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; var testPackage1 = new TestNupkg("packageA", "1.0.0"); var testPackage2 = new TestNupkg("packageB", "1.0.0"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); using (var zip1 = new ZipArchive(File.OpenRead(zipFile1.FullName), ZipArchiveMode.Read, false)) using (var zip2 = new ZipArchive(File.OpenRead(zipFile2.FullName), ZipArchiveMode.Read, false)) { var input1 = PackageInput.Create(zipFile1.FullName); var input2 = PackageInput.Create(zipFile2.FullName); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var regPackages = await registration.GetPackagesByIdAsync("packageA"); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(2, catalogEntries.Count); Assert.Equal(2, catalogExistingEntries.Count); Assert.Equal(1, regPackages.Count); Assert.Equal(2, indexPackages.Count); Assert.Equal(2, searchPackages.Count); Assert.Equal(2, autoCompletePackages.Count); } } }
public override ProductUpgraderPlatformStrategy CreateProductUpgraderPlatformInteractions( PhysicalFileSystem fileSystem, ITracer tracer) { return(new WindowsProductUpgraderPlatformStrategy(fileSystem, tracer)); }
public void ServerPackageRepositorySearchUnlisted() { var tempPath = Path.GetTempPath(); var workingDirectory = Path.Combine(tempPath, Guid.NewGuid().ToString()); try { // Arrange // create the server repo, from a directory containing a package. Func<string, bool, bool> settingsFunc = (key, defaultValue) => { if (key == "enableDelisting") { return true; } return defaultValue; }; CreateDirectory(workingDirectory); var packageFile = CreatePackage("test1", "1.0", workingDirectory); var fileSystem = new PhysicalFileSystem(workingDirectory); var serverRepository = new ServerPackageRepository( new DefaultPackagePathResolver(fileSystem), fileSystem, settingsFunc) { HashProvider = GetHashProvider().Object }; var packages = serverRepository.Search("test1", true).ToList(); Assert.Equal(1, packages.Count); Assert.Equal("test1", packages[0].Id); Assert.Equal("1.0", packages[0].Version.ToString()); // delist the package serverRepository.RemovePackage("test1", new SemanticVersion("1.0")); // verify that the package is not returned by search packages = serverRepository.Search("test1", true).ToList(); Assert.Equal(0, packages.Count); // Act: search with includeDelisted=true packages = serverRepository.Search( "test1", targetFrameworks: Enumerable.Empty<string>(), allowPrereleaseVersions: true, includeDelisted: true).ToList(); // Verify Assert.Equal(1, packages.Count); Assert.Equal("test1", packages[0].Id); Assert.Equal("1.0", packages[0].Version.ToString()); } finally { // Cleanup DeleteDirectory(workingDirectory); } }
/// <summary> /// Creates a new <seealso cref="DefaultStore"/>. /// </summary> /// <param name="path">The path of the directory where the storage files will be saved. /// If the path is <c>null</c>, the database is created in memory.</param> /// <param name="compress">Whether to compress data. Does not compress by default.</param> /// <param name="journal"> /// Enables or disables double write check to ensure durability. /// </param> /// <param name="indexCacheSize">Max number of pages in the index cache.</param> /// <param name="blockCacheSize">The capacity of the block cache.</param> /// <param name="txCacheSize">The capacity of the transaction cache.</param> /// <param name="statesCacheSize">The capacity of the states cache.</param> /// <param name="flush">Writes data direct to disk avoiding OS cache. Turned on by default. /// </param> /// <param name="readOnly">Opens database readonly mode. Turned off by default.</param> public DefaultStore( string path, bool compress = false, bool journal = true, int indexCacheSize = 50000, int blockCacheSize = 512, int txCacheSize = 1024, int statesCacheSize = 10000, bool flush = true, bool readOnly = false ) { _logger = Log.ForContext <DefaultStore>(); if (path is null) { _root = new MemoryFileSystem(); _memoryStream = new MemoryStream(); _db = new LiteDatabase(_memoryStream); } else { path = Path.GetFullPath(path); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var pfs = new PhysicalFileSystem(); _root = new SubFileSystem( pfs, pfs.ConvertPathFromInternal(path), owned: true ); var connectionString = new ConnectionString { Filename = Path.Combine(path, "index.ldb"), Journal = journal, CacheSize = indexCacheSize, Flush = flush, }; if (readOnly) { connectionString.Mode = FileMode.ReadOnly; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && Type.GetType("Mono.Runtime") is null) { // macOS + .NETCore doesn't support shared lock. connectionString.Mode = FileMode.Exclusive; } _db = new LiteDatabase(connectionString); } lock (_db.Mapper) { _db.Mapper.RegisterType( hash => hash.ToByteArray(), b => new HashDigest <SHA256>(b)); _db.Mapper.RegisterType( txid => txid.ToByteArray(), b => new TxId(b)); _db.Mapper.RegisterType( address => address.ToByteArray(), b => new Address(b.AsBinary)); } _root.CreateDirectory(TxRootPath); _txs = new SubFileSystem(_root, TxRootPath, owned: false); _root.CreateDirectory(BlockRootPath); _blocks = new SubFileSystem(_root, BlockRootPath, owned: false); _root.CreateDirectory(BlockPerceptionRootPath); _blockPerceptions = new SubFileSystem(_root, BlockPerceptionRootPath, owned: false); _txCache = new LruCache <TxId, object>(capacity: txCacheSize); _blockCache = new LruCache <HashDigest <SHA256>, BlockDigest>(capacity: blockCacheSize); }
public override FileBasedLock CreateFileBasedLock(PhysicalFileSystem fileSystem, ITracer tracer, string lockPath) { return(new MockFileBasedLock(fileSystem, tracer, lockPath)); }
public GitObjects(ITracer tracer, Enlistment enlistment, GitObjectsHttpRequestor objectRequestor, PhysicalFileSystem fileSystem = null) { this.Tracer = tracer; this.Enlistment = enlistment; this.GitObjectRequestor = objectRequestor; this.fileSystem = fileSystem ?? new PhysicalFileSystem(); this.checkData = true; }
public SiteObject(ILoggerFactory loggerFactory = null) { ReadmeAsIndex = true; ErrorRedirect = "/404.html"; var sharedFolder = Path.Combine(AppContext.BaseDirectory, SharedFolderName); _contentFileSystems = new List <IFileSystem>(); var sharedPhysicalFileSystem = new PhysicalFileSystem(); // Make sure that SharedFileSystem is a read-only filesystem SharedFileSystem = new ReadOnlyFileSystem(new SubFileSystem(sharedPhysicalFileSystem, sharedPhysicalFileSystem.ConvertPathFromInternal(sharedFolder))); SharedMetaFileSystem = SharedFileSystem.GetOrCreateSubFileSystem(LunetFolder); _fileSystem = new AggregateFileSystem(SharedFileSystem); // MetaFileSystem provides an aggregate view of the shared meta file system + the user meta file system _metaFileSystem = new AggregateFileSystem(SharedMetaFileSystem); MetaFileSystem = _metaFileSystem; ConfigFile = new FileEntry(_fileSystem, UPath.Root / DefaultConfigFileName); StaticFiles = new PageCollection(); Pages = new PageCollection(); DynamicPages = new PageCollection(); // Create the logger LoggerFactory = loggerFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(builder => { // Similar to builder.AddSimpleConsole // But we are using our own console that stays on the same line if the message doesn't have new lines builder.AddConfiguration(); builder.AddProvider(new LoggerProviderIntercept(this)) .AddFilter(LogFilter) .AddConsoleFormatter <SimpleConsoleFormatter, SimpleConsoleFormatterOptions>(configure => { configure.SingleLine = true; }); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <ILoggerProvider, ConsoleLoggerProvider>()); LoggerProviderOptions.RegisterProviderOptions <ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services); }); Log = LoggerFactory.CreateLogger("lunet"); ContentTypes = new ContentTypeManager(); DefaultPageExtension = DefaultPageExtensionValue; Html = new HtmlPage(this); CommandLine = new LunetCommandLine(this); Statistics = new SiteStatistics(); Scripts = new ScriptingPlugin(this); Content = new ContentPlugin(this); Plugins = new OrderedList <ISitePlugin>(); Builtins = new BuiltinsObject(this); ForceExcludes = new GlobCollection() { $"**/{LunetFolderName}/{BuildFolderName}/**", $"/{DefaultConfigFileName}", }; Excludes = new GlobCollection() { "**/~*/**", "**/.*/**", "**/_*/**", }; Includes = new GlobCollection() { $"**/{LunetFolderName}/**", }; SetValue(SiteVariables.ForceExcludes, ForceExcludes, true); SetValue(SiteVariables.Excludes, Excludes, true); SetValue(SiteVariables.Includes, Includes, true); SetValue(SiteVariables.Pages, Pages, true); _pluginBuilders = new ContainerBuilder(); _pluginBuilders.RegisterInstance(LoggerFactory).As <ILoggerFactory>(); _pluginBuilders.RegisterInstance(this); }
protected override void Execute(GVFSEnlistment enlistment) { if (this.List || ( !this.Prune && !this.Disable && string.IsNullOrEmpty(this.Add) && string.IsNullOrEmpty(this.Remove) && string.IsNullOrEmpty(this.Set) && string.IsNullOrEmpty(this.File))) { this.ListSparseFolders(enlistment.EnlistmentRoot); return; } this.CheckOptions(); using (JsonTracer tracer = new JsonTracer(GVFSConstants.GVFSEtwProviderName, SparseVerbName)) { tracer.AddLogFileEventListener( GVFSEnlistment.GetNewGVFSLogFileName(enlistment.GVFSLogsRoot, GVFSConstants.LogFileTypes.Sparse), EventLevel.Informational, Keywords.Any); HashSet <string> directories; bool needToChangeProjection = false; using (GVFSDatabase database = new GVFSDatabase(new PhysicalFileSystem(), enlistment.EnlistmentRoot, new SqliteDatabase())) { SparseTable sparseTable = new SparseTable(database); directories = sparseTable.GetAll(); List <string> foldersToRemove = new List <string>(); List <string> foldersToAdd = new List <string>(); if (this.Disable) { if (directories.Count > 0) { needToChangeProjection = true; foldersToRemove.AddRange(directories); directories.Clear(); } else { return; } } else if (!string.IsNullOrEmpty(this.Set) || !string.IsNullOrEmpty(this.File)) { IEnumerable <string> folders = null; if (!string.IsNullOrEmpty(this.Set)) { folders = this.ParseFolderList(this.Set); } else if (!string.IsNullOrEmpty(this.File)) { PhysicalFileSystem fileSystem = new PhysicalFileSystem(); folders = this.ParseFolderList(fileSystem.ReadAllText(this.File), folderSeparator: Environment.NewLine); } else { this.WriteMessage(tracer, "Invalid options specified."); throw new InvalidOperationException(); } foreach (string folder in folders) { if (!directories.Contains(folder)) { needToChangeProjection = true; foldersToAdd.Add(folder); } else { // Remove from directories so that the only directories left in the directories collection // will be the ones that will need to be removed from sparse set directories.Remove(folder); } } if (directories.Count > 0) { needToChangeProjection = true; foldersToRemove.AddRange(directories); } } else { // Process adds and removes foreach (string folder in this.ParseFolderList(this.Remove)) { if (directories.Contains(folder)) { needToChangeProjection = true; directories.Remove(folder); foldersToRemove.Add(folder); } } foreach (string folder in this.ParseFolderList(this.Add)) { if (!directories.Contains(folder)) { needToChangeProjection = true; directories.Add(folder); foldersToAdd.Add(folder); } } } if (needToChangeProjection || this.Prune) { if (directories.Count > 0) { // Make sure there is a clean git status before allowing sparse set to change this.CheckGitStatus(tracer, enlistment, directories); } this.UpdateSparseFolders(tracer, sparseTable, foldersToRemove, foldersToAdd); } if (needToChangeProjection) { // Force a projection update to get the current inclusion set this.ForceProjectionChange(tracer, enlistment); tracer.RelatedInfo("Projection updated after adding or removing folders."); } else { this.WriteMessage(tracer, "No folders to update in sparse set."); } if (this.Prune && directories.Count > 0) { this.PruneFoldersOutsideSparse(tracer, enlistment, sparseTable); } } } }
public void ShadowScopeCompleteWithDirectoryConflict() { var logger = Mock.Of <ILogger>(); var path = IOHelper.MapPath("FileSysTests"); var shadowfs = IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; var phy = new PhysicalFileSystem(path, "ignore"); var container = Mock.Of <IFactory>(); var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem <FS>(phy); var sw = (ShadowWrapper)fs.InnerFileSystem; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f1.txt", ms); Assert.IsTrue(phy.FileExists("sub/f1.txt")); string id; scopedFileSystems = true; // pretend we have a scope var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId()); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); Assert.IsFalse(phy.FileExists("sub/f2.txt")); // pretend we're another thread w/out scope scopedFileSystems = false; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("bar"))) sw.AddFile("sub/f2.txt/f2.txt", ms); scopedFileSystems = true; // pretend we have a scope Assert.IsTrue(phy.FileExists("sub/f2.txt/f2.txt")); // other thread has written out to fs using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f3.txt", ms); Assert.IsFalse(phy.FileExists("sub/f3.txt")); scope.Complete(); try { // no way this can work since we're trying to write a file // but there's now a directory with the same name on the real fs scope.Dispose(); Assert.Fail("Expected AggregateException."); } catch (AggregateException ae) { Assert.AreEqual(1, ae.InnerExceptions.Count); var e = ae.InnerExceptions[0]; Assert.IsNotNull(e.InnerException); Assert.IsInstanceOf <AggregateException>(e); ae = (AggregateException)e; Assert.AreEqual(1, ae.InnerExceptions.Count); e = ae.InnerExceptions[0]; Assert.IsNotNull(e.InnerException); Assert.IsInstanceOf <Exception>(e.InnerException); } // still, the rest of the changes has been applied ok Assert.IsTrue(phy.FileExists("sub/f3.txt")); }
private void PackageRestore(ProjectPackageReferenceFile projectPackageReferenceFile) { if (HasCanceled()) { return; } var repoSettings = ServiceLocator.GetInstance<IRepositorySettings>(); var fileSystem = new PhysicalFileSystem(repoSettings.RepositoryPath); var projectName = projectPackageReferenceFile.Project.GetName(); try { WriteLine(VerbosityLevel.Normal, Resources.RestoringPackagesForProject, projectName); WriteLine(VerbosityLevel.Detailed, Resources.RestoringPackagesListedInFile, projectPackageReferenceFile.FullPath); RestorePackages(projectPackageReferenceFile.FullPath, fileSystem); } catch (Exception ex) { var exceptionMessage = _msBuildOutputVerbosity >= (int)VerbosityLevel.Detailed ? ex.ToString() : ex.Message; var message = String.Format( CultureInfo.CurrentCulture, Resources.PackageRestoreFailedForProject, projectName, exceptionMessage); WriteLine(VerbosityLevel.Quiet, message); ActivityLog.LogError(LogEntrySource, message); VsUtility.ShowError(_errorListProvider, TaskErrorCategory.Error, TaskPriority.High, message, hierarchyItem: null); _hasError = true; } finally { WriteLine(VerbosityLevel.Normal, Resources.PackageRestoreFinishedForProject, projectName); } }
/// <summary> /// Safely gets the config value give a setting name /// </summary> /// <param name="settingName">The name of the config setting</param> /// <param name="forceOutsideEnlistment"> /// If false, will run the call from inside the enlistment if the working dir found, /// otherwise it will run it from outside the enlistment. /// </param> /// <param value>The value found for the config setting.</param> /// <returns>True if the config call was successful, false otherwise.</returns> public bool TryGetFromConfig(string settingName, bool forceOutsideEnlistment, out string value, PhysicalFileSystem fileSystem = null) { value = null; try { Result result = this.GetFromConfig(settingName, forceOutsideEnlistment, fileSystem); if (!result.HasErrors) { value = result.Output; return(true); } } catch { } return(false); }
private static ICollection<InstalledPackageReference> GetInstalledPackageReferences(string fullConfigFilePath, string projectName) { var projectFileSystem = new PhysicalFileSystem(Path.GetDirectoryName(fullConfigFilePath)); string configFileName = Path.GetFileName(fullConfigFilePath); PackageReferenceFile packageReferenceFile = new PackageReferenceFile(projectFileSystem, configFileName, projectName); return CommandLineUtility.GetInstalledPackageReferences(packageReferenceFile, requireVersion: true); }
public void CallingEnableCurrentSolutionDoNotDownloadPackageIfPresentInLocalCache() { // Arrange string tempSolutionPath = CreateTempFolder(); // setup SolutionManager var solutionManager = new Mock<ISolutionManager>(); solutionManager.Setup(p => p.IsSolutionOpen).Returns(true); solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath); // setup file system var fileSystem = new PhysicalFileSystem(tempSolutionPath); var fileSystemProvider = new Mock<IFileSystemProvider>(MockBehavior.Strict); fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem); var nugetFolderFileSystem = new PhysicalFileSystem(tempSolutionPath + "\\.nuget"); fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath + "\\.nuget")).Returns(nugetFolderFileSystem); // setup DTE var dte = new Mock<DTE>(); var projectItems = new Mock<ProjectItems>(); var solutionFolder = new Mock<Project>(); solutionFolder.Setup(s => s.Name).Returns(".nuget"); solutionFolder.SetupGet(s => s.ProjectItems).Returns(projectItems.Object); var solution = new Mock<Solution>(); solution.As<Solution2>().Setup(p => p.AddSolutionFolder(".nuget")).Returns(solutionFolder.Object); var projects = new MockProjects(new Project[0]); solution.As<Solution2>().Setup(s => s.Projects).Returns(projects); dte.SetupGet(p => p.Solution).Returns(solution.Object); // setup package repository var packageRepository = new MockPackageRepository(); var packageA = new Mock<IPackage>(MockBehavior.Strict); packageA.Setup(p => p.Id).Returns("NuGet.Build"); packageA.Setup(p => p.Version).Returns(new SemanticVersion("1.0")); packageA.Setup(p => p.IsLatestVersion).Returns(true); packageA.Setup(p => p.Listed).Returns(true); var packageB = new Mock<IPackage>(MockBehavior.Strict); packageB.Setup(p => p.Id).Returns("NuGet.CommandLine"); packageB.Setup(p => p.Version).Returns(new SemanticVersion("2.0")); packageB.Setup(p => p.IsLatestVersion).Returns(true); packageB.Setup(p => p.Listed).Returns(true); packageRepository.AddPackage(packageA.Object); packageRepository.AddPackage(packageB.Object); var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict); packageRepositoryFactory.Setup(p => p.CreateRepository("x:\\nugetsource")).Returns(packageRepository); var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(p => p.LoadPackageSources()).Returns(new[] { new PackageSource("x:\\nugetsource"), new PackageSource("y:\\me", "unabled", isEnabled: false), }); var localCache = new MockPackageRepository(); localCache.Add(PackageUtility.CreatePackage( "NuGet.Build", version: "1.0", tools: new string[] { "NuGet.targets" }, dependencies: new PackageDependency[] { new PackageDependency("NuGet.CommandLine") }, listed: true)); localCache.Add(PackageUtility.CreatePackage( "NuGet.CommandLine", version: "2.0", tools: new string[] { "NuGet.exe" }, listed: true)); var packageRestore = CreateInstance( dte.Object, solutionManager.Object, fileSystemProvider.Object, packageRepositoryFactory.Object, localCache: localCache, packageSourceProvider: packageSourceProvider.Object); // Act packageRestore.EnableCurrentSolutionForRestore(fromActivation: false); // Assert packageA.Verify(p => p.GetFiles(), Times.Never()); packageB.Verify(p => p.GetFiles(), Times.Never()); }
public void TestFileExceptions() { var fs = new PhysicalFileSystem(); var path = fs.ConvertPathFromInternal(SystemPath); var fileName = $"toto-{Guid.NewGuid()}.txt"; var filePath = path / fileName; fs.CreateFile(filePath).Dispose(); var filePathNotExist = path / "FileDoesNotExist.txt"; var systemFilePath = Path.Combine(SystemPath, fileName); // Try to create a folder on an unauthorized location try { // CreateFile Assert.Throws <UnauthorizedAccessException>(() => fs.CreateFile("/toto.txt")); // Length Assert.Throws <UnauthorizedAccessException>(() => fs.GetFileLength("/toto.txt")); // ConvertPathFromInternal / ConvertPathToInternal Assert.Throws <NotSupportedException>(() => fs.ConvertPathFromInternal(@"\\network\toto.txt")); Assert.Throws <NotSupportedException>(() => fs.ConvertPathFromInternal(@"zx:\toto.txt")); Assert.Throws <ArgumentException>(() => fs.ConvertPathToInternal(@"/toto.txt")); Assert.Throws <ArgumentException>(() => fs.ConvertPathToInternal(@"/mnt/yo/toto.txt")); // LastWriteTime, LastAccessTime, CreationTime Assert.Throws <DirectoryNotFoundException>(() => fs.GetLastWriteTime("/toto.txt")); Assert.Throws <DirectoryNotFoundException>(() => fs.GetLastAccessTime("/toto.txt")); Assert.Throws <DirectoryNotFoundException>(() => fs.GetCreationTime("/toto.txt")); Assert.Throws <UnauthorizedAccessException>(() => fs.SetLastWriteTime("/", DateTime.Now)); Assert.Throws <UnauthorizedAccessException>(() => fs.SetLastAccessTime("/", DateTime.Now)); Assert.Throws <UnauthorizedAccessException>(() => fs.SetCreationTime("/", DateTime.Now)); Assert.Throws <UnauthorizedAccessException>(() => fs.SetLastWriteTime("/mnt", DateTime.Now)); Assert.Throws <UnauthorizedAccessException>(() => fs.SetLastAccessTime("/mnt", DateTime.Now)); Assert.Throws <UnauthorizedAccessException>(() => fs.SetCreationTime("/mnt", DateTime.Now)); Assert.Throws <DirectoryNotFoundException>(() => fs.SetLastWriteTime("/toto.txt", DateTime.Now)); Assert.Throws <DirectoryNotFoundException>(() => fs.SetLastAccessTime("/toto.txt", DateTime.Now)); Assert.Throws <DirectoryNotFoundException>(() => fs.SetCreationTime("/toto.txt", DateTime.Now)); // FileAttributes Assert.Throws <DirectoryNotFoundException>(() => fs.GetAttributes("/toto.txt")); Assert.Throws <DirectoryNotFoundException>(() => fs.SetAttributes("/toto.txt", FileAttributes.ReadOnly)); Assert.Throws <UnauthorizedAccessException>(() => fs.SetAttributes("/", FileAttributes.ReadOnly)); // CopyFile Assert.Throws <UnauthorizedAccessException>(() => fs.CopyFile("/toto.txt", filePath, true)); Assert.Throws <UnauthorizedAccessException>(() => fs.CopyFile(filePath, "/toto.txt", true)); // Delete Assert.Throws <UnauthorizedAccessException>(() => fs.DeleteFile("/toto.txt")); // Move Assert.Throws <UnauthorizedAccessException>(() => fs.MoveFile("/toto.txt", filePath)); Assert.Throws <UnauthorizedAccessException>(() => fs.MoveFile(filePath, "/toto.txt")); // ReplaceFile Assert.Throws <FileNotFoundException>(() => fs.ReplaceFile("/toto.txt", filePath, filePath, true)); Assert.Throws <FileNotFoundException>(() => fs.ReplaceFile(filePath, "/toto.txt", filePath, true)); Assert.Throws <UnauthorizedAccessException>(() => fs.ReplaceFile(filePath, filePath, "/toto.txt", true)); Assert.Throws <FileNotFoundException>(() => fs.ReplaceFile(filePathNotExist, filePath, filePath, true)); Assert.Throws <FileNotFoundException>(() => fs.ReplaceFile(filePath, filePathNotExist, filePath, true)); } finally { SafeDeleteFile(systemFilePath); } }
private void UpdatePackages(IMSBuildProjectSystem project, string repositoryPath = null, IPackageRepository sourceRepository = null) { // Resolve the repository path repositoryPath = repositoryPath ?? GetRepositoryPath(project.Root); var sharedRepositoryFileSystem = new PhysicalFileSystem(repositoryPath); var pathResolver = new DefaultPackagePathResolver(sharedRepositoryFileSystem); // Create the local and source repositories var sharedPackageRepository = new SharedPackageRepository(pathResolver, sharedRepositoryFileSystem, sharedRepositoryFileSystem); var localRepository = new PackageReferenceRepository(project, project.ProjectName, sharedPackageRepository); sourceRepository = sourceRepository ?? AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source); Console.WriteLine(LocalizedResourceManager.GetString("UpdatingProject"), project.ProjectName); UpdatePackages(localRepository, sharedRepositoryFileSystem, sharedPackageRepository, sourceRepository, localRepository, pathResolver, project); project.Save(); }
public void TestFile() { var fs = new PhysicalFileSystem(); var path = fs.ConvertPathFromInternal(SystemPath); var fileName = $"toto-{Guid.NewGuid()}.txt"; var filePath = path / fileName; var filePathDest = path / Path.ChangeExtension(fileName, "dest"); var filePathBack = path / Path.ChangeExtension(fileName, "bak"); var systemFilePath = Path.Combine(SystemPath, fileName); var systemFilePathDest = fs.ConvertPathToInternal(filePathDest); var systemFilePathBack = fs.ConvertPathToInternal(filePathBack); try { // CreateFile / OpenFile var fileStream = fs.CreateFile(filePath); var buffer = Encoding.UTF8.GetBytes("This is a test"); fileStream.Write(buffer, 0, buffer.Length); fileStream.Dispose(); // FileLength Assert.Equal(buffer.Length, fs.GetFileLength(filePath)); // LastAccessTime // LastWriteTime // CreationTime Assert.Equal(File.GetLastWriteTime(systemFilePath), fs.GetLastWriteTime(filePath)); Assert.Equal(File.GetLastAccessTime(systemFilePath), fs.GetLastAccessTime(filePath)); Assert.Equal(File.GetCreationTime(systemFilePath), fs.GetCreationTime(filePath)); var lastWriteTime = DateTime.Now + TimeSpan.FromSeconds(10); var lastAccessTime = DateTime.Now + TimeSpan.FromSeconds(11); var creationTime = DateTime.Now + TimeSpan.FromSeconds(12); fs.SetLastWriteTime(filePath, lastWriteTime); fs.SetLastAccessTime(filePath, lastAccessTime); fs.SetCreationTime(filePath, creationTime); Assert.Equal(lastWriteTime, fs.GetLastWriteTime(filePath)); Assert.Equal(lastAccessTime, fs.GetLastAccessTime(filePath)); Assert.Equal(creationTime, fs.GetCreationTime(filePath)); // FileAttributes Assert.Equal(File.GetAttributes(systemFilePath), fs.GetAttributes(filePath)); var attributes = fs.GetAttributes(filePath); attributes |= FileAttributes.ReadOnly; fs.SetAttributes(filePath, attributes); Assert.Equal(File.GetAttributes(systemFilePath), fs.GetAttributes(filePath)); attributes &= ~FileAttributes.ReadOnly; fs.SetAttributes(filePath, attributes); Assert.Equal(File.GetAttributes(systemFilePath), fs.GetAttributes(filePath)); // FileExists Assert.True(File.Exists(systemFilePath)); Assert.True(fs.FileExists(filePath)); // CopyFile fs.CopyFile(filePath, filePathDest, true); Assert.True(File.Exists(systemFilePathDest)); Assert.True(fs.FileExists(filePathDest)); // DeleteFile fs.DeleteFile(filePath); Assert.False(File.Exists(systemFilePath)); Assert.False(fs.FileExists(filePath)); // MoveFile fs.MoveFile(filePathDest, filePath); Assert.False(File.Exists(systemFilePathDest)); Assert.False(fs.FileExists(filePathDest)); Assert.True(File.Exists(systemFilePath)); Assert.True(fs.FileExists(filePath)); // ReplaceFile // copy file to filePathDest fs.CopyFile(filePath, filePathDest, true); // Change src file var filestream2 = fs.OpenFile(filePath, FileMode.Open, FileAccess.ReadWrite); var buffer2 = Encoding.UTF8.GetBytes("This is a test 123"); filestream2.Write(buffer2, 0, buffer2.Length); filestream2.Dispose(); Assert.Equal(buffer2.Length, fs.GetFileLength(filePath)); // Perform ReplaceFile fs.ReplaceFile(filePath, filePathDest, filePathBack, true); Assert.False(fs.FileExists(filePath)); Assert.True(fs.FileExists(filePathDest)); Assert.True(fs.FileExists(filePathBack)); Assert.Equal(buffer2.Length, fs.GetFileLength(filePathDest)); Assert.Equal(buffer.Length, fs.GetFileLength(filePathBack)); // RootFileSystem fs.GetLastWriteTime("/"); fs.GetLastAccessTime("/"); fs.GetCreationTime("/"); fs.GetLastWriteTime("/mnt"); fs.GetLastAccessTime("/mnt"); fs.GetCreationTime("/mnt"); fs.GetLastWriteTime("/mnt/c"); fs.GetLastAccessTime("/mnt/c"); fs.GetCreationTime("/mnt/c"); fs.GetAttributes("/mnt/c"); var sysAttr = FileAttributes.Directory | FileAttributes.System | FileAttributes.ReadOnly; Assert.True((fs.GetAttributes("/") & (sysAttr)) == sysAttr); Assert.True((fs.GetAttributes("/mnt") & (sysAttr)) == sysAttr); } finally { SafeDeleteFile(systemFilePath); SafeDeleteFile(systemFilePathDest); SafeDeleteFile(systemFilePathBack); } }
private void PackageRestore(Solution solution) { WriteLine(VerbosityLevel.Normal, Resources.RestoringPackagesOfSolution, solution.FullName); var repoSettings = ServiceLocator.GetInstance<IRepositorySettings>(); var fileSystem = new PhysicalFileSystem(repoSettings.RepositoryPath); try { var packageReferenceFileName = Path.Combine( GetNuGetSolutionFolder(solution), PackageReferenceFile); RestorePackages(packageReferenceFileName, fileSystem); } catch (Exception ex) { var message = String.Format(CultureInfo.CurrentCulture, Resources.PackageRestoreFailedForSolution, solution.FullName, ex.Message); WriteLine(VerbosityLevel.Quiet, message); ActivityLog.LogError(LogEntrySource, message); } finally { WriteLine(VerbosityLevel.Normal, Resources.PackageRestoreFinishedForSolution, solution.FullName); } }
public async Task AddRemove_AddMultipleBatchesCIOnly() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, SymbolsEnabled = true } }; var identities = new HashSet <PackageIdentity>(); var ids = new[] { "a", "b", "c", "d", "e", "f", "g" }; foreach (var id in ids) { for (var i = 0; i < 1000; i++) { var testPackage = new TestNupkg(id, $"{i}.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); identities.Add(new PackageIdentity(testPackage.Nuspec.Id, NuGetVersion.Parse(testPackage.Nuspec.Version))); } } // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogPackages = await catalog.GetPackagesAsync(); var regPackages = new HashSet <PackageIdentity>(); foreach (var id in ids) { regPackages.UnionWith(await registration.GetPackagesByIdAsync(id)); } var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(identities.Count, catalogEntries.Count); Assert.Equal(identities.Count, catalogExistingEntries.Count); regPackages.Count.Should().Be(identities.Count); Assert.Equal(identities.Count, indexPackages.Count); Assert.Equal(identities.Count, searchPackages.Count); Assert.Equal(ids.Length, autoCompletePackages.Count); foreach (var entry in catalogEntries) { Assert.Equal(SleetOperation.Add, entry.Operation); } } }
public void CatalogTest_CreatePackageDetails_Minimal() { using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { // Arrange var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new SourceSettings() }; var catalog = new Catalog(context); var testPackage = new TestPackageContext() { Nuspec = new TestNuspecContext() { Id = "packageA", Version = "1.0.0" } }; var zipFile = testPackage.Create(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = new PackageInput() { Identity = new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), NupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0/packageA.1.0.0.nupkg"), Zip = zip, Package = new PackageArchiveReader(zip), PackagePath = zipFile.FullName }; // Act var actual = catalog.CreatePackageDetails(input); var dependencyGroups = actual["dependencyGroups"] as JArray; var frameworkAssemblyGroups = actual["frameworkAssemblyGroup"] as JArray; var tags = actual["tags"] as JArray; // Assert Assert.True(actual["@id"].ToString().EndsWith(".json")); Assert.Equal(string.Empty, actual["authors"].ToString()); Assert.Equal(string.Empty, actual["copyright"].ToString()); Assert.Equal(string.Empty, actual["description"].ToString()); Assert.Equal(string.Empty, actual["iconUrl"].ToString()); Assert.Equal(string.Empty, actual["licenseUrl"].ToString()); Assert.Null(actual["minClientVersion"]); Assert.Equal(string.Empty, actual["projectUrl"].ToString()); Assert.False(actual["requireLicenseAcceptance"].ToObject <bool>()); Assert.Null(actual["title"]); Assert.Equal(testPackage.Nuspec.Id, actual["id"].ToString()); Assert.Equal(testPackage.Nuspec.Version, actual["version"].ToString()); Assert.True(actual["packageContent"].ToString().EndsWith(".nupkg")); Assert.Equal(0, dependencyGroups.Count); Assert.Equal(0, frameworkAssemblyGroups.Count); Assert.Equal(0, tags.Count); } } }
public LocalCacheResolver(GVFSEnlistment enlistment, PhysicalFileSystem fileSystem = null) { this.fileSystem = fileSystem ?? new PhysicalFileSystem(); this.enlistment = enlistment; }