Skip to content

Commit

Permalink
Run garbage collection after each symlink and expose --gc in tart pru…
Browse files Browse the repository at this point in the history
…ne (#191)
  • Loading branch information
edigaryev authored Aug 23, 2022
1 parent 9e69c8c commit 732c824
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/tart/Commands/Prune.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Sources/tart/VMStorageOCI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class VMStorageOCI: PrunableStorage {
}

try FileManager.default.createSymbolicLink(at: vmURL(to), withDestinationURL: vmURL(from))

try gc()
}
}

Expand Down

0 comments on commit 732c824

Please sign in to comment.