From 732c8244a476399a86c7aa6f02400da476d92f85 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Tue, 23 Aug 2022 17:31:02 +0400 Subject: [PATCH] Run garbage collection after each symlink and expose --gc in tart prune (#191) --- Sources/tart/Commands/Prune.swift | 7 +++++++ Sources/tart/VMStorageOCI.swift | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Sources/tart/Commands/Prune.swift b/Sources/tart/Commands/Prune.swift index 39037d8..cab8eaf 100644 --- a/Sources/tart/Commands/Prune.swift +++ b/Sources/tart/Commands/Prune.swift @@ -16,6 +16,9 @@ struct Prune: AsyncParsableCommand { valueName: "n")) var cacheBudget: UInt? + @Flag(help: .hidden) + var gc: Bool = false + func validate() throws { if olderThan == nil && cacheBudget == nil { throw ValidationError("at least one criteria must be specified") @@ -24,6 +27,10 @@ struct Prune: AsyncParsableCommand { func run() async throws { do { + if gc { + try VMStorageOCI().gc() + } + // Clean up cache entries based on last accessed date if let olderThan = olderThan { let olderThanInterval = Int(exactly: olderThan)!.days.timeInterval diff --git a/Sources/tart/VMStorageOCI.swift b/Sources/tart/VMStorageOCI.swift index f9f616c..00e6ce1 100644 --- a/Sources/tart/VMStorageOCI.swift +++ b/Sources/tart/VMStorageOCI.swift @@ -166,6 +166,8 @@ class VMStorageOCI: PrunableStorage { } try FileManager.default.createSymbolicLink(at: vmURL(to), withDestinationURL: vmURL(from)) + + try gc() } }