/// <summary> /// Ensures smooth transition between mono based Kudu and KuduLite. /// <remarks> /// <list type="bullet"> /// <item> /// POST Receive GitHook File:This file was previously hard coded with mono path to launch kudu console. /// </item> /// <item> /// We will would use the OryxBuild in future for deployments, as a safety measure we clear /// the deployment script. /// </item> /// </list> /// </remarks> /// </summary> /// <param name="environment"></param> internal static void MigrateToNetCorePatch(IEnvironment environment) { // Get the repository path: // Use value in the settings.xml file if it is present. string repositoryPath = environment.RepositoryPath; IDeploymentSettingsManager settings = GetDeploymentSettingsManager(environment); if (settings != null) { var settingsRepoPath = DeploymentSettingsExtension.GetRepositoryPath(settings); repositoryPath = Path.Combine(environment.SiteRootPath, settingsRepoPath); } var gitPostReceiveHookFile = Path.Combine(repositoryPath, ".git", "hooks", "post-receive"); if (FileSystemHelpers.FileExists(gitPostReceiveHookFile)) { var fileText = FileSystemHelpers.ReadAllText(gitPostReceiveHookFile); var isRunningOnAzure = System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") != null; if (!EnvironmentHelper.IsDynamicInstallEnvironment()) { if (fileText.Contains("/usr/bin/mono")) { if (isRunningOnAzure) { FileSystemHelpers.WriteAllText(gitPostReceiveHookFile, fileText.Replace("/usr/bin/mono", "benv dotnet=2.2 dotnet")); } } else if (!fileText.Contains("benv") && fileText.Contains("dotnet") && isRunningOnAzure) { FileSystemHelpers.WriteAllText(gitPostReceiveHookFile, fileText.Replace("dotnet", "benv dotnet=2.2 dotnet")); } } else { // Dynamic Install should just contain dotnet if (fileText.Contains("benv") && fileText.Contains("dotnet") && isRunningOnAzure) { FileSystemHelpers.WriteAllText(gitPostReceiveHookFile, fileText.Replace("benv dotnet=2.2", "dotnet")); } } } if (FileSystemHelpers.DirectoryExists(Path.Combine(environment.RootPath, ".mono")) && FileSystemHelpers.FileExists(Path.Combine(environment.DeploymentToolsPath, "deploy.sh"))) { FileSystemHelpers.DeleteFileSafe(Path.Combine(environment.DeploymentToolsPath, "deploy.sh")); } }
public void Release() { LockExpiry = null; if (FileSystemHelpers.DirectoryExists(locksPath + "/deployment")) { //Console.WriteLine("Releasing Lock - RemovingDir"); _traceFactory.GetTracer().Trace("Releasing Deployment Lock"); FileSystemHelpers.DeleteDirectorySafe(locksPath + "/deployment"); } else { _traceFactory.GetTracer().Trace("Releasing Deployment Lock - There is NO LOCK HELD | ERROR"); } }
private IEnumerable <ScanOverviewResult> EnumerateResults(String mainScanDir) { if (FileSystemHelpers.DirectoryExists(mainScanDir)) { foreach (String scanFolderPath in FileSystemHelpers.GetDirectories(mainScanDir)) { ScanOverviewResult result = new ScanOverviewResult(); ScanStatusResult scanStatus = ReadScanStatusFile("", "", Constants.ScanStatusFile, scanFolderPath); result.Status = scanStatus; yield return(result); } } }
public override async Task RunAsync() { var functionAppRoot = string.IsNullOrEmpty(FolderName) ? Path.Combine(Environment.CurrentDirectory, FolderName) : ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); string outputPath; if (string.IsNullOrEmpty(OutputPath)) { outputPath = Path.Combine(Environment.CurrentDirectory, $"{Path.GetFileName(functionAppRoot)}.zip"); } else { outputPath = Path.Combine(Environment.CurrentDirectory, OutputPath); if (FileSystemHelpers.DirectoryExists(outputPath)) { outputPath = Path.Combine(outputPath, $"{Path.GetFileName(functionAppRoot)}.zip"); } } if (!FileSystemHelpers.FileExists(Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName))) { throw new CliException($"Can't find {Path.Combine(functionAppRoot, ScriptConstants.HostMetadataFileName)}"); } var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); if (FileSystemHelpers.FileExists(outputPath)) { ColoredConsole.WriteLine($"Deleting the old package {outputPath}"); try { FileSystemHelpers.FileDelete(outputPath); } catch (Exception) { throw new CliException($"Could not delete {outputPath}"); } } // Restore all valid extensions var installExtensionAction = new InstallExtensionAction(_secretsManager); await installExtensionAction.RunAsync(); var zipStream = await ZipHelper.GetAppZipFile(workerRuntime, functionAppRoot, BuildNativeDeps, NoBundler, additionalPackages : AdditionalPackages); ColoredConsole.WriteLine($"Creating a new package {outputPath}"); await FileSystemHelpers.WriteToFile(outputPath, zipStream); }
public 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. string xdtPath = Path.Combine(installationDirectory, "applicationHost.xdt"); if (!FileSystemHelpers.FileExists(xdtPath)) { string xdtContent = CreateDefaultXdtFile(package.Id); OperationManager.Attempt(() => FileSystemHelpers.WriteAllText(xdtPath, xdtContent)); } // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); string packageFilePath = Path.Combine(installationDirectory, String.Format("{0}.{1}.nupkg", package.Id, package.Version)); 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); return(null); } return(_localRepository.FindPackage(package.Id)); }
private static async Task DotnetTemplatesAction(string action) { var templatesLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "templates"); if (!FileSystemHelpers.DirectoryExists(templatesLocation)) { throw new CliException($"Can't find templates location. Looked under '{templatesLocation}'"); } foreach (var nupkg in FileSystemHelpers.GetFiles(templatesLocation, null, null, "*.nupkg")) { var exe = new Executable("dotnet", $"new --{action} \"{nupkg}\""); await exe.RunAsync(); } }
public static async Task <bool> BuildDotnetProject(string outputPath, string dotnetCliParams) { if (FileSystemHelpers.DirectoryExists(outputPath)) { FileSystemHelpers.DeleteDirectorySafe(outputPath); } var exe = new Executable("dotnet", $"build --output {outputPath} {dotnetCliParams}"); var exitCode = await exe.RunAsync(o => ColoredConsole.WriteLine(o), e => ColoredConsole.Error.WriteLine(e)); if (exitCode != 0) { throw new CliException("Error building project"); } return(true); }
private async Task SetLocalInfo(SiteExtensionInfo info) { string localPath = GetInstallationDirectory(info.Id); if (FileSystemHelpers.DirectoryExists(localPath)) { info.LocalPath = localPath; info.InstalledDateTime = FileSystemHelpers.GetLastWriteTimeUtc(info.LocalPath); await TryCheckLocalPackageLatestVersionFromRemote(info); } if (ExtensionRequiresApplicationHost(info)) { info.ExtensionUrl = GetFullUrl(GetUrlFromApplicationHost(localPath)); } else { info.ExtensionUrl = string.IsNullOrEmpty(info.LocalPath) ? null : GetFullUrl(info.ExtensionUrl); } foreach (var setting in GetSettingManager(info.Id).GetValues()) { if (string.Equals(setting.Key, _feedUrlSetting, StringComparison.OrdinalIgnoreCase)) { info.FeedUrl = setting.Value.Value <string>(); } else if (string.Equals(setting.Key, _installUtcTimestampSetting, StringComparison.OrdinalIgnoreCase)) { DateTime installedDateTime; if (DateTime.TryParse(setting.Value.Value <string>(), out installedDateTime)) { info.InstalledDateTime = installedDateTime.ToUniversalTime(); } } else if (string.Equals(setting.Key, _installationArgs, StringComparison.OrdinalIgnoreCase)) { info.InstallationArgs = setting.Value.Value <string>(); } } if (IsInstalledToWebRoot(info.Id)) { // override WebRoot type from setting // WebRoot is a special type that install package to wwwroot, when perform update we need to update new content to wwwroot even if type is not specified info.Type = SiteExtensionInfo.SiteExtensionType.WebRoot; } }
public async override Task RunAsync() { if (CommandChecker.CommandExists("dotnet")) { if (!string.IsNullOrEmpty(ConfigPath) && !FileSystemHelpers.DirectoryExists(ConfigPath)) { throw new CliArgumentsException("Invalid config path, please verify directory exists"); } var extensionsProj = await ExtensionsHelper.EnsureExtensionsProjectExistsAsync(_secretsManager, Csx, ConfigPath); if (string.IsNullOrEmpty(Package) && string.IsNullOrEmpty(Version)) { foreach (var extensionPackage in ExtensionsHelper.GetExtensionPackages()) { await AddPackage(extensionsProj, extensionPackage.Name, extensionPackage.Version); } } else if (!string.IsNullOrEmpty(Package) && !string.IsNullOrEmpty(Version)) { await AddPackage(extensionsProj, Package, Version); } else { throw new CliArgumentsException("Must specify extension package name and version", new CliArgument { Name = nameof(Package), Description = "Extension package name" }, new CliArgument { Name = nameof(Version), Description = "Extension package version" } ); } var syncAction = new SyncExtensionsAction(_secretsManager) { OutputPath = OutputPath, ConfigPath = ConfigPath }; await syncAction.RunAsync(); } else { ColoredConsole.Error.WriteLine(ErrorColor("Extensions command require dotnet on your path. Please make sure to install dotnet for your system from https://www.microsoft.com/net/download")); } }
public bool Lock(string operationName) { if (FileSystemHelpers.DirectoryExists(locksPath + "/deployment")) { // Directory exists implies a lock exists // Either lock info is still being written or it exists // If it exists check the expiry if (IsHeld) { //Console.WriteLine("LockOp - Lock Already Held"); return(false); } } //Console.WriteLine("LockOp - Creating Lock"); CreateLockInfoFile(operationName); return(true); }
internal static async Task <Stream> GetPythonDeploymentPackage(IEnumerable <string> files, string functionAppRoot, bool buildNativeDeps, string additionalPackages) { var reqTxtFile = Path.Combine(functionAppRoot, Constants.RequirementsTxt); if (!FileSystemHelpers.FileExists(reqTxtFile)) { throw new CliException($"{Constants.RequirementsTxt} is not found. " + $"{Constants.RequirementsTxt} is required for python function apps. Please make sure to generate one before publishing."); } var packagesLocation = Path.Combine(functionAppRoot, Constants.ExternalPythonPackages); if (FileSystemHelpers.DirectoryExists(packagesLocation)) { // Only update packages if checksum of requirements.txt does not match or a sync is forced if (await ArePackagesInSync(reqTxtFile, packagesLocation)) { ColoredConsole.WriteLine(Yellow($"Directory {Constants.ExternalPythonPackages} already in sync with {Constants.RequirementsTxt}. Skipping restoring dependencies...")); return(ZipHelper.CreateZip(files.Union(FileSystemHelpers.GetFiles(packagesLocation)), functionAppRoot)); } ColoredConsole.WriteLine($"Deleting the old {Constants.ExternalPythonPackages} directory"); FileSystemHelpers.DeleteDirectorySafe(Path.Combine(functionAppRoot, Constants.ExternalPythonPackages)); } FileSystemHelpers.EnsureDirectory(packagesLocation); if (buildNativeDeps) { if (CommandChecker.CommandExists("docker") && await DockerHelpers.VerifyDockerAccess()) { await RestorePythonRequirementsDocker(functionAppRoot, packagesLocation, additionalPackages); } else { throw new CliException("Docker is required to build native dependencies for python function apps"); } } else { await RestorePythonRequirementsPackapp(functionAppRoot, packagesLocation); } // Store a checksum of requirements.txt var md5FilePath = Path.Combine(packagesLocation, $"{Constants.RequirementsTxt}.md5"); await FileSystemHelpers.WriteAllTextToFileAsync(md5FilePath, SecurityHelpers.CalculateMd5(reqTxtFile)); return(ZipHelper.CreateZip(files.Union(FileSystemHelpers.GetFiles(packagesLocation)), functionAppRoot)); }
protected override void OnLockRelease() { // if installed failed, when release lock, we should also remove empty folder as well base.OnLockRelease(); try { string folder = Path.GetDirectoryName(_path); if (FileSystemHelpers.DirectoryExists(folder) && FileSystemHelpers.GetFiles(folder, "*").Length == 0) { FileSystemHelpers.DeleteDirectorySafe(folder); } } catch { // no-op } }
private void StartWatcher(object state) { try { lock (_lockObject) { // Check if there is a directory we can listen on if (!FileSystemHelpers.DirectoryExists(_watchedDirectoryPath)) { // If not check again in 30 seconds _startFileWatcherTimer.Change(CheckForWatcherTimeout, Timeout.Infinite); return; } // dispose existing _fileSystemWatcher in case of exception and retry DisposeWatcher(); // Start file system watcher _fileSystemWatcher = _filter != null ? new FileSystemWatcher(_watchedDirectoryPath, _filter) : new FileSystemWatcher(_watchedDirectoryPath); _fileSystemWatcher.Created += OnChanged; _fileSystemWatcher.Changed += OnChanged; _fileSystemWatcher.Deleted += OnChanged; _fileSystemWatcher.Renamed += OnChanged; _fileSystemWatcher.Error += OnError; _fileSystemWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite; _fileSystemWatcher.IncludeSubdirectories = true; _fileSystemWatcher.EnableRaisingEvents = true; // Refresh all jobs IEnumerable <string> jobNames = _listJobNames(true); foreach (string jobName in jobNames) { MarkJobUpdated(jobName); } } } catch (Exception ex) { _analytics.UnexpectedException(ex); // Retry in 30 seconds. _startFileWatcherTimer.Change(CheckForWatcherTimeout, Timeout.Infinite); } }
private void CacheJobBinaries(IJobLogger logger) { if (WorkingDirectory != null) { int currentHash = CalculateHashForJob(JobBinariesPath); int lastHash = CalculateHashForJob(WorkingDirectory); if (lastHash == currentHash) { return; } } SafeKillAllRunningJobInstances(logger); if (FileSystemHelpers.DirectoryExists(JobTempPath)) { FileSystemHelpers.DeleteDirectorySafe(JobTempPath, ignoreErrors: true); } if (FileSystemHelpers.DirectoryExists(JobTempPath)) { logger.LogWarning("Failed to delete temporary directory"); } try { var tempJobInstancePath = Path.Combine(JobTempPath, Path.GetRandomFileName()); FileSystemHelpers.CopyDirectoryRecursive(JobBinariesPath, tempJobInstancePath); UpdateAppConfigs(tempJobInstancePath); WorkingDirectory = tempJobInstancePath; } catch (Exception ex) { //Status = "Worker is not running due to an error"; //TraceError("Failed to copy bin directory: " + ex); logger.LogError("Failed to copy job files: " + ex); _analytics.UnexpectedException(ex); // job disabled WorkingDirectory = null; } }
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); }
public bool Lock(string operationName) { _traceFactory.GetTracer().Trace("Acquiring Deployment Lock"); if (FileSystemHelpers.DirectoryExists(locksPath + "/deployment")) { // Directory exists implies a lock exists // Either lock info is still being written or it exists // If it exists check the expiry if (IsHeld) { _traceFactory.GetTracer().Trace("Cannot Acquire Deployment Lock already held"); return(false); } } CreateLockInfoFile(operationName); _traceFactory.GetTracer().Trace("Acquired Deployment Lock"); return(true); }
private void AddOryxBuildCommand(StringBuilder args, DeploymentContext context, string source, string destination) { // If it is express build, we don't directly need to write to /home/site/wwwroot // So, we build into a different directory to avoid overlap // Additionally, we didn't run kudusync, and can just build directly from repository path if (Flags == BuildOptimizationsFlags.UseExpressBuild) { source = context.RepositoryPath; destination = OryxBuildConstants.FunctionAppBuildSettings.ExpressBuildSetup; // It is important to clean and recreate the directory to make sure no overwrite occurs if (FileSystemHelpers.DirectoryExists(destination)) { FileSystemHelpers.DeleteDirectorySafe(destination); } FileSystemHelpers.EnsureDirectory(destination); } OryxArgumentsHelper.AddOryxBuildCommand(args, source, destination); }
private void PreDeployment(ITracer tracer) { if (Environment.IsAzureEnvironment() && FileSystemHelpers.DirectoryExists(_environment.SSHKeyPath)) { string src = Path.GetFullPath(_environment.SSHKeyPath); string dst = Path.GetFullPath(Path.Combine(System.Environment.GetEnvironmentVariable("USERPROFILE"), Constants.SSHKeyPath)); if (!String.Equals(src, dst, StringComparison.OrdinalIgnoreCase)) { // copy %HOME%\.ssh to %USERPROFILE%\.ssh key to workaround // npm with private ssh git dependency using (tracer.Step("Copying SSH keys")) { FileSystemHelpers.CopyDirectoryRecursive(src, dst, overwrite: true); } } } }
/// <summary> /// Determines if Kudu Should Monitor Mounted Logs directory, /// or the mounted fs logs dir, if kudu /// </summary> /// <returns></returns> private static bool shouldMonitiorMountedLogsPath(string mountedDirPath) { int count = 0; string dateToday = DateTime.Now.ToString("yyyy_MM_dd"); if (FileSystemHelpers.DirectoryExists(mountedDirPath)) { // if more than two log files present that are generated today, // use this directory; first file for a date is the marker file foreach (var file in Directory.GetFiles(mountedDirPath, "*", SearchOption.AllDirectories)) { if (file.StartsWith(dateToday) && ++count > 1) { break; } } } return(count == 2); }
/// <summary> /// Handle both file and folder deletion, and ignore not found exception /// </summary> private void HandlingDeletion(OneDriveModel.OneDriveChange change, string wwwroot) { if (!change.IsDeleted) { return; } string fullPath = GetDestinationPath(wwwroot, change.Path); if (fullPath == null) { TraceMessage("Ignore folder {0}", change.Path); return; } try { if (FileSystemHelpers.FileExists(fullPath)) { FileSystemHelpers.DeleteFile(fullPath); TraceMessage("Deleted file {0}", fullPath); LogMessage(Resources.OneDriveDeletedFile, fullPath); } else if (FileSystemHelpers.DirectoryExists(fullPath)) { FileSystemHelpers.DeleteDirectorySafe(fullPath, ignoreErrors: false); TraceMessage("Deleted directory {0}", fullPath); LogMessage(Resources.OneDriveDeletedDirectory, fullPath); } else { TraceMessage("Not found: {0}. Unknown item type, skip deletion!", fullPath); } } catch (DirectoryNotFoundException) { TraceMessage("Directory Not found: {0}. Skip deletion!", fullPath); } catch (FileNotFoundException) { TraceMessage("File Not found: {0}. Skip deletion!", fullPath); } }
private void StartWatcher(object state) { try { lock (_lockObject) { // Check if there is a directory we can listen on if (!FileSystemHelpers.DirectoryExists(JobsBinariesPath)) { // If not check again in 30 seconds _startFileWatcherTimer.Change(CheckForWatcherTimeout, Timeout.Infinite); return; } // Start file system watcher _fileSystemWatcher = new FileSystemWatcher(JobsBinariesPath); _fileSystemWatcher.Created += OnChanged; _fileSystemWatcher.Changed += OnChanged; _fileSystemWatcher.Deleted += OnChanged; _fileSystemWatcher.Renamed += OnChanged; _fileSystemWatcher.Error += OnError; _fileSystemWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite; _fileSystemWatcher.IncludeSubdirectories = true; _fileSystemWatcher.EnableRaisingEvents = true; // Refresh all jobs IEnumerable <ContinuousJob> continuousJobs = ListJobs(); IEnumerable <string> continuousJobsNames = _continuousJobRunners.Keys.Union(continuousJobs.Select(j => j.Name)); foreach (string continuousJobName in continuousJobsNames) { MarkJobUpdated(continuousJobName); } } } catch (Exception ex) { Analytics.UnexpectedException(ex); // Retry in 30 seconds. _startFileWatcherTimer.Change(CheckForWatcherTimeout, Timeout.Infinite); } }
private IEnumerable <DeployResult> EnumerateResults() { if (!FileSystemHelpers.DirectoryExists(_environment.DeploymentsPath)) { yield break; } string activeDeploymentId = _status.ActiveDeploymentId; bool isDeploying = IsDeploying; foreach (var id in FileSystemHelpers.GetDirectoryNames(_environment.DeploymentsPath).Where(p => !p.Equals(@"tools", StringComparison.OrdinalIgnoreCase))) { DeployResult result = GetResult(id, activeDeploymentId, isDeploying); if (result != null) { yield return(result); } } }
private IEnumerable <DeployResult> EnumerateResults() { if (!FileSystemHelpers.DirectoryExists(_environment.DeploymentsPath)) { yield break; } string activeDeploymentId = _status.ActiveDeploymentId; bool isDeploying = IsDeploying; foreach (var id in FileSystemHelpers.GetDirectories(_environment.DeploymentsPath)) { DeployResult result = GetResult(id, activeDeploymentId, isDeploying); if (result != null) { yield return(result); } } }
public void Delete(string id) { ITracer tracer = _traceFactory.GetTracer(); using (tracer.Step($"DeploymentManager.Delete(id:{id})")) { string path = GetRoot(id, ensureDirectory: false); if (!FileSystemHelpers.DirectoryExists(path)) { throw new DirectoryNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.Error_UnableToDeleteNoDeploymentFound, id)); } if (IsActive(id)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_UnableToDeleteDeploymentActive, id)); } _status.Delete(id); } }
public async Task RemoveStatus() { try { string dirName = Path.GetDirectoryName(_filePath); if (FileSystemHelpers.DirectoryExists(dirName)) { FileSystemHelpers.DeleteDirectoryContentsSafe(dirName); // call DeleteDirectorySafe directly would sometime causing "Access denied" on folder // work-around: remove content and wait briefly before delete folder await Task.Delay(300); FileSystemHelpers.DeleteDirectorySafe(dirName); } } catch (Exception ex) { // no-op _tracer.TraceError(ex); } }
private static void AddDiskSpaceInfo(Dictionary <string, object> telemetry) { if (Kudu.Core.Helpers.EnvironmentHelper.IsWindowsContainers()) { return; } ulong freeBytes; ulong totalBytes; var homePath = Environment.GetEnvironmentVariable("HOME"); var localPath = Environment.ExpandEnvironmentVariables("%SystemDrive%\\local"); var userProfilePath = Environment.ExpandEnvironmentVariables("%SystemDrive%\\users\\%WEBSITE_SITE_NAME%"); OperationManager.SafeExecute(() => { telemetry["homePath"] = homePath; Kudu.Core.Environment.GetDiskFreeSpace(homePath, out freeBytes, out totalBytes); telemetry["homeFreeMB"] = freeBytes / (1024 * 1024); telemetry["homeTotalMB"] = totalBytes / (1024 * 1024); }); OperationManager.SafeExecute(() => { telemetry["localPath"] = localPath; Kudu.Core.Environment.GetDiskFreeSpace(localPath, out freeBytes, out totalBytes); telemetry["localFreeMB"] = freeBytes / (1024 * 1024); telemetry["localTotalMB"] = totalBytes / (1024 * 1024); }); OperationManager.SafeExecute(() => { if (FileSystemHelpers.DirectoryExists(userProfilePath)) { telemetry["userProfilePath"] = userProfilePath; Kudu.Core.Environment.GetDiskFreeSpace(userProfilePath, out freeBytes, out totalBytes); telemetry["userProfileFreeMB"] = freeBytes / (1024 * 1024); telemetry["userProfileTotalMB"] = totalBytes / (1024 * 1024); } }); }
private void SetLocalInfo(SiteExtensionInfo info) { string localPath = GetInstallationDirectory(info.Id); if (FileSystemHelpers.DirectoryExists(localPath)) { info.LocalPath = localPath; info.InstalledDateTime = FileSystemHelpers.GetLastWriteTimeUtc(info.LocalPath); } if (ExtensionRequiresApplicationHost(info)) { info.ExtensionUrl = FileSystemHelpers.FileExists(Path.Combine(localPath, Constants.ApplicationHostXdtFileName)) ? GetFullUrl(GetUrlFromApplicationHost(info)) : null; } else { info.ExtensionUrl = String.IsNullOrEmpty(info.LocalPath) ? null : GetFullUrl(info.ExtensionUrl); } info.FeedUrl = GetSettingManager(info.Id).GetValue(_feedUrlSetting); }
private void SetLocalInfo(SiteExtensionInfo info) { string localPath = GetInstallationDirectory(info.Id); if (FileSystemHelpers.DirectoryExists(localPath)) { info.LocalPath = localPath; info.InstalledDateTime = FileSystemHelpers.GetLastWriteTimeUtc(info.LocalPath); } if (ExtensionRequiresApplicationHost(info)) { info.ExtensionUrl = GetFullUrl(GetUrlFromApplicationHost(localPath)); } else { info.ExtensionUrl = String.IsNullOrEmpty(info.LocalPath) ? null : GetFullUrl(info.ExtensionUrl); } foreach (var setting in GetSettingManager(info.Id).GetValues()) { if (String.Equals(setting.Key, _feedUrlSetting, StringComparison.OrdinalIgnoreCase)) { info.FeedUrl = setting.Value.Value <string>(); } else if (String.Equals(setting.Key, _installUtcTimestampSetting, StringComparison.OrdinalIgnoreCase)) { DateTime installedDateTime; if (DateTime.TryParse(setting.Value.Value <string>(), out installedDateTime)) { info.InstalledDateTime = installedDateTime.ToUniversalTime(); } } else if (String.Equals(setting.Key, _installationArgs, StringComparison.OrdinalIgnoreCase)) { info.InstallationArgs = setting.Value.Value <string>(); } } }
private void SetLocalInfo(SiteExtensionInfo info) { string localPath = GetInstallationDirectory(info.Id); if (FileSystemHelpers.DirectoryExists(localPath)) { info.LocalPath = localPath; info.InstalledDateTime = FileSystemHelpers.GetLastWriteTimeUtc(info.LocalPath); } if (ExtensionRequiresApplicationHost(info)) { if (FileSystemHelpers.FileExists(Path.Combine(localPath, _applicationHostFile))) { info.ExtensionUrl = GetUrlFromApplicationHost(info); } else { info.ExtensionUrl = null; } if (info.Type == SiteExtensionInfo.SiteExtensionType.PreInstalledNonKudu) { info.Version = GetLatestPreInstalledExtensionVersion(info.Id); } } else { if (!String.IsNullOrEmpty(info.LocalPath)) { info.ExtensionUrl = _baseUrl + info.ExtensionUrl + "/"; } else { info.ExtensionUrl = null; } } }
public static async Task EnsureVirtualEnvrionmentIgnored() { if (InVirtualEnvironment) { try { var virtualEnvName = Path.GetFileNameWithoutExtension(VirtualEnvironmentPath); if (FileSystemHelpers.DirectoryExists(Path.Join(Environment.CurrentDirectory, virtualEnvName))) { var funcIgnorePath = Path.Join(Environment.CurrentDirectory, Constants.FuncIgnoreFile); // If .funcignore exists and already has the venv name, we are done here if (FileSystemHelpers.FileExists(funcIgnorePath)) { var rawfuncIgnoreContents = await FileSystemHelpers.ReadAllTextFromFileAsync(funcIgnorePath); if (rawfuncIgnoreContents.Contains(Environment.NewLine + virtualEnvName)) { return; } } // Write the current env to .funcignore ColoredConsole.WriteLine($"Writing {Constants.FuncIgnoreFile}"); using (var fileStream = FileSystemHelpers.OpenFile(funcIgnorePath, FileMode.Append, FileAccess.Write)) using (var streamWriter = new StreamWriter(fileStream)) { await streamWriter.WriteAsync(Environment.NewLine + virtualEnvName); await streamWriter.FlushAsync(); } } } catch (Exception) { // Safe execution, we aren't harmed by failures here } } }