diff --git a/src/Console/Program.cs b/src/Console/Program.cs index 197c3ec8..a13315a4 100644 --- a/src/Console/Program.cs +++ b/src/Console/Program.cs @@ -530,8 +530,15 @@ namespace Bit.Console } else { + var force = false; + if(_usingArgs) + { + var parameters = ParseParameters(); + force = parameters.ContainsKey("f"); + } + Con.WriteLine("Syncing..."); - var result = await Sync.SyncAllAsync(); + var result = await Sync.SyncAllAsync(force); if(result.Success) { diff --git a/src/Core/Utilities/Sync.cs b/src/Core/Utilities/Sync.cs index 403de437..ce9b37b7 100644 --- a/src/Core/Utilities/Sync.cs +++ b/src/Core/Utilities/Sync.cs @@ -11,7 +11,7 @@ namespace Bit.Core.Utilities { public static class Sync { - public static async Task SyncAllAsync() + public static async Task SyncAllAsync(bool force = false) { if(!AuthService.Instance.Authenticated || !AuthService.Instance.OrganizationSet) { @@ -45,13 +45,13 @@ namespace Bit.Core.Utilities List groups = null; if(SettingsService.Instance.Sync.SyncGroups) { - groups = await GetGroupsAsync(); + groups = await GetGroupsAsync(force); } List users = null; if(SettingsService.Instance.Sync.SyncUsers) { - users = await GetUsersAsync(); + users = await GetUsersAsync(force); } FlattenGroupsToUsers(groups, null, groups, users); @@ -87,7 +87,7 @@ namespace Bit.Core.Utilities } } - private static Task> GetGroupsAsync() + private static Task> GetGroupsAsync(bool force = false) { if(!SettingsService.Instance.Sync.SyncGroups) { @@ -113,7 +113,7 @@ namespace Bit.Core.Utilities var filter = string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.GroupFilter) ? null : SettingsService.Instance.Sync.GroupFilter; - if(!string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.RevisionDateAttribute) && + if(!force && !string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.RevisionDateAttribute) && SettingsService.Instance.LastGroupSyncDate.HasValue) { filter = string.Format("(&{0}({1}>{2}))", @@ -177,7 +177,7 @@ namespace Bit.Core.Utilities return Task.FromResult(groups); } - private static Task> GetUsersAsync() + private static Task> GetUsersAsync(bool force = false) { if(!SettingsService.Instance.Sync.SyncUsers) { @@ -203,7 +203,7 @@ namespace Bit.Core.Utilities var filter = string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.UserFilter) ? null : SettingsService.Instance.Sync.UserFilter; - if(!string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.RevisionDateAttribute) && + if(!force && !string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.RevisionDateAttribute) && SettingsService.Instance.LastUserSyncDate.HasValue) { filter = string.Format("(&{0}({1}>{2}))",