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