/// <summary> /// Whether the driver support the specified uri. /// </summary> /// <param name="io">The input/output instance.</param> /// <param name="config">The config instance.</param> /// <param name="uri">Thr specified uri.</param> /// <param name="deep">Whether is deep checker.</param> /// <returns>True if the driver is supported.</returns> public static bool IsSupport(IIO io, Config config, string uri, bool deep = false) { if (Regex.IsMatch(uri, @"(^git://|\.git/?$|git(?:olite)?@|//git\.|//github\.com/|//gitlib\.com/)", RegexOptions.IgnoreCase)) { return(true); } bool ProcessCheck(string command, string cwd) { var process = new BucketProcessExecutor(io); return(process.Execute(command, cwd) == 0); } if (FileSystemLocal.IsLocalPath(uri)) { uri = FileSystemLocal.GetPlatformPath(uri); if (!Directory.Exists(uri)) { return(false); } return(ProcessCheck("git tag", uri)); } if (!deep) { return(false); } return(ProcessCheck($"git ls-remote --heads {ProcessExecutor.Escape(uri)}", null)); }
/// <inheritdoc /> public override void Initialize() { string cacheUri; if (FileSystemLocal.IsLocalPath(Uri)) { Uri = Regex.Replace(Uri, @"[\\/]\.git/?$", string.Empty); repositoryDirectory = Uri; cacheUri = Path.GetFullPath(Uri); } else { var cacheVcsDir = Config.Get(Settings.CacheVcsDir); if (!CacheFileSystem.IsUsable(cacheVcsDir)) { throw new RuntimeException("DriverGit requires a usable cache directory, and it looks like you set it to be disabled."); } if (Regex.IsMatch("^ssh://[^@]+@[^:]+:[^0-9]+", Uri)) { throw new InvalidArgumentException($"The source URL {Uri} is invalid, ssh URLs should have a port number after \":\".{Environment.NewLine}Use ssh://[email protected]:22/path or just [email protected]:path if you do not want to provide a password or custom port."); } Git.CleanEnvironment(); var fileSystem = new FileSystemLocal($"{cacheVcsDir}/{CacheFileSystem.FormatCacheFolder(Uri)}/"); var git = new Git(IO, Config, Process, fileSystem); repositoryDirectory = fileSystem.Root; if (!git.SyncMirror(Uri, repositoryDirectory)) { IO.WriteError($"<error>Failed to update {Uri}, package information from this repository may be outdated</error>"); } cacheUri = Uri; } GetTags(); GetBranches(); cache = new CacheFileSystem($"{Config.Get(Settings.CacheRepoDir)}/{CacheFileSystem.FormatCacheFolder(cacheUri)}", IO); }
private void ProcessAction(string[] sourceUris, Action <string> closure) { var uris = new Queue <string>(sourceUris); Guard.Requires <UnexpectedException>(uris.Count > 0, "The number of valid download addresses must be greater than 0."); while (uris.Count > 0) { var uri = uris.Dequeue(); try { if (FileSystemLocal.IsLocalPath(uri)) { uri = ProcessLocalSourceUri(uri); } closure(uri); break; } catch (SException ex) { if (IO.IsDebug) { IO.WriteError($"Failed: [{ex.GetType()}] {ex.Message}"); } else if (uris.Count > 0) { IO.WriteError(" Failed, trying the next URI"); } if (uris.Count <= 0) { throw; } } } }
public void TestIsLocalPath(bool expected, string path) { Assert.AreEqual(expected, FileSystemLocal.IsLocalPath(path)); }