@@ -379,7 +379,7 @@ public long getSize() {
379
379
}
380
380
381
381
@ Override
382
- public boolean wasModifiedSinceDigest (Path path ) throws IOException {
382
+ public boolean wasModifiedSinceDigest (Path path ) {
383
383
return false ;
384
384
}
385
385
@@ -540,24 +540,26 @@ protected boolean couldBeModifiedByMetadata(FileArtifactValue o) {
540
540
541
541
/** Metadata for remotely stored files. */
542
542
public static class RemoteFileArtifactValue extends FileArtifactValue {
543
- protected final byte [] digest ;
544
- protected final long size ;
545
- protected final int locationIndex ;
546
- // The time when the remote file expires in milliseconds since epoch. negative value means the
547
- // remote file will never expire. This field doesn't contribute to the equality of the metadata.
548
- protected final long expireAtEpochMilli ;
543
+ private final byte [] digest ;
544
+ private final long size ;
545
+ private final int locationIndex ;
546
+ @ Nullable private final PathFragment materializationExecPath ;
549
547
550
548
private RemoteFileArtifactValue (
551
- byte [] digest , long size , int locationIndex , long expireAtEpochMilli ) {
549
+ byte [] digest ,
550
+ long size ,
551
+ int locationIndex ,
552
+ @ Nullable PathFragment materializationExecPath ) {
552
553
this .digest = Preconditions .checkNotNull (digest );
553
554
this .size = size ;
554
555
this .locationIndex = locationIndex ;
555
- this .expireAtEpochMilli = expireAtEpochMilli ;
556
+ this .materializationExecPath = materializationExecPath ;
556
557
}
557
558
558
559
public static RemoteFileArtifactValue create (
559
560
byte [] digest , long size , int locationIndex , long expireAtEpochMilli ) {
560
- return new RemoteFileArtifactValue (digest , size , locationIndex , expireAtEpochMilli );
561
+ return create (
562
+ digest , size , locationIndex , expireAtEpochMilli , /* materializationExecPath= */ null );
561
563
}
562
564
563
565
public static RemoteFileArtifactValue create (
@@ -566,147 +568,127 @@ public static RemoteFileArtifactValue create(
566
568
int locationIndex ,
567
569
long expireAtEpochMilli ,
568
570
@ Nullable PathFragment materializationExecPath ) {
569
- if (materializationExecPath != null ) {
570
- return new RemoteFileArtifactValueWithMaterializationPath (
571
- digest , size , locationIndex , expireAtEpochMilli , materializationExecPath );
572
- }
573
- return new RemoteFileArtifactValue (digest , size , locationIndex , expireAtEpochMilli );
571
+ return expireAtEpochMilli < 0
572
+ ? new RemoteFileArtifactValue (digest , size , locationIndex , materializationExecPath )
573
+ : new RemoteFileArtifactValueWithExpiration (
574
+ digest , size , locationIndex , materializationExecPath , expireAtEpochMilli );
574
575
}
575
576
576
577
@ Override
577
578
public boolean equals (Object o ) {
579
+ if (this == o ) {
580
+ return true ;
581
+ }
578
582
if (!(o instanceof RemoteFileArtifactValue )) {
579
583
return false ;
580
584
}
581
585
582
586
RemoteFileArtifactValue that = (RemoteFileArtifactValue ) o ;
583
587
return Arrays .equals (digest , that .digest )
584
588
&& size == that .size
585
- && locationIndex == that .locationIndex ;
589
+ && locationIndex == that .locationIndex
590
+ && Objects .equals (materializationExecPath , that .materializationExecPath );
586
591
}
587
592
588
593
@ Override
589
- public int hashCode () {
590
- return Objects .hash (Arrays .hashCode (digest ), size , locationIndex );
594
+ public final int hashCode () {
595
+ return Objects .hash (Arrays .hashCode (digest ), size , locationIndex , materializationExecPath );
591
596
}
592
597
593
598
@ Override
594
- public FileStateType getType () {
599
+ public final FileStateType getType () {
595
600
return FileStateType .REGULAR_FILE ;
596
601
}
597
602
598
603
@ Override
599
- public byte [] getDigest () {
604
+ public final byte [] getDigest () {
600
605
return digest ;
601
606
}
602
607
603
608
@ Override
604
- public FileContentsProxy getContentsProxy () {
609
+ public final FileContentsProxy getContentsProxy () {
605
610
throw new UnsupportedOperationException ();
606
611
}
607
612
608
613
@ Override
609
- public long getSize () {
614
+ public final long getSize () {
610
615
return size ;
611
616
}
612
617
613
618
@ Override
614
- public long getModifiedTime () {
619
+ public final long getModifiedTime () {
615
620
throw new UnsupportedOperationException (
616
621
"RemoteFileArtifactValue doesn't support getModifiedTime" );
617
622
}
618
623
619
624
@ Override
620
- public int getLocationIndex () {
625
+ public final int getLocationIndex () {
621
626
return locationIndex ;
622
627
}
623
628
629
+ @ Override
630
+ public final Optional <PathFragment > getMaterializationExecPath () {
631
+ return Optional .ofNullable (materializationExecPath );
632
+ }
633
+
634
+ /**
635
+ * Returns the time when the remote file expires in milliseconds since epoch. A negative value
636
+ * means the remote is not known to expire.
637
+ *
638
+ * <p>Expiration time does not contribute to equality of remote files.
639
+ */
624
640
public long getExpireAtEpochMilli () {
625
- return expireAtEpochMilli ;
641
+ return - 1 ;
626
642
}
627
643
628
644
public boolean isAlive (Instant now ) {
629
- if (expireAtEpochMilli < 0 ) {
630
- return true ;
631
- }
632
-
633
- return now .toEpochMilli () < expireAtEpochMilli ;
645
+ return true ;
634
646
}
635
647
636
648
@ Override
637
- public boolean wasModifiedSinceDigest (Path path ) {
649
+ public final boolean wasModifiedSinceDigest (Path path ) {
638
650
return false ;
639
651
}
640
652
641
653
@ Override
642
- public boolean isRemote () {
654
+ public final boolean isRemote () {
643
655
return true ;
644
656
}
645
657
646
658
@ Override
647
- public String toString () {
659
+ public final String toString () {
648
660
return MoreObjects .toStringHelper (this )
649
661
.add ("digest" , bytesToString (digest ))
650
662
.add ("size" , size )
651
663
.add ("locationIndex" , locationIndex )
652
- .add ("expireAtEpochMilli" , expireAtEpochMilli )
664
+ .add ("materializationExecPath" , materializationExecPath )
665
+ .add ("expireAtEpochMilli" , getExpireAtEpochMilli ())
653
666
.toString ();
654
667
}
655
668
}
656
669
657
- /**
658
- * A remote artifact that should be materialized in the local filesystem as a symlink to another
659
- * location.
660
- *
661
- * <p>See the documentation for {@link FileArtifactValue#getMaterializationExecPath}.
662
- */
663
- public static final class RemoteFileArtifactValueWithMaterializationPath
664
- extends RemoteFileArtifactValue {
665
- private final PathFragment materializationExecPath ;
670
+ /** A remote artifact that expires at a particular time. */
671
+ private static final class RemoteFileArtifactValueWithExpiration extends RemoteFileArtifactValue {
672
+ private final long expireAtEpochMilli ;
666
673
667
- private RemoteFileArtifactValueWithMaterializationPath (
674
+ private RemoteFileArtifactValueWithExpiration (
668
675
byte [] digest ,
669
676
long size ,
670
677
int locationIndex ,
671
- long expireAtEpochMilli ,
672
- PathFragment materializationExecPath ) {
673
- super (digest , size , locationIndex , expireAtEpochMilli );
674
- this .materializationExecPath = Preconditions .checkNotNull (materializationExecPath );
675
- }
676
-
677
- @ Override
678
- public Optional <PathFragment > getMaterializationExecPath () {
679
- return Optional .ofNullable (materializationExecPath );
680
- }
681
-
682
- @ Override
683
- public boolean equals (Object o ) {
684
- if (!(o instanceof RemoteFileArtifactValueWithMaterializationPath )) {
685
- return false ;
686
- }
687
-
688
- RemoteFileArtifactValueWithMaterializationPath that =
689
- (RemoteFileArtifactValueWithMaterializationPath ) o ;
690
- return Arrays .equals (digest , that .digest )
691
- && size == that .size
692
- && locationIndex == that .locationIndex
693
- && Objects .equals (materializationExecPath , that .materializationExecPath );
678
+ PathFragment materializationExecPath ,
679
+ long expireAtEpochMilli ) {
680
+ super (digest , size , locationIndex , materializationExecPath );
681
+ this .expireAtEpochMilli = expireAtEpochMilli ;
694
682
}
695
683
696
684
@ Override
697
- public int hashCode () {
698
- return Objects . hash ( Arrays . hashCode ( digest ), size , locationIndex , materializationExecPath ) ;
685
+ public long getExpireAtEpochMilli () {
686
+ return expireAtEpochMilli ;
699
687
}
700
688
701
689
@ Override
702
- public String toString () {
703
- return MoreObjects .toStringHelper (this )
704
- .add ("digest" , bytesToString (digest ))
705
- .add ("size" , size )
706
- .add ("locationIndex" , locationIndex )
707
- .add ("expireAtEpochMilli" , expireAtEpochMilli )
708
- .add ("materializationExecPath" , materializationExecPath )
709
- .toString ();
690
+ public boolean isAlive (Instant now ) {
691
+ return now .toEpochMilli () < expireAtEpochMilli ;
710
692
}
711
693
}
712
694
0 commit comments