Ejemplo n.º 1
0
        internal NuGetUpgrader(
            string currentVersion,
            ITracer tracer,
            bool dryRun,
            bool noVerify,
            PhysicalFileSystem fileSystem,
            NuGetUpgraderConfig config,
            NuGetFeed nuGetFeed,
            ICredentialStore credentialStore)
            : base(
                currentVersion,
                tracer,
                dryRun,
                noVerify,
                fileSystem)
        {
            this.nuGetUpgraderConfig = config;

            this.nuGetFeed       = nuGetFeed;
            this.credentialStore = credentialStore;

            // Extract the folder inside ProductUpgraderInfo.GetAssetDownloadsPath to ensure the
            // correct ACLs are in place
            this.ExtractedInstallerPath = Path.Combine(
                ProductUpgraderInfo.GetAssetDownloadsPath(),
                ExtractedInstallerDirectoryName);
        }
Ejemplo n.º 2
0
 public override bool TryPrepareDownloadDirectory(out string error)
 {
     return(this.FileSystem.TryCreateOrUpdateDirectoryToAdminModifyPermissions(
                this.Tracer,
                ProductUpgraderInfo.GetAssetDownloadsPath(),
                out error));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Try to load a NuGetUpgrader from config settings.
        /// <isConfigured>Flag to indicate whether the system is configured to use a NuGetUpgrader.
        /// A NuGetUpgrader can be set as the Upgrader to use, but it might not be properly configured.
        /// </isConfigured>
        /// <Returns>True if able to load a properly configured NuGetUpgrader<Returns>
        /// </summary>
        public static bool TryCreate(
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            bool dryRun,
            bool noVerify,
            out NuGetUpgrader nuGetUpgrader,
            out bool isConfigured,
            out string error)
        {
            NuGetUpgraderConfig upgraderConfig = new NuGetUpgraderConfig(tracer, new LocalGVFSConfig());

            nuGetUpgrader = null;
            isConfigured  = false;

            if (!upgraderConfig.TryLoad(out error))
            {
                nuGetUpgrader = null;
                return(false);
            }

            if (!(isConfigured = upgraderConfig.IsConfigured(out error)))
            {
                return(false);
            }

            // At this point, we have determined that the system is set up to use
            // the NuGetUpgrader

            if (!upgraderConfig.IsReady(out error))
            {
                return(false);
            }

            string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();

            if (string.IsNullOrEmpty(gitBinPath))
            {
                error = $"NuGetUpgrader: Unable to locate git installation. Ensure git is installed and try again.";
                return(false);
            }

            ICredentialStore credentialStore = new GitProcess(gitBinPath, workingDirectoryRoot: null, gvfsHooksRoot: null);

            nuGetUpgrader = new NuGetUpgrader(
                ProcessHelper.GetCurrentProcessVersion(),
                tracer,
                fileSystem,
                dryRun,
                noVerify,
                upgraderConfig,
                ProductUpgraderInfo.GetAssetDownloadsPath(),
                credentialStore);

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Try to load a NuGetUpgrader from config settings.
        /// <isConfigured>Flag to indicate whether the system is configured to use a NuGetUpgrader.
        /// A NuGetUpgrader can be set as the Upgrader to use, but it might not be properly configured.
        /// </isConfigured>
        /// <Returns>True if able to load a properly configured NuGetUpgrader<Returns>
        /// </summary>
        public static bool TryCreate(
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            LocalScalarConfig scalarConfig,
            ICredentialStore credentialStore,
            bool dryRun,
            bool noVerify,
            out NuGetUpgrader nuGetUpgrader,
            out bool isConfigured,
            out string error)
        {
            NuGetUpgraderConfig upgraderConfig = new NuGetUpgraderConfig(tracer, scalarConfig);

            nuGetUpgrader = null;
            isConfigured  = false;

            if (!upgraderConfig.TryLoad(out error))
            {
                nuGetUpgrader = null;
                return(false);
            }

            if (!(isConfigured = upgraderConfig.IsConfigured(out error)))
            {
                return(false);
            }

            // At this point, we have determined that the system is set up to use
            // the NuGetUpgrader

            if (!upgraderConfig.IsReady(out error))
            {
                return(false);
            }

            nuGetUpgrader = new NuGetUpgrader(
                ProcessHelper.GetCurrentProcessVersion(),
                tracer,
                fileSystem,
                dryRun,
                noVerify,
                upgraderConfig,
                ProductUpgraderInfo.GetAssetDownloadsPath(),
                credentialStore);

            return(true);
        }
        public override bool TryPrepareDownloadDirectory(out string error)
        {
            string directory = ProductUpgraderInfo.GetAssetDownloadsPath();

            Exception deleteDirectoryException;

            if (this.FileSystem.DirectoryExists(directory) &&
                !this.FileSystem.TryDeleteDirectory(directory, out deleteDirectoryException))
            {
                error = $"Failed to delete {directory} - {deleteDirectoryException.Message}";

                this.TraceException(deleteDirectoryException, nameof(this.TryPrepareDownloadDirectory), $"Error deleting {directory}.");
                return(false);
            }

            this.FileSystem.CreateDirectory(directory);

            error = null;
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Try to load a NuGetUpgrader from config settings.
        /// <isConfigured>Flag to indicate whether the system is configured to use a NuGetUpgrader.
        /// A NuGetUpgrader can be set as the Upgrader to use, but it might not be properly configured.
        /// </isConfigured>
        /// <Returns>True if able to load a properly configured NuGetUpgrader<Returns>
        /// </summary>
        public static bool TryCreate(
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            bool dryRun,
            bool noVerify,
            out NuGetUpgrader nuGetUpgrader,
            out bool isConfigured,
            out string error)
        {
            NuGetUpgraderConfig upgraderConfig = new NuGetUpgraderConfig(tracer, new LocalGVFSConfig());

            nuGetUpgrader = null;
            isConfigured  = false;

            if (!upgraderConfig.TryLoad(out error))
            {
                nuGetUpgrader = null;
                return(false);
            }

            if (!(isConfigured = upgraderConfig.IsConfigured(out error)))
            {
                return(false);
            }

            // At this point, we have determined that the system is set up to use
            // the NuGetUpgrader

            if (!upgraderConfig.IsReady(out error))
            {
                return(false);
            }

            string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();

            if (string.IsNullOrEmpty(gitBinPath))
            {
                error = $"NuGetUpgrader: Unable to locate git installation. Ensure git is installed and try again.";
                return(false);
            }

            string authUrl;

            if (!TryCreateAzDevOrgUrlFromPackageFeedUrl(upgraderConfig.FeedUrl, out authUrl, out error))
            {
                return(false);
            }

            if (!TryGetPersonalAccessToken(
                    gitBinPath,
                    authUrl,
                    tracer,
                    out string token,
                    out string getPatError))
            {
                error = $"NuGetUpgrader was not able to acquire Personal Access Token to access NuGet feed. Error: {getPatError}";
                tracer.RelatedError(error);
                return(false);
            }

            nuGetUpgrader = new NuGetUpgrader(
                ProcessHelper.GetCurrentProcessVersion(),
                tracer,
                fileSystem,
                dryRun,
                noVerify,
                upgraderConfig,
                ProductUpgraderInfo.GetAssetDownloadsPath(),
                token);

            return(true);
        }