@@ -269,7 +269,7 @@ private void deleteTrapFileAndDependencies(IrDeclaration sym, String signature)
269
269
* Any unique suffix needed to distinguish `sym` from other declarations with the same name.
270
270
* For functions for example, this means its parameter signature.
271
271
*/
272
- private TrapFileManager getMembersWriterForDecl (File trap , IrDeclaration sym , String signature ) {
272
+ private TrapFileManager getMembersWriterForDecl (File trap , File trapFileBase , TrapClassVersion trapFileVersion , IrDeclaration sym , String signature ) {
273
273
if (use_trap_locking ) {
274
274
TrapClassVersion currVersion = TrapClassVersion .fromSymbol (sym , log );
275
275
String shortName = sym instanceof IrDeclarationWithName ? ((IrDeclarationWithName )sym ).getName ().asString () : "(name unknown)" ;
@@ -298,11 +298,30 @@ private TrapFileManager getMembersWriterForDecl(File trap, IrDeclaration sym, St
298
298
// then renamed to its trap-old name, then we
299
299
// don't need to rewrite it only to rename it
300
300
// again.
301
- File trapOld = new File (trap .getParentFile (), trap .getName ().replace (".trap.gz" , ".trap-old.gz" ));
301
+ File trapFileDir = trap .getParentFile ();
302
+ File trapOld = new File (trapFileDir , trap .getName ().replace (".trap.gz" , ".trap-old.gz" ));
302
303
if (trapOld .exists ()) {
303
304
log .warn ("Not rewriting trap file for " + trap .toString () + " as the trap-old exists" );
304
305
return null ;
305
306
}
307
+ // Otherwise, if any newer TRAP file has already
308
+ // been written then we don't need to write
309
+ // anything.
310
+ if (trapFileBase != null && trapFileVersion != null && trapFileDir .exists ()) {
311
+ String trapFileBaseName = trapFileBase .getName ();
312
+
313
+ for (File f : FileUtil .list (trapFileDir )) {
314
+ String name = f .getName ();
315
+ Matcher m = selectClassVersionComponents .matcher (name );
316
+ if (m .matches () && m .group (1 ).equals (trapFileBaseName )) {
317
+ TrapClassVersion v = new TrapClassVersion (Integer .valueOf (m .group (2 )), Integer .valueOf (m .group (3 )), Long .valueOf (m .group (4 )), m .group (5 ));
318
+ if (v .newerThan (trapFileVersion )) {
319
+ log .warn ("Not rewriting trap file for " + trap .toString () + " as " + f .toString () + " exists" );
320
+ return null ;
321
+ }
322
+ }
323
+ }
324
+ }
306
325
}
307
326
return trapWriter (trap , sym , signature );
308
327
}
@@ -390,6 +409,8 @@ public void setHasError() {
390
409
* Trap file locking.
391
410
*/
392
411
412
+ private final Pattern selectClassVersionComponents = Pattern .compile ("(.*)#(-?[0-9]+)\\ .(-?[0-9]+)-(-?[0-9]+)-(.*)\\ .trap\\ .gz" );
413
+
393
414
/**
394
415
* <b>CAUTION</b>: to avoid the potential for deadlock between multiple concurrent extractor processes,
395
416
* only one source file {@link TrapLocker} may be open at any time, and the lock must be obtained
@@ -485,14 +506,12 @@ public TrapFileManager getTrapFileManager() {
485
506
if (use_trap_locking ) {
486
507
lockTrapFile (trapFile );
487
508
}
488
- return getMembersWriterForDecl (trapFile , sym , signature );
509
+ return getMembersWriterForDecl (trapFile , trapFileBase , trapFileVersion , sym , signature );
489
510
} else {
490
511
return null ;
491
512
}
492
513
}
493
514
494
- private final Pattern selectClassVersionComponents = Pattern .compile ("(.*)#(-?[0-9]+)\\ .(-?[0-9]+)-(-?[0-9]+)-(.*)\\ .trap\\ .gz" );
495
-
496
515
@ Override
497
516
public void close () {
498
517
if (trapFile !=null ) {
0 commit comments