diff --git a/src/borg/archiver/create_cmd.py b/src/borg/archiver/create_cmd.py index d87c1bd1e..785c7ea8a 100644 --- a/src/borg/archiver/create_cmd.py +++ b/src/borg/archiver/create_cmd.py @@ -224,8 +224,9 @@ class CreateMixIn: manifest, progress=args.progress, lock_wait=self.lock_wait, - permit_adhoc_cache=args.no_cache_sync, - force_adhoc_cache=args.no_cache_sync_forced, + no_cache_sync_permitted=args.no_cache_sync, + no_cache_sync_forced=args.no_cache_sync_forced, + prefer_adhoc_cache=args.prefer_adhoc_cache, cache_mode=args.files_cache_mode, iec=args.iec, ) as cache: @@ -802,13 +803,19 @@ class CreateMixIn: "--no-cache-sync", dest="no_cache_sync", action="store_true", - help="experimental: do not synchronize the cache. Implies not using the files cache.", + help="experimental: do not synchronize the chunks cache.", ) subparser.add_argument( "--no-cache-sync-forced", dest="no_cache_sync_forced", action="store_true", - help="experimental: do not synchronize the cache (forced). Implies not using the files cache.", + help="experimental: do not synchronize the chunks cache (forced).", + ) + subparser.add_argument( + "--prefer-adhoc-cache", + dest="prefer_adhoc_cache", + action="store_true", + help="experimental: prefer AdHocCache (w/o files cache) over NewCache (with files cache).", ) subparser.add_argument( "--stdin-name", diff --git a/src/borg/cache.py b/src/borg/cache.py index 20e7a3903..a7f6bc53c 100644 --- a/src/borg/cache.py +++ b/src/borg/cache.py @@ -350,8 +350,9 @@ class Cache: warn_if_unencrypted=True, progress=False, lock_wait=None, - permit_adhoc_cache=False, - force_adhoc_cache=False, + no_cache_sync_permitted=False, + no_cache_sync_forced=False, + prefer_adhoc_cache=False, cache_mode=FILES_CACHE_MODE_DISABLED, iec=False, ): @@ -381,14 +382,14 @@ class Cache: def adhoc(): return AdHocCache(manifest=manifest, lock_wait=lock_wait, iec=iec) - if force_adhoc_cache: - return adhoc() + if no_cache_sync_forced: + return adhoc() if prefer_adhoc_cache else newcache() - if not permit_adhoc_cache: + if not no_cache_sync_permitted: return local() - # ad-hoc cache may be permitted, but if the local cache is in sync it'd be stupid to invalidate - # it by needlessly using the ad-hoc cache. + # no cache sync may be permitted, but if the local cache is in sync it'd be stupid to invalidate + # it by needlessly using the AdHocCache or the NewCache. # Check if the local cache exists and is in sync. cache_config = CacheConfig(repository, path, lock_wait) @@ -400,8 +401,12 @@ class Cache: # Local cache is in sync, use it logger.debug("Cache: choosing local cache (in sync)") return local() - logger.debug("Cache: choosing ad-hoc cache (local cache does not exist or is not in sync)") - return adhoc() + if prefer_adhoc_cache: + logger.debug("Cache: choosing AdHocCache (local cache does not exist or is not in sync)") + return adhoc() + else: + logger.debug("Cache: choosing NewCache (local cache does not exist or is not in sync)") + return newcache() class CacheStatsMixin: diff --git a/src/borg/testsuite/archiver/create_cmd.py b/src/borg/testsuite/archiver/create_cmd.py index a064f4635..82b7c7af7 100644 --- a/src/borg/testsuite/archiver/create_cmd.py +++ b/src/borg/testsuite/archiver/create_cmd.py @@ -540,20 +540,20 @@ def test_create_pattern_intermediate_folders_first(archivers, request): assert out_list.index("d x/b") < out_list.index("- x/b/foo_b") -def test_create_no_cache_sync(archivers, request): +def test_create_no_cache_sync_adhoc(archivers, request): # TODO: add test for NewCache archiver = request.getfixturevalue(archivers) create_test_files(archiver.input_path) cmd(archiver, "rcreate", RK_ENCRYPTION) cmd(archiver, "rdelete", "--cache-only") create_json = json.loads( - cmd(archiver, "create", "--no-cache-sync", "--json", "--error", "test", "input") + cmd(archiver, "create", "--no-cache-sync", "--prefer-adhoc-cache", "--json", "--error", "test", "input") ) # ignore experimental warning info_json = json.loads(cmd(archiver, "info", "-a", "test", "--json")) create_stats = create_json["cache"]["stats"] info_stats = info_json["cache"]["stats"] assert create_stats == info_stats cmd(archiver, "rdelete", "--cache-only") - cmd(archiver, "create", "--no-cache-sync", "test2", "input") + cmd(archiver, "create", "--no-cache-sync", "--prefer-adhoc-cache", "test2", "input") cmd(archiver, "rinfo") cmd(archiver, "check")