@@ -73,7 +73,7 @@ public class GitRepositoryProvider: RepositoryProvider {
73
73
/// Clones the git repository we want to cache into the cache directory if it does not already exist and returns it.
74
74
/// If the repository is already cached we perfrom a fetch. In case the `RepositoryProvider`has no `cachePath` or an error occured while
75
75
/// setting up the cache `nil` is returned.
76
- private func setupCacheIfNeeded( for repository: RepositorySpecifier ) -> GitRepository ? {
76
+ private func setupCacheIfNeeded( for repository: RepositorySpecifier ) throws -> GitRepository ? {
77
77
guard let cachePath = cachePath else { return nil }
78
78
let repositoryPath = cachePath. appending ( component: repository. fileSystemIdentifier)
79
79
@@ -93,7 +93,10 @@ public class GitRepositoryProvider: RepositoryProvider {
93
93
}
94
94
95
95
try processSet? . add ( process)
96
- try process. checkNonZeroExit ( )
96
+ let lock = FileLock ( name: repository. fileSystemIdentifier, cachePath: cachePath)
97
+ try lock. withLock {
98
+ try ! process. checkNonZeroExit ( )
99
+ }
97
100
} catch {
98
101
return nil
99
102
}
@@ -118,11 +121,14 @@ public class GitRepositoryProvider: RepositoryProvider {
118
121
for repository in repositories {
119
122
let cacheSize = try localFileSystem. getDirectorySize ( cachePath)
120
123
guard cacheSize > desiredCacheSize else { break }
121
- try localFileSystem. removeFileTree ( repository. path)
124
+ let lock = FileLock ( name: repository. path. basename, cachePath: cachePath)
125
+ try lock. withLock {
126
+ try localFileSystem. removeFileTree ( repository. path)
127
+ }
122
128
}
123
129
} catch {
124
130
// The cache seems to be broken. Lets remove everything.
125
- try ? localFileSystem . removeFileTree ( cachePath )
131
+ print ( " Error purging cache " )
126
132
}
127
133
}
128
134
@@ -139,14 +145,17 @@ public class GitRepositoryProvider: RepositoryProvider {
139
145
// FIXME: We need infrastructure in this subsystem for reporting
140
146
// status information.
141
147
142
- if let cache = setupCacheIfNeeded ( for: repository) {
148
+ if let cachePath = cachePath , let cache = try setupCacheIfNeeded ( for: repository) {
143
149
// Clone the repository using the cache as a reference if possible.
144
150
// Git objects are not shared (--dissociate) to avoid problems that might occur when the cache is
145
151
// deleted or the package is copied somewhere it cannot reach the cache directory.
146
152
let process = Process ( args: Git . tool, " clone " , " --mirror " ,
147
153
cache. path. pathString, path. pathString, environment: Git . environment)
148
154
try processSet? . add ( process)
149
- try process. checkGitError ( repository: repository)
155
+ let lock = FileLock ( name: cache. path. basename, cachePath: cachePath)
156
+ try lock. withLock {
157
+ try process. checkGitError ( repository: repository)
158
+ }
150
159
151
160
let clone = GitRepository ( path: path, isWorkingRepo: false )
152
161
// In destination repo remove the remote which will be pointing to the cached source repo.
0 commit comments