42
42
import org .eclipse .jgit .internal .storage .reftable .ReftableReader ;
43
43
import org .eclipse .jgit .internal .storage .reftable .ReftableWriter ;
44
44
import org .eclipse .jgit .lib .Config ;
45
+ import org .eclipse .jgit .lib .Constants ;
45
46
import org .eclipse .jgit .lib .CoreConfig ;
46
47
import org .eclipse .jgit .lib .CoreConfig .TrustStat ;
47
48
import org .eclipse .jgit .util .FileUtils ;
@@ -69,7 +70,7 @@ private static class StackEntry {
69
70
70
71
private long lastNextUpdateIndex ;
71
72
72
- private final File stackPath ;
73
+ private final File tablesListFile ;
73
74
74
75
private final File reftableDir ;
75
76
@@ -111,8 +112,6 @@ static class CompactionStats {
111
112
/**
112
113
* Creates a stack corresponding to the list of reftables in the argument
113
114
*
114
- * @param stackPath
115
- * the filename for the stack.
116
115
* @param reftableDir
117
116
* the dir holding the tables.
118
117
* @param onChange
@@ -122,10 +121,10 @@ static class CompactionStats {
122
121
* @throws IOException
123
122
* on I/O problems
124
123
*/
125
- public FileReftableStack (File stackPath , File reftableDir ,
124
+ public FileReftableStack (File reftableDir ,
126
125
@ Nullable Runnable onChange , Supplier <Config > configSupplier )
127
126
throws IOException {
128
- this .stackPath = stackPath ;
127
+ this .tablesListFile = new File ( reftableDir , Constants . TABLES_LIST ) ;
129
128
this .reftableDir = reftableDir ;
130
129
this .stack = new ArrayList <>();
131
130
this .configSupplier = configSupplier ;
@@ -244,7 +243,7 @@ void reload() throws IOException {
244
243
}
245
244
246
245
if (!success ) {
247
- throw new LockFailedException (stackPath );
246
+ throw new LockFailedException (tablesListFile );
248
247
}
249
248
250
249
mergedReftable = new MergedReftable (stack .stream ()
@@ -288,14 +287,14 @@ private List<String> readTableNames() throws IOException {
288
287
List <String > names = new ArrayList <>(stack .size () + 1 );
289
288
old = snapshot .get ();
290
289
try (BufferedReader br = new BufferedReader (
291
- new InputStreamReader (new FileInputStream (stackPath ), UTF_8 ))) {
290
+ new InputStreamReader (new FileInputStream (tablesListFile ), UTF_8 ))) {
292
291
String line ;
293
292
while ((line = br .readLine ()) != null ) {
294
293
if (!line .isEmpty ()) {
295
294
names .add (line );
296
295
}
297
296
}
298
- snapshot .compareAndSet (old , FileSnapshot .save (stackPath ));
297
+ snapshot .compareAndSet (old , FileSnapshot .save (tablesListFile ));
299
298
} catch (FileNotFoundException e ) {
300
299
// file isn't there: empty repository.
301
300
snapshot .compareAndSet (old , FileSnapshot .MISSING_FILE );
@@ -315,15 +314,15 @@ boolean isUpToDate() throws IOException {
315
314
break ;
316
315
case AFTER_OPEN :
317
316
try (InputStream stream = Files
318
- .newInputStream (stackPath .toPath ())) {
317
+ .newInputStream (tablesListFile .toPath ())) {
319
318
// open the tables.list file to refresh attributes (on some
320
319
// NFS clients)
321
320
} catch (FileNotFoundException | NoSuchFileException e ) {
322
321
// ignore
323
322
}
324
323
//$FALL-THROUGH$
325
324
case ALWAYS :
326
- if (!snapshot .get ().isModified (stackPath )) {
325
+ if (!snapshot .get ().isModified (tablesListFile )) {
327
326
return true ;
328
327
}
329
328
break ;
@@ -387,7 +386,7 @@ private String filename(long low, long high) {
387
386
*/
388
387
@ SuppressWarnings ("nls" )
389
388
public boolean addReftable (Writer w ) throws IOException {
390
- LockFile lock = new LockFile (stackPath );
389
+ LockFile lock = new LockFile (tablesListFile );
391
390
try {
392
391
if (!lock .lockForAppend ()) {
393
392
return false ;
@@ -398,8 +397,7 @@ public boolean addReftable(Writer w) throws IOException {
398
397
399
398
String fn = filename (nextUpdateIndex (), nextUpdateIndex ());
400
399
401
- File tmpTable = File .createTempFile (fn + "_" , ".ref" ,
402
- stackPath .getParentFile ());
400
+ File tmpTable = File .createTempFile (fn + "_" , ".ref" , reftableDir );
403
401
404
402
ReftableWriter .Stats s ;
405
403
try (FileOutputStream fos = new FileOutputStream (tmpTable )) {
@@ -453,7 +451,7 @@ private File compactLocked(int first, int last) throws IOException {
453
451
String fn = filename (first , last );
454
452
455
453
File tmpTable = File .createTempFile (fn + "_" , ".ref" , //$NON-NLS-1$//$NON-NLS-2$
456
- stackPath . getParentFile () );
454
+ reftableDir );
457
455
try (FileOutputStream fos = new FileOutputStream (tmpTable )) {
458
456
ReftableCompactor c = new ReftableCompactor (fos )
459
457
.setConfig (reftableConfig ())
@@ -497,7 +495,7 @@ boolean compactRange(int first, int last) throws IOException {
497
495
if (first >= last ) {
498
496
return true ;
499
497
}
500
- LockFile lock = new LockFile (stackPath );
498
+ LockFile lock = new LockFile (tablesListFile );
501
499
502
500
File tmpTable = null ;
503
501
List <LockFile > subtableLocks = new ArrayList <>();
@@ -526,7 +524,7 @@ boolean compactRange(int first, int last) throws IOException {
526
524
527
525
tmpTable = compactLocked (first , last );
528
526
529
- lock = new LockFile (stackPath );
527
+ lock = new LockFile (tablesListFile );
530
528
if (!lock .lock ()) {
531
529
return false ;
532
530
}
0 commit comments