File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,9 @@ public class SwiftPackageTool: SwiftTool<PackageToolOptions> {
153
153
case . reset:
154
154
try getActiveWorkspace ( ) . reset ( with: diagnostics)
155
155
156
+ case . cleanCache:
157
+ try getActiveWorkspace ( ) . cleanCache ( with: diagnostics)
158
+
156
159
case . apidiff:
157
160
let apiDigesterPath = try getToolchain ( ) . getSwiftAPIDigester ( )
158
161
let apiDigesterTool = SwiftAPIDigester ( tool: apiDigesterPath)
@@ -468,9 +471,10 @@ public class SwiftPackageTool: SwiftTool<PackageToolOptions> {
468
471
to: { $0. editOptions. path = $1. path } )
469
472
470
473
parser. add ( subparser: PackageMode . clean. rawValue, overview: " Delete build artifacts " )
474
+ parser. add ( subparser: PackageMode . cleanCache. rawValue, overview: " Clean the repository cache " )
471
475
parser. add ( subparser: PackageMode . fetch. rawValue, overview: " " )
472
- parser. add ( subparser: PackageMode . reset. rawValue, overview: " Reset the complete cache/ build directory " )
473
-
476
+ parser. add ( subparser: PackageMode . reset. rawValue, overview: " Reset the complete build directory " )
477
+
474
478
let updateParser = parser. add ( subparser: PackageMode . update. rawValue, overview: " Update package dependencies " )
475
479
binder. bind (
476
480
positional: updateParser. add (
@@ -830,6 +834,7 @@ public class PackageToolOptions: ToolOptions {
830
834
831
835
public enum PackageMode : String , StringEnumArgument {
832
836
case clean
837
+ case cleanCache = " clean-cache "
833
838
case config
834
839
case format = " _format "
835
840
case describe
Original file line number Diff line number Diff line change @@ -618,6 +618,32 @@ extension Workspace {
618
618
}
619
619
}
620
620
621
+ /// Cleans the repository cache.
622
+ ///
623
+ /// - Parameters:
624
+ /// - diagnostics: The diagnostics engine that reports errors, warnings
625
+ /// and notes.
626
+ public func cleanCache( with diagnostics: DiagnosticsEngine ) {
627
+ // If we have no data yet, we're done.
628
+ guard fileSystem. exists ( repositoryManager. path) else {
629
+ return
630
+ }
631
+
632
+ guard let repositories = diagnostics. wrap ( { try fileSystem. getDirectoryContents ( repositoryManager. path) } ) else {
633
+ return
634
+ }
635
+
636
+ for repository in repositories {
637
+ let filePath = dataPath. appending ( RelativePath ( repository) )
638
+ let lock = FileLock ( name: filePath. basename, cachePath: filePath)
639
+ diagnostics. wrap {
640
+ try lock. withLock {
641
+ try fileSystem. removeFileTree ( filePath)
642
+ }
643
+ }
644
+ }
645
+ }
646
+
621
647
/// Resets the entire workspace by removing the data directory.
622
648
///
623
649
/// - Parameters:
You can’t perform that action at this time.
0 commit comments