public Repository Init(IAbsoluteDirectoryPath folder, IReadOnlyCollection<Uri> hosts, Action<SyncOptions> cfg = null) { Contract.Requires<ArgumentNullException>(folder != null); Contract.Requires<ArgumentNullException>(hosts != null); var opts = new SyncOptions(); cfg?.Invoke(opts); return Init(folder, hosts, opts); }
internal Repository Init(IAbsoluteDirectoryPath folder, IReadOnlyCollection<Uri> hosts, SyncOptions opts) { var rsyncFolder = folder.GetChildDirectoryWithName(Repository.RepoFolderName); if (rsyncFolder.Exists) throw new Exception("Already appears to be a repository"); var packFolder = GetPackFolder(opts, rsyncFolder); var configFile = rsyncFolder.GetChildFileWithName(Repository.ConfigFileName); var wdVersionFile = rsyncFolder.GetChildFileWithName(Repository.VersionFileName); var packVersionFile = packFolder.GetChildFileWithName(Repository.VersionFileName); this.Logger().Info("Initializing {0}", folder); rsyncFolder.MakeSurePathExists(); packFolder.MakeSurePathExists(); var config = new RepoConfig { Hosts = hosts.ToList() }; config.PackPath = opts.PackPath?.ToString(); if (opts.Include != null) config.Include = opts.Include; if (opts.Exclude != null) config.Include = opts.Exclude; var guid = opts.RequiredGuid ?? Guid.NewGuid().ToString(); var packVersion = new RepoVersion { Guid = guid }; if (opts.ArchiveFormat != null) packVersion.ArchiveFormat = (string)opts.ArchiveFormat; var wdVersion = SyncEvilGlobal.Yaml.NewFromYaml<RepoVersion>(packVersion.ToYaml()); SyncEvilGlobal.Yaml.ToYamlFile(config, configFile); SyncEvilGlobal.Yaml.ToYamlFile(packVersion, packVersionFile); SyncEvilGlobal.Yaml.ToYamlFile(wdVersion, wdVersionFile); return TryGetRepository(folder, opts, rsyncFolder); }
Repository TryGetRepository(IAbsoluteDirectoryPath folder, SyncOptions opts, IAbsoluteDirectoryPath rsyncFolder) { try { var repo = GetRepository(folder, opts); if (opts.MaxThreads.HasValue) repo.MultiThreadingSettings.MaxThreads = opts.MaxThreads.Value; if (opts.RequiredVersion.HasValue) repo.RequiredVersion = opts.RequiredVersion; if (opts.RequiredGuid != null) repo.RequiredGuid = opts.RequiredGuid; if (opts.Output != null) repo.Output = opts.Output; repo.LoadHosts(); return repo; } catch (Exception) { Tools.FileUtil.Ops.DeleteWithRetry(rsyncFolder.ToString()); throw; } }
private async Task InstallNew(GroupContent mod, IAuthProvider provider, Action<SyncOptions> config, IAbsoluteDirectoryPath folder) { SetupHosts(mod, provider); var opts = new SyncOptions(); config(opts); await Repository.Factory.Clone(opts.Hosts, folder.ToString(), config) .ConfigureAwait(false); }
public virtual Task Update(Action<SyncOptions> config = null) { var opts = new SyncOptions(); config?.Invoke(opts); return Update(opts); }
internal async Task Update(SyncOptions opts) { HandleOpts(opts); StatusRepo.Action = RepoStatus.Verifying; var localOnly = opts.LocalOnly; if (!localOnly) { this.Logger().Info("Required Version: {0}, Required GUID: {1}", RequiredVersion, RequiredGuid); await UpdateRepository().ConfigureAwait(false); } this.Logger().Info( $"Repository version: {WdVersion.Version}, GUID: {WdVersion.Guid}{(!string.IsNullOrWhiteSpace(Config.PackPath) ? "Pack Path: " + Config.PackPath : string.Empty)}"); LoadSums(true, localOnly); StatusRepo.ResetWithoutClearItems(RepoStatus.Updating, StatusRepo.Total); var differences = CompareSums(RepositoryFileType.Wd, 1); var removed = differences[0]; var changed = differences[1]; var changesOnly = !_keepCompressedFiles; var changeLock = !localOnly && (changed.Any() || removed.Any()) && await ProcessPackChanges(changed.Concat(removed), changesOnly).ConfigureAwait(false); if (await ProcessWdChanges(differences, changesOnly).ConfigureAwait(false)) changeLock = true; TryCleanupTmpFiles(); if (changeLock) { this.Logger().Info("Changes detected. Verifying checksums..."); TryConfirmChecksumValidity(localOnly || changesOnly); } WdVersion.Guid = PackVersion.Guid; if (changeLock || (WdVersion.Version != PackVersion.Version)) { UpdateRepoInfo(); this.Logger().Info("New repository version: {0}, Pack Size: {1}, WD Size: {2}", WdVersion.Version, WdVersion.PackSize * 1024, WdVersion.WdSize * 1024); } SyncEvilGlobal.Yaml.ToYamlFile(WdVersion, WdVersionFile); StatusRepo.Finish(); }
bool HandleOpts(SyncOptions opts, bool save = true) { Contract.Requires<ArgumentNullException>(opts != null); var changed = false; if (opts.Include != null) { Config.Include = opts.Include; changed = true; } if (opts.Exclude != null) { Config.Exclude = opts.Exclude; changed = true; } AllowFullTransferFallBack = opts.AllowFullTransferFallBack; if (opts.Hosts != null) { Config.Hosts = opts.Hosts; changed = true; } if (opts.MaxThreads.HasValue) MultiThreadingSettings.MaxThreads = opts.MaxThreads.Value; _keepCompressedFiles = opts.KeepCompressedFiles; if (opts.Status != null) StatusRepo = opts.Status; if (opts.RequiredVersion.HasValue) RequiredVersion = opts.RequiredVersion; if (opts.RequiredGuid != null) RequiredGuid = opts.RequiredGuid; if (save && changed) SaveAndReloadConfig(); else LoadHosts(); return changed; }
private static IAbsoluteDirectoryPath GetPackFolder(SyncOptions opts, IAbsoluteDirectoryPath rsyncFolder) => opts.PackPath ?? rsyncFolder.GetChildDirectoryWithName(Repository.PackFolderName);
public Repository Open(IAbsoluteDirectoryPath folder, Action<SyncOptions> config = null) { Contract.Requires<ArgumentNullException>(folder != null); var opts = new SyncOptions(); config?.Invoke(opts); var repo = GetRepository(folder, opts); if (opts.Output != null) repo.Output = opts.Output; return repo; }
public Repository Convert(IAbsoluteDirectoryPath folder, Action<SyncOptions> config = null) { Contract.Requires<ArgumentNullException>(folder != null); var opts = new SyncOptions(); config?.Invoke(opts); var hosts = opts.Hosts; var repo = Init(folder, hosts, opts); repo.Commit(false, false); return repo; }
public async Task<Repository> Clone(IReadOnlyCollection<Uri> hosts, string folder, Action<SyncOptions> config = null) { Contract.Requires<ArgumentNullException>(folder != null); Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(folder)); Contract.Requires<ArgumentNullException>(hosts != null); var opts = new SyncOptions(); config?.Invoke(opts); if (opts.Path != null) folder = opts.Path.GetChildDirectoryWithName(folder).ToString(); var repo = Init(folder.ToAbsoluteDirectoryPath(), hosts, opts); await repo.Update(opts).ConfigureAwait(false); return repo; }
Repository GetRepository(IAbsoluteDirectoryPath folder, SyncOptions opts) => opts.Status != null ? new Repository(_zsyncMake, opts.Status, folder.ToString()) : new Repository(_zsyncMake, folder.ToString());
internal Repository Init(IAbsoluteDirectoryPath folder, IReadOnlyCollection <Uri> hosts, SyncOptions opts) { var rsyncFolder = folder.GetChildDirectoryWithName(Repository.RepoFolderName); if (rsyncFolder.Exists) { throw new Exception("Already appears to be a repository"); } var packFolder = GetPackFolder(opts, rsyncFolder); var configFile = rsyncFolder.GetChildFileWithName(Repository.ConfigFileName); var wdVersionFile = rsyncFolder.GetChildFileWithName(Repository.VersionFileName); var packVersionFile = packFolder.GetChildFileWithName(Repository.VersionFileName); this.Logger().Info("Initializing {0}", folder); rsyncFolder.MakeSurePathExists(); packFolder.MakeSurePathExists(); var config = new RepoConfig { Hosts = hosts.ToList() }; config.PackPath = opts.PackPath?.ToString(); if (opts.Include != null) { config.Include = opts.Include; } if (opts.Exclude != null) { config.Include = opts.Exclude; } var guid = opts.RequiredGuid ?? Guid.NewGuid().ToString(); var packVersion = new RepoVersion { Guid = guid }; if (opts.ArchiveFormat != null) { packVersion.ArchiveFormat = (string)opts.ArchiveFormat; } var wdVersion = SyncEvilGlobal.Yaml.NewFromYaml <RepoVersion>(packVersion.ToYaml()); SyncEvilGlobal.Yaml.ToYamlFile(config, configFile); SyncEvilGlobal.Yaml.ToYamlFile(packVersion, packVersionFile); SyncEvilGlobal.Yaml.ToYamlFile(wdVersion, wdVersionFile); return(TryGetRepository(folder, opts, rsyncFolder)); }