public static void Chmod(string permission, string filePath, IEnvironment environment, IDeploymentSettingsManager deploymentSettingManager, ILogger logger) { var folder = Path.GetDirectoryName(filePath); var exeFactory = new ExternalCommandFactory(environment, deploymentSettingManager, null); Executable exe = exeFactory.BuildCommandExecutable("/bin/chmod", folder, deploymentSettingManager.GetCommandIdleTimeout(), logger); exe.Execute("{0} {1}", permission, filePath); }
public bool UninstallExtension(string id) { string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = GetLocalExtension(id, checkLatest: false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { throw new DirectoryNotFoundException(installationDirectory); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); return GetLocalExtension(id, checkLatest: false) == null; }
private IPackage InstallExtension(IPackage package, string installationDirectory) { try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } foreach (IPackageFile file in package.GetContentFiles()) { // It is necessary to place applicationHost.xdt under site extension root. string contentFilePath = file.Path.Substring("content/".Length); string fullPath = Path.Combine(installationDirectory, contentFilePath); FileSystemHelpers.CreateDirectory(Path.GetDirectoryName(fullPath)); using (Stream writeStream = FileSystemHelpers.OpenWrite(fullPath), readStream = file.GetStream()) { OperationManager.Attempt(() => readStream.CopyTo(writeStream)); } } // If there is no xdt file, generate default. GenerateApplicationHostXdt(installationDirectory, '/' + package.Id, isPreInstalled: false); OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Id)); var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); string packageFilePath = GetNuGetPackageFile(package.Id, package.Version.ToString()); using ( Stream readStream = package.GetStream(), writeStream = FileSystemHelpers.OpenWrite(packageFilePath)) { OperationManager.Attempt(() => readStream.CopyTo(writeStream)); } } catch (Exception ex) { ITracer tracer = _traceFactory.GetTracer(); tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return _localRepository.FindPackage(package.Id); }
public async Task<bool> UninstallExtension(string id) { ITracer tracer = _traceFactory.GetTracer(); string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = await GetLocalExtension(id, checkLatest: false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { tracer.TraceError("Site extension {0} not found.", id); throw new DirectoryNotFoundException(installationDirectory); } if (IsInstalledToWebRoot(id)) { // special handling for package that install in wwwroot instead of under site extension folder tracer.Trace("Clear all content in wwwroot"); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.WebRootPath)); } else { // default action for site extension uninstall // only site extension has below infomation var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { using (tracer.Step("Execute uninstall.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } using (tracer.Step("Remove site extension job")) { OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); } } using (tracer.Step("Delete site extension package, directory and arm settings")) { OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); SiteExtensionStatus armSettings = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer); await armSettings.RemoveStatus(); } return await GetLocalExtension(id, checkLatest: false) == null; }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task<UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, string feedUrl, SiteExtensionInfo.SiteExtensionType type, ITracer tracer) { try { EnsureInstallationEnviroment(installationDirectory, tracer); string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToNormalizedString()); bool packageExisted = FileSystemHelpers.DirectoryExists(installationDirectory); SourceRepository remoteRepo = GetRemoteRepository(feedUrl); using (tracer.Step("Download site extension: {0}", package.Identity)) { string extractPath = installationDirectory; if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { extractPath = _environment.WebRootPath; FileSystemHelpers.EnsureDirectory(extractPath); } // Copy/update content folder // Copy/update nupkg file for package list/lookup if (packageExisted) { await remoteRepo.UpdateLocalPackage(_localRepository, package.Identity, extractPath, packageLocalFilePath, tracer); } else { FileSystemHelpers.EnsureDirectory(installationDirectory); await remoteRepo.DownloadPackageToFolder(package.Identity, extractPath, packageLocalFilePath); } if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { // if install to WebRoot, check if there is any xdt file come with package // if there is one, move it to site extension folder string xdtFile = Path.Combine(extractPath, Constants.ApplicationHostXdtFileName); if (File.Exists(xdtFile)) { tracer.Trace("Use xdt file from package."); string newXdtFile = Path.Combine(installationDirectory, Constants.ApplicationHostXdtFileName); tracer.Trace("Moving {0} to {1}", xdtFile, newXdtFile); FileSystemHelpers.MoveFile(xdtFile, newXdtFile); } else { tracer.Trace("No xdt file come with package."); } } } // ignore below action if we install packge to wwwroot if (SiteExtensionInfo.SiteExtensionType.WebRoot != type) { // If there is no xdt file, generate default. using (tracer.Step("Check if applicationhost.xdt file existed.")) { GenerateApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, isPreInstalled: false, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return await _localRepository.GetLatestPackageById(package.Identity.Id); }
public bool UninstallExtension(string id) { string installationDirectory = GetInstallationDirectory(id); if (!FileSystemHelpers.DirectoryExists(installationDirectory)) { throw new DirectoryNotFoundException(installationDirectory); } OperationManager.Attempt(() => { var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); } FileSystemHelpers.DeleteDirectorySafe(installationDirectory); }); return !FileSystemHelpers.DirectoryExists(installationDirectory); }
public async Task<bool> UninstallExtension(string id) { ITracer tracer = _traceFactory.GetTracer(); string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = await GetLocalExtension(id, checkLatest: false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { tracer.TraceError("Site extension {0} not found.", id); throw new DirectoryNotFoundException(installationDirectory); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { using (tracer.Step("Execute uninstall.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } using (tracer.Step("Remove site extension job")) { OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); } using (tracer.Step("Delete site extension package and directory")) { OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); } return await GetLocalExtension(id, checkLatest: false) == null; }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task<UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, string feedUrl) { ITracer tracer = _traceFactory.GetTracer(); try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } SourceRepository remoteRepo = GetRemoteRepository(feedUrl); // Copy content folder // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); // package path from local repo string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToString()); using (tracer.Step("Download site extension: {0}", package.Identity)) { await remoteRepo.DownloadPackageToFolder(package.Identity, installationDirectory, pathToLocalCopyOfNudpk: packageLocalFilePath); } // If there is no xdt file, generate default. using (tracer.Step("Check if applicationhost.xdt file existed.")) { GenerateApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, isPreInstalled: false, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return await _localRepository.GetLatestPackageById(package.Identity.Id); }