@@ -107,12 +107,14 @@ private static final class PathMetadata {
107
107
private final Digest digest ;
108
108
private final boolean directory ;
109
109
private final boolean remote ;
110
+ private final boolean omitted ;
110
111
111
- PathMetadata (Path path , Digest digest , boolean directory , boolean remote ) {
112
+ PathMetadata (Path path , Digest digest , boolean directory , boolean remote , boolean omitted ) {
112
113
this .path = path ;
113
114
this .digest = digest ;
114
115
this .directory = directory ;
115
116
this .remote = remote ;
117
+ this .omitted = omitted ;
116
118
}
117
119
118
120
public Path getPath () {
@@ -130,6 +132,10 @@ public boolean isDirectory() {
130
132
public boolean isRemote () {
131
133
return remote ;
132
134
}
135
+
136
+ public boolean isOmitted () {
137
+ return omitted ;
138
+ }
133
139
}
134
140
135
141
/**
@@ -138,22 +144,29 @@ public boolean isRemote() {
138
144
*/
139
145
private PathMetadata readPathMetadata (Path file ) throws IOException {
140
146
if (file .isDirectory ()) {
141
- return new PathMetadata (file , /* digest= */ null , /* directory= */ true , /* remote= */ false );
142
- }
143
- if (omittedFiles .contains (file )) {
144
- return new PathMetadata (file , /*digest=*/ null , /*directory=*/ false , /*remote=*/ false );
147
+ return new PathMetadata (
148
+ file ,
149
+ /* digest= */ null ,
150
+ /* directory= */ true ,
151
+ /* remote= */ false ,
152
+ /* omitted= */ false );
145
153
}
146
154
147
- for (Path treeRoot : omittedTreeRoots ) {
148
- if (file .startsWith (treeRoot )) {
149
- omittedFiles .add (file );
150
- return new PathMetadata (file , /*digest=*/ null , /*directory=*/ false , /*remote=*/ false );
155
+ boolean omitted = false ;
156
+ if (omittedFiles .contains (file )) {
157
+ omitted = true ;
158
+ } else {
159
+ for (Path treeRoot : omittedTreeRoots ) {
160
+ if (file .startsWith (treeRoot )) {
161
+ omittedFiles .add (file );
162
+ omitted = true ;
163
+ }
151
164
}
152
165
}
153
166
154
167
DigestUtil digestUtil = new DigestUtil (file .getFileSystem ().getDigestFunction ());
155
168
Digest digest = digestUtil .compute (file );
156
- return new PathMetadata (file , digest , /* directory= */ false , isRemoteFile (file ));
169
+ return new PathMetadata (file , digest , /* directory= */ false , isRemoteFile (file ), omitted );
157
170
}
158
171
159
172
private static void processQueryResult (
@@ -166,14 +179,18 @@ private static void processQueryResult(
166
179
} else {
167
180
PathMetadata remotePathMetadata =
168
181
new PathMetadata (
169
- file .getPath (), file .getDigest (), file .isDirectory (), /* remote= */ true );
182
+ file .getPath (),
183
+ file .getDigest (),
184
+ file .isDirectory (),
185
+ /* remote= */ true ,
186
+ file .isOmitted ());
170
187
knownRemotePaths .add (remotePathMetadata );
171
188
}
172
189
}
173
190
}
174
191
175
192
private static boolean shouldUpload (PathMetadata path ) {
176
- return path .getDigest () != null && !path .isRemote () && !path .isDirectory ();
193
+ return path .getDigest () != null && !path .isRemote () && !path .isDirectory () && ! path . isOmitted () ;
177
194
}
178
195
179
196
private Single <List <PathMetadata >> queryRemoteCache (
@@ -182,7 +199,8 @@ private Single<List<PathMetadata>> queryRemoteCache(
182
199
List <PathMetadata > filesToQuery = new ArrayList <>();
183
200
Set <Digest > digestsToQuery = new HashSet <>();
184
201
for (PathMetadata path : paths ) {
185
- if (shouldUpload (path )) {
202
+ // Query remote cache for files even if omitted from uploading
203
+ if (shouldUpload (path ) || path .isOmitted ()) {
186
204
filesToQuery .add (path );
187
205
digestsToQuery .add (path .getDigest ());
188
206
} else {
@@ -239,7 +257,8 @@ private Single<List<PathMetadata>> uploadLocalFiles(
239
257
path .getPath (),
240
258
/*digest=*/ null ,
241
259
path .isDirectory (),
242
- path .isRemote ()));
260
+ path .isRemote (),
261
+ path .isOmitted ()));
243
262
});
244
263
})
245
264
.collect (Collectors .toList ());
@@ -265,13 +284,17 @@ private Single<PathConverter> upload(Set<Path> files) {
265
284
} catch (IOException e ) {
266
285
reporterUploadError (e );
267
286
return new PathMetadata (
268
- file , /*digest=*/ null , /*directory=*/ false , /*remote=*/ false );
287
+ file ,
288
+ /*digest=*/ null ,
289
+ /*directory=*/ false ,
290
+ /*remote=*/ false ,
291
+ /*omitted=*/ false );
269
292
}
270
293
})
271
294
.collect (Collectors .toList ())
272
295
.flatMap (paths -> queryRemoteCache (remoteCache , context , paths ))
273
296
.flatMap (paths -> uploadLocalFiles (remoteCache , context , paths ))
274
- .map (paths -> new PathConverterImpl (remoteServerInstanceName , paths , omittedFiles )),
297
+ .map (paths -> new PathConverterImpl (remoteServerInstanceName , paths )),
275
298
RemoteCache ::release );
276
299
}
277
300
@@ -305,23 +328,25 @@ private static class PathConverterImpl implements PathConverter {
305
328
private final Set <Path > skippedPaths ;
306
329
private final Set <Path > localPaths ;
307
330
308
- PathConverterImpl (
309
- String remoteServerInstanceName , List <PathMetadata > uploads , Set <Path > localPaths ) {
331
+ PathConverterImpl (String remoteServerInstanceName , List <PathMetadata > uploads ) {
310
332
Preconditions .checkNotNull (uploads );
311
333
this .remoteServerInstanceName = remoteServerInstanceName ;
312
334
pathToDigest = new HashMap <>(uploads .size ());
313
335
ImmutableSet .Builder <Path > skippedPaths = ImmutableSet .builder ();
336
+ ImmutableSet .Builder <Path > localPaths = ImmutableSet .builder ();
314
337
for (PathMetadata pair : uploads ) {
315
338
Path path = pair .getPath ();
316
339
Digest digest = pair .getDigest ();
317
- if (digest != null ) {
340
+ if (!pair .isRemote () && pair .isOmitted ()) {
341
+ localPaths .add (path );
342
+ } else if (digest != null ) {
318
343
pathToDigest .put (path , digest );
319
344
} else {
320
345
skippedPaths .add (path );
321
346
}
322
347
}
323
348
this .skippedPaths = skippedPaths .build ();
324
- this .localPaths = localPaths ;
349
+ this .localPaths = localPaths . build () ;
325
350
}
326
351
327
352
@ Override
0 commit comments