internal static async Task <TraceLevel> GetTraceLevel(string scriptPath) { var filePath = Path.Combine(scriptPath, ScriptConstants.HostMetadataFileName); if (!FileSystemHelpers.FileExists(filePath)) { return(DefaultTraceLevel); } var hostJson = JsonConvert.DeserializeObject <JObject>(await FileSystemHelpers.ReadAllTextFromFileAsync(filePath)); var traceLevelStr = hostJson["tracing"]?["consoleLevel"]?.ToString(); if (!string.IsNullOrEmpty(traceLevelStr) && Enum.TryParse(traceLevelStr, true, out TraceLevel traceLevel)) { return(traceLevel); } else { return(DefaultTraceLevel); } }
private async Task <string> GetFunctionTestData(string functionName, FunctionTestData packageLimit) { string testDataFilePath = GetFunctionTestDataFilePath(functionName); // Create an empty file if it doesn't exist if (!FileSystemHelpers.FileExists(testDataFilePath)) { FileSystemHelpers.WriteAllText(testDataFilePath, String.Empty); } if (packageLimit != null) { var fileSize = FileSystemHelpers.FileInfoFromFileName(testDataFilePath).Length; if (!packageLimit.DeductFromBytesLeftInPackage(fileSize)) { return($"Test_Data is of size {fileSize} bytes, but there's only {packageLimit.BytesLeftInPackage} bytes left in ARM response"); } } return(await FileSystemHelpers.ReadAllTextFromFileAsync(testDataFilePath)); }
public static TJobStatus ReadJobStatusFromFile <TJobStatus>(ITraceFactory traceFactory, string statusFilePath) where TJobStatus : class, IJobStatus { try { if (!FileSystemHelpers.FileExists(statusFilePath)) { return(null); } return(OperationManager.Attempt(() => { string content = FileSystemHelpers.ReadAllTextFromFile(statusFilePath).Trim(); return JsonConvert.DeserializeObject <TJobStatus>(content, JsonSerializerSettings); })); } catch (Exception ex) { Analytics.UnexpectedException(ex, traceFactory); return(null); } }
protected void InitializeJobInstance(JobBase job, IJobLogger logger) { if (!String.Equals(JobName, job.Name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException( "The job runner can only run jobs with the same name it was configured, configured - {0}, trying to run - {1}".FormatInvariant( JobName, job.Name)); } if (!FileSystemHelpers.FileExists(job.ScriptFilePath)) { throw new InvalidOperationException("Missing job script to run - {0}".FormatInvariant(job.ScriptFilePath)); } CacheJobBinaries(logger); if (WorkingDirectory == null) { throw new InvalidOperationException("Missing working directory"); } }
public void SetPrivateKey(string key) { ITracer tracer = _traceFactory.GetTracer(); using (tracer.Step("SSHKeyManager.SetPrivateKey")) { FileSystemHelpers.EnsureDirectory(_fileSystem, _sshPath); // Delete existing public key if (_fileSystem.File.Exists(_id_rsaPub)) { _fileSystem.File.Delete(_id_rsaPub); } // bypass service key checking prompt (StrictHostKeyChecking=no). _fileSystem.File.WriteAllText(_config, ConfigContent); // This overrides if file exists _fileSystem.File.WriteAllText(_id_rsa, key); } }
public void CheckTemplateRootRelativeToInstallPath(string pathToTemplateJson, bool shouldAllPathsBeValid) { string sourcePath = FileSystemHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(pathToTemplateJson, BasicTemplateConfig); TestTemplateSetup setup = new TestTemplateSetup(EngineEnvironmentSettings, sourcePath, templateSourceFiles); setup.WriteSource(); RunnableProjectGenerator generator = new RunnableProjectGenerator(); IFile templateFile = setup.FileInfoForSourceFile(pathToTemplateJson); JObject srcObject = generator.ReadJObjectFromIFile(templateFile); SimpleConfigModel templateModel = SimpleConfigModel.FromJObject(templateFile.MountPoint.EnvironmentSettings, srcObject); RunnableProjectTemplate runnableProjectTemplate = new RunnableProjectTemplate(srcObject, generator, templateFile, templateModel, null, null); bool allPathsAreValid = generator.AreAllTemplatePathsValid(templateModel, runnableProjectTemplate); Assert.Equal(shouldAllPathsBeValid, allPathsAreValid); }
public void CheckAlwaysOn_OnlyLogsOncePerLogFile() { System.Environment.SetEnvironmentVariable(ContinuousJobRunner.WebsiteSCMAlwaysOnEnabledKey, "0"); _runner.CheckAlwaysOn(); _runner.CheckAlwaysOn(); _runner.CheckAlwaysOn(); VerifyAlwaysOnWarningWritten(); // when the log file is rolled, we expect the new log file to // contain the warning FileSystemHelpers.DeleteFileSafe(_logFilePath); _runner.OnLogFileRolled(); _runner.CheckAlwaysOn(); _runner.CheckAlwaysOn(); VerifyAlwaysOnWarningWritten(); System.Environment.SetEnvironmentVariable(ContinuousJobRunner.WebsiteSCMAlwaysOnEnabledKey, null); }
private string GetActiveDeploymentManifestPath() { string id = _status.ActiveDeploymentId; // We've seen rare cases of corruption where the file is full of NUL characters. // If we see the first char is 0, treat the file as corrupted and ignore it if (String.IsNullOrEmpty(id) || id[0] == 0) { return(null); } string manifestPath = GetDeploymentManifestPath(id); // If the manifest file doesn't exist, don't return it as it could confuse kudusync. // This can happen if the deployment was created with just metadata but no actualy deployment took place. if (!FileSystemHelpers.FileExists(manifestPath)) { return(null); } return(manifestPath); }
public void Delete(string id) { ITracer tracer = _traceFactory.GetTracer(); using (tracer.Step("DeploymentManager.Delete(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 async Task <ProfileResultInfo> StopProfileInternalAsync(int processId, int profilingSessionId, bool ignoreProfileFile, ITracer tracer = null, bool iisProfiling = false) { tracer = tracer ?? NullTracer.Instance; using (tracer.Step("ProfileManager.StopProfileInternalAsync")) { string profileFileFullPath = GetProfilePath(processId, iisProfiling); string profileFileName = Path.GetFileName(profileFileFullPath); string arguments = string.Format("stop {0} /output:{1}", profilingSessionId, profileFileFullPath); var profileProcessResponse = await ExecuteProfilingCommandAsync(arguments, tracer); ProfileInfo removedId; if (profileProcessResponse.StatusCode != HttpStatusCode.OK) { _profilingList.TryRemove(processId, out removedId); return(profileProcessResponse); } FileSystemHelpers.EnsureDirectory(Path.GetDirectoryName(profileFileFullPath)); tracer.Step("profile was saved to {0} successfully.", profileFileFullPath); _profilingList.TryRemove(processId, out removedId); if (ignoreProfileFile) { try { FileSystemHelpers.DeleteFile(profileFileFullPath); } catch { } } DisposeTimerIfNecessary(); return(new ProfileResultInfo(HttpStatusCode.OK, string.Empty)); } }
public void SourceConfigExcludesAreOverriddenByIncludes() { string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Sources = new List <ExtendedFileSource>() { new ExtendedFileSource() { Exclude = "**/*.config", Modifiers = new List <SourceModifier>() { new SourceModifier() { Include = "core.config" } } } } }; IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); // config templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); // content templateSourceFiles.Add("core.config", null); templateSourceFiles.Add("full.config", null); TestTemplateSetup setup = new TestTemplateSetup(_engineEnvironmentSettings, sourceBasePath, templateSourceFiles, config); setup.WriteSource(); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); setup.InstantiateTemplate(targetDir); Assert.True(_engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(targetDir, "core.config"))); Assert.False(_engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(targetDir, "full.config"))); }
/// <summary> /// Helper function to download package from given url, and place package (only 'content' folder from package) to given folder /// </summary> /// <param name="identity">Package identity</param> /// <param name="destinationFolder">Folder where we copy the package content (content folder only) to</param> /// <param name="pathToLocalCopyOfNupkg">File path where we copy the nudpk to</param> /// <returns></returns> public static async Task DownloadPackageToFolder(this SourceRepository srcRepo, PackageIdentity identity, string destinationFolder, string pathToLocalCopyOfNupkg) { var downloadResource = await srcRepo.GetResourceAndValidateAsync <DownloadResource>(); using (Stream packageStream = await srcRepo.GetPackageStream(identity)) { using (ZipFile zipFile = ZipFile.Read(packageStream)) { // we only care about stuff under "content" folder int substringStartIndex = @"content/".Length; IEnumerable <ZipEntry> contentEntries = zipFile.Entries.Where(e => e.FileName.StartsWith(@"content/", StringComparison.InvariantCultureIgnoreCase)); foreach (var entry in contentEntries) { string fullPath = Path.Combine(destinationFolder, entry.FileName.Substring(substringStartIndex)); if (entry.IsDirectory) { FileSystemHelpers.EnsureDirectory(fullPath.Replace('/', '\\')); continue; } FileSystemHelpers.EnsureDirectory(Path.GetDirectoryName(fullPath)); using (Stream writeStream = FileSystemHelpers.OpenWrite(fullPath)) { // reset length of file stream writeStream.SetLength(0); // let the thread go with itself, so that once file finishes writing, doesn't need to request thread context from main thread await entry.OpenReader().CopyToAsync(writeStream).ConfigureAwait(false); } } } // set position back to the head of stream packageStream.Position = 0; // save a copy of the nupkg at last WriteStreamToFile(packageStream, pathToLocalCopyOfNupkg); } }
public static async Task <Stream> GetAppZipFile(string functionAppRoot, bool buildNativeDeps, BuildOption buildOption, bool noBuild, GitIgnoreParser ignoreParser = null, string additionalPackages = null, bool ignoreDotNetCheck = false) { var gitIgnorePath = Path.Combine(functionAppRoot, Constants.FuncIgnoreFile); if (ignoreParser == null && FileSystemHelpers.FileExists(gitIgnorePath)) { ignoreParser = new GitIgnoreParser(await FileSystemHelpers.ReadAllTextFromFileAsync(gitIgnorePath)); } if (noBuild) { ColoredConsole.WriteLine(DarkYellow("Skipping build event for functions project (--no-build).")); } else if (buildOption == BuildOption.Remote) { ColoredConsole.WriteLine(DarkYellow("Performing remote build for functions project.")); } else if (buildOption == BuildOption.Local) { ColoredConsole.WriteLine(DarkYellow("Performing local build for functions project.")); } if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.python && !noBuild) { return(await PythonHelpers.GetPythonDeploymentPackage(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser), functionAppRoot, buildNativeDeps, buildOption, additionalPackages)); } else if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnet && !ignoreDotNetCheck && !noBuild && buildOption != BuildOption.Remote) { throw new CliException("Pack command doesn't work for dotnet functions"); } else if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnet && buildOption == BuildOption.Remote) { // Remote build for dotnet does not require bin and obj folders. They will be generated during the oryx build return(await CreateZip(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser, false, new string[] { "bin", "obj" }), functionAppRoot)); } else { return(await CreateZip(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser, false), functionAppRoot)); } }
private static async Task <string> RestorePythonRequirements(string functionAppRoot) { var packagesLocation = Path.Combine(functionAppRoot, Constants.ExternalPythonPackages); FileSystemHelpers.EnsureDirectory(packagesLocation); var requirementsTxt = Path.Combine(functionAppRoot, Constants.RequirementsTxt); await InstallDislib(); var packApp = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools", "python", "packapp.py"); var exe = new Executable("python", $"{packApp} --platform linux --python-version 36 --packages-dir-name {Constants.ExternalPythonPackages} {functionAppRoot}"); var sbErrors = new StringBuilder(); var exitCode = await exe.RunAsync(o => ColoredConsole.WriteLine(o), e => sbErrors.AppendLine(e)); if (exitCode != 0) { throw new CliException("There was an error restoring dependencies." + sbErrors.ToString()); } return(packagesLocation); }
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>(); } } }
public static FileStream Create(string aFile) { if (aFile == null) { throw new ArgumentNullException("aFile"); } if (aFile.Length == 0) { throw new ArgumentException("File path must not be empty.", "aFile"); } FileSystemHelpers.Debug("File.Create", "aFile =", aFile); var xEntry = VFSManager.CreateFile(aFile); if (xEntry == null) { return(null); } return(new FileStream(aFile, FileMode.Open)); }
/// <summary> /// Gets an existing created public key or creates a new one and returns the public key /// </summary> public string GetPublicKey(bool ensurePublicKey) { ITracer tracer = _traceFactory.GetTracer(); using (tracer.Step("SSHKeyManager.GetKey")) { if (FileSystemHelpers.FileExists(_id_rsaPub)) { tracer.Trace("Public key exists."); // If a public key exists, return it. return(FileSystemHelpers.ReadAllText(_id_rsaPub)); } else if (ensurePublicKey) { tracer.Trace("Creating key pair."); return(CreateKeyPair()); } // A public key does not exist but we weren't asked to create it. return(null); } }
public static async Task <string> EnsureExtensionsProjectExistsAsync() { var extensionsProj = Path.Combine(Environment.CurrentDirectory, "extensions.csproj"); if (!FileSystemHelpers.FileExists(extensionsProj)) { var assembly = typeof(ExtensionsHelper).Assembly; var extensionsProjText = string.Empty; using (Stream resource = assembly.GetManifestResourceStream(assembly.GetName().Name + ".ExtensionsProj.txt")) using (var reader = new StreamReader(resource)) { while (!reader.EndOfStream) { var line = await reader.ReadLineAsync(); extensionsProjText += $"{line}{Environment.NewLine}"; } } await FileSystemHelpers.WriteAllTextToFileAsync(extensionsProj, extensionsProjText); } return(extensionsProj); }
internal void SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata aEntryMetadata, string aValue) { var xData = mParent.GetDirectoryEntryData(); if (xData.Length > 0) { var xValue = new byte[aEntryMetadata.DataLength]; xValue = aValue.GetUtf8Bytes(0, aEntryMetadata.DataLength); uint offset = mEntryHeaderDataOffset + aEntryMetadata.DataOffset; Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength); FileSystemHelpers.Debug("SetDirectoryEntryMetadataValue: DataLength =", aEntryMetadata.DataLength); FileSystemHelpers.Debug("SetDirectoryEntryMetadataValue: DataOffset =", aEntryMetadata.DataOffset); FileSystemHelpers.Debug("SetDirectoryEntryMetadataValue: EntryHeaderDataOffset =", mEntryHeaderDataOffset); FileSystemHelpers.Debug("SetDirectoryEntryMetadataValue: TotalOffset =", offset); FileSystemHelpers.Debug("SetDirectoryEntryMetadataValue: aValue =", aValue); mParent.SetDirectoryEntryData(xData); } }
public static DirectoryInfo CreateDirectory(string aPath) { if (aPath == null) { throw new ArgumentNullException("aPath"); } if (aPath.Length == 0) { throw new ArgumentException("Path must not be empty.", "aPath"); } FileSystemHelpers.Debug("Directory.CreateDirectory", "aPath =", aPath); var xEntry = VFSManager.CreateDirectory(aPath); if (xEntry == null) { return(null); } return(new DirectoryInfo(aPath)); }
public static TJobStatus ReadJobStatusFromFile <TJobStatus>(IAnalytics analytics, string statusFilePath) where TJobStatus : class, IJobStatus { try { if (!FileSystemHelpers.FileExists(statusFilePath)) { return(null); } // since we don't have proper lock on file, we are more forgiving in retry (10 times 250 ms interval). return(OperationManager.Attempt(() => { string content = FileSystemHelpers.ReadAllTextFromFile(statusFilePath).Trim(); return JsonConvert.DeserializeObject <TJobStatus>(content, JsonSerializerSettings); }, retries: 10)); } catch (Exception ex) { analytics.UnexpectedException(ex); return(null); } }
public static async Task <Stream> GetAppZipFile(WorkerRuntime workerRuntime, string functionAppRoot, bool buildNativeDeps, GitIgnoreParser ignoreParser = null) { var gitIgnorePath = Path.Combine(functionAppRoot, Constants.FuncIgnoreFile); if (ignoreParser == null && FileSystemHelpers.FileExists(gitIgnorePath)) { ignoreParser = new GitIgnoreParser(await FileSystemHelpers.ReadAllTextFromFileAsync(gitIgnorePath)); } if (workerRuntime == WorkerRuntime.python) { return(await PythonHelpers.GetPythonDeploymentPackage(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser), functionAppRoot, buildNativeDeps)); } else if (workerRuntime == WorkerRuntime.dotnet) { throw new CliException("Pack command doesn't work for dotnet functions"); } else { return(CreateZip(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser), functionAppRoot)); } }
public string Solve(string url) { var captchaFile = FileSystemHelpers.GetFile("captcha.jpg"); new WebClient().DownloadFile(new Uri(url), captchaFile.FullName); captchaFile.OpenFile(); var solved = io.RequestInput("Please, solve captcha and enter result here"); if (captchaFile.Exists) { try { captchaFile.Delete(); } catch (IOException) { io.Print("File is opened somewhere else and will be not deleted. " + $"You can delete it manually, path is: {captchaFile.FullName}"); } } return(solved); }
public static string GetValue(string key, string defaultValue = null) { var configs = _configs; if (configs == null || DateTime.UtcNow > _configsTTL) { _configsTTL = DateTime.UtcNow.AddMinutes(10); try { var settings = FileSystemHelpers.FileExists(_configsFile) ? FileSystemHelpers.ReadAllText(_configsFile) : null; KuduEventSource.Log.GenericEvent( ServerConfiguration.GetApplicationName(), $"ScmHostingConfigurations: Update value '{settings}'", string.Empty, string.Empty, string.Empty, string.Empty); configs = Parse(settings); _configs = configs; } catch (Exception ex) { KuduEventSource.Log.KuduException( ServerConfiguration.GetApplicationName(), "ScmHostingConfigurations.GetValue", string.Empty, string.Empty, $"ScmHostingConfigurations: Fail to GetValue('{key}')", ex.ToString()); } } return((configs == null || !configs.TryGetValue(key, out string value)) ? defaultValue : value); }
private IEnumerable <string> GetCurrentDockerLogFilenames() { // Get all non-rolled Docker log filenames from the LogFiles directory var nonRolledDockerLogFilenames = FileSystemHelpers.ListFiles(_environment.LogFilesPath, SearchOption.TopDirectoryOnly, new[] { "*" }) .Where(f => NONROLLED_DOCKER_LOG_FILENAME_REGEX.IsMatch(Path.GetFileName(f))) .ToArray(); if (!nonRolledDockerLogFilenames.Any()) { return(Enumerable.Empty <string>()); } // Find the latest date stamp and filter out those that don't have it // Timestamps are YYYY_MM_DD (sortable as integers with the underscores removed) var latestDatestamp = nonRolledDockerLogFilenames .Select(p => Path.GetFileName(p).Substring(0, 10)) .OrderByDescending(s => int.Parse(s.Replace("_", String.Empty))) .First(); return(nonRolledDockerLogFilenames.Where(f => Path.GetFileName(f).StartsWith(latestDatestamp, StringComparison.OrdinalIgnoreCase))); }
protected override string DetermineSecurityProtocol(JObject payload) { JObject repository = payload.Value <JObject>("repository"); string repositoryUrl = repository.Value <string>("url"); bool isPrivate = repository.Value <bool>("private"); if (isPrivate) { repositoryUrl = repository.Value <string>("ssh_url"); } else if (!String.Equals(new Uri(repositoryUrl).Host, "github.com", StringComparison.OrdinalIgnoreCase)) { if (_environment != null && FileSystemHelpers.FileExists(Path.Combine(_environment.SSHKeyPath, PrivateKeyFile))) { // if we determine that a github request does not come from "github.com" // and it is not a private repository, but we still find a ssh key, we assume // the request is from a private GHE repositoryUrl = repository.Value <string>("ssh_url"); } } return(repositoryUrl); }
public static void Ctor( DirectoryInfo aThis, string aPath, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage, [FieldAccess(Name = "$$FullPath$$")] ref string aFullPath, [FieldAccess(Name = "$$Name$$")] ref string aName) { FileSystemHelpers.Debug("DirectoryInfo.ctor", "aPath =", aPath); if (aPath == null) { throw new ArgumentNullException("aPath is null in DirectoryInfo ctor"); } if (!VFSManager.DirectoryExists(aPath)) { throw new DirectoryNotFoundException("Unable to find directory " + aPath); } aStorage = VFSManager.GetDirectory(aPath); aFullPath = VFSManager.GetFullPath(aStorage); aName = Path.GetDirectoryName(aFullPath); }
public IEnumerable <string> ListFiles(string path, SearchOption searchOption, params string[] lookupList) { path = PathUtility.CleanPath(path); if (!FileSystemHelpers.IsSubfolder(RepositoryPath, path)) { throw new NotSupportedException("Only paths relative to the repository root path are supported, path provided: '{0}' is not a child folder of '{1}'".FormatCurrentCulture(path, RepositoryPath)); } if (!Directory.Exists(path)) { return(Enumerable.Empty <string>()); } using (var repo = new LibGit2Sharp.Repository(RepositoryPath)) { var files = repo.Diff.Compare <TreeChanges>(null, DiffTargets.Index, lookupList, compareOptions: new CompareOptions() { IncludeUnmodified = true, Similarity = SimilarityOptions.None }) .Select(d => Path.Combine(repo.Info.WorkingDirectory, d.Path)) .Where(p => p.StartsWith(path, StringComparison.OrdinalIgnoreCase)); switch (searchOption) { case SearchOption.TopDirectoryOnly: files = files.Where(line => !line.Substring(path.Length).TrimStart('\\').Contains('\\')); break; case SearchOption.AllDirectories: break; default: throw new NotSupportedException("Search option {0} is not supported".FormatCurrentCulture(searchOption)); } // Make sure to materialize the list before finalizing repo return(files.ToList()); } }
public static void CopyWithManifest(string sourcePath, string destinationPath, IDeploymentManifestReader previousManifest, bool skipOldFiles = true) { using (var progressWriter = new ProgressWriter()) { progressWriter.Start(); if (previousManifest != null) { var previousFiles = new HashSet <string>(previousManifest.GetPaths(), StringComparer.OrdinalIgnoreCase); SmartCopy(sourcePath, destinationPath, previousFiles.Contains, new DirectoryInfoWrapper(new DirectoryInfo(sourcePath)), new DirectoryInfoWrapper(new DirectoryInfo(destinationPath)), path => new DirectoryInfoWrapper(new DirectoryInfo(path))); } else { // On first deployment, delete the contents of the destination path before copying FileSystemHelpers.DeleteDirectoryContentsSafe(destinationPath); // If there's no manifest then there's nothing to copy FileSystemHelpers.Copy(sourcePath, destinationPath); } } }