|
6 | 6 | import os |
7 | 7 |
|
8 | 8 | from ._common import with_repository, Highlander |
9 | | -from ..archive import Archive |
10 | | -from ..cache import Cache |
11 | 9 | from ..constants import * # NOQA |
12 | 10 | from ..helpers import ArchiveFormatter, interval, sig_int, ProgressIndicatorPercent, CommandError, Error |
13 | 11 | from ..helpers import archivename_validator |
@@ -172,44 +170,41 @@ def do_prune(self, args, repository, manifest): |
172 | 170 | to_delete = set(archives) - set(keep) |
173 | 171 | logger.info("Found %d archives.", len(archives)) |
174 | 172 | logger.info("Keeping %d archives, pruning %d archives.", len(keep), len(to_delete)) |
175 | | - with Cache(repository, manifest, iec=args.iec) as cache: |
176 | | - list_logger = logging.getLogger("borg.output.list") |
177 | | - # set up counters for the progress display |
178 | | - to_delete_len = len(to_delete) |
179 | | - archives_deleted = 0 |
180 | | - uncommitted_deletes = 0 |
181 | | - pi = ProgressIndicatorPercent(total=len(to_delete), msg="Pruning archives %3.0f%%", msgid="prune") |
182 | | - for archive_info in archives: |
183 | | - if sig_int and sig_int.action_done(): |
184 | | - break |
185 | | - # format_item may internally load the archive from the repository, |
186 | | - # so we must call it before deleting the archive. |
187 | | - archive_formatted = formatter.format_item(archive_info, jsonline=False) |
188 | | - if archive_info in to_delete: |
189 | | - pi.show() |
190 | | - if args.dry_run: |
191 | | - log_message = "Would prune:" |
192 | | - else: |
193 | | - archives_deleted += 1 |
194 | | - log_message = "Pruning archive (%d/%d):" % (archives_deleted, to_delete_len) |
195 | | - archive = Archive(manifest, archive_info.id, cache=cache) |
196 | | - archive.delete() |
197 | | - uncommitted_deletes += 1 |
| 173 | + list_logger = logging.getLogger("borg.output.list") |
| 174 | + # set up counters for the progress display |
| 175 | + to_delete_len = len(to_delete) |
| 176 | + archives_deleted = 0 |
| 177 | + pi = ProgressIndicatorPercent(total=len(to_delete), msg="Pruning archives %3.0f%%", msgid="prune") |
| 178 | + for archive_info in archives: |
| 179 | + if sig_int and sig_int.action_done(): |
| 180 | + break |
| 181 | + # format_item may internally load the archive from the repository, |
| 182 | + # so we must call it before deleting the archive. |
| 183 | + archive_formatted = formatter.format_item(archive_info, jsonline=False) |
| 184 | + if archive_info in to_delete: |
| 185 | + pi.show() |
| 186 | + if args.dry_run: |
| 187 | + log_message = "Would prune:" |
198 | 188 | else: |
199 | | - log_message = "Keeping archive (rule: {rule} #{num}):".format( |
200 | | - rule=kept_because[archive_info.id][0], num=kept_because[archive_info.id][1] |
201 | | - ) |
202 | | - if ( |
203 | | - args.output_list |
204 | | - or (args.list_pruned and archive_info in to_delete) |
205 | | - or (args.list_kept and archive_info not in to_delete) |
206 | | - ): |
207 | | - list_logger.info(f"{log_message:<44} {archive_formatted}") |
208 | | - pi.finish() |
209 | | - if sig_int: |
210 | | - raise Error("Got Ctrl-C / SIGINT.") |
211 | | - elif uncommitted_deletes > 0: |
212 | | - manifest.write() |
| 189 | + log_message = "Pruning archive (%d/%d):" % (archives_deleted, to_delete_len) |
| 190 | + manifest.archives.delete_by_id(archive_info.id) |
| 191 | + archives_deleted += 1 |
| 192 | + else: |
| 193 | + log_message = "Keeping archive (rule: {rule} #{num}):".format( |
| 194 | + rule=kept_because[archive_info.id][0], num=kept_because[archive_info.id][1] |
| 195 | + ) |
| 196 | + if ( |
| 197 | + args.output_list |
| 198 | + or (args.list_pruned and archive_info in to_delete) |
| 199 | + or (args.list_kept and archive_info not in to_delete) |
| 200 | + ): |
| 201 | + list_logger.info(f"{log_message:<44} {archive_formatted}") |
| 202 | + pi.finish() |
| 203 | + if archives_deleted > 0: |
| 204 | + manifest.write() |
| 205 | + self.print_warning('Done. Run "borg compact" to free space.', wc=None) |
| 206 | + if sig_int: |
| 207 | + raise Error("Got Ctrl-C / SIGINT.") |
213 | 208 |
|
214 | 209 | def build_parser_prune(self, subparsers, common_parser, mid_common_parser): |
215 | 210 | from ._common import process_epilog |
|
0 commit comments