@@ -75,6 +75,7 @@ class CryptoFileSystemImpl extends CryptoFileSystem {
75
75
private final CryptoFileStore fileStore ;
76
76
private final CryptoFileSystemStats stats ;
77
77
private final CryptoPathMapper cryptoPathMapper ;
78
+ private final LongFileNameProvider longFileNameProvider ;
78
79
private final CryptoPathFactory cryptoPathFactory ;
79
80
private final PathMatcherFactory pathMatcherFactory ;
80
81
private final DirectoryStreamFactory directoryStreamFactory ;
@@ -95,7 +96,7 @@ class CryptoFileSystemImpl extends CryptoFileSystem {
95
96
96
97
@ Inject
97
98
public CryptoFileSystemImpl (CryptoFileSystemProvider provider , CryptoFileSystems cryptoFileSystems , @ PathToVault Path pathToVault , Cryptor cryptor ,
98
- CryptoFileStore fileStore , CryptoFileSystemStats stats , CryptoPathMapper cryptoPathMapper , CryptoPathFactory cryptoPathFactory ,
99
+ CryptoFileStore fileStore , CryptoFileSystemStats stats , CryptoPathMapper cryptoPathMapper , LongFileNameProvider longFileNameProvider , CryptoPathFactory cryptoPathFactory ,
99
100
PathMatcherFactory pathMatcherFactory , DirectoryStreamFactory directoryStreamFactory , DirectoryIdProvider dirIdProvider ,
100
101
AttributeProvider fileAttributeProvider , AttributeByNameProvider fileAttributeByNameProvider , AttributeViewProvider fileAttributeViewProvider ,
101
102
OpenCryptoFiles openCryptoFiles , Symlinks symlinks , FinallyUtil finallyUtil , CiphertextDirectoryDeleter ciphertextDirDeleter , ReadonlyFlag readonlyFlag , RootDirectoryInitializer rootDirectoryInitializer ) {
@@ -106,6 +107,7 @@ public CryptoFileSystemImpl(CryptoFileSystemProvider provider, CryptoFileSystems
106
107
this .fileStore = fileStore ;
107
108
this .stats = stats ;
108
109
this .cryptoPathMapper = cryptoPathMapper ;
110
+ this .longFileNameProvider = longFileNameProvider ;
109
111
this .cryptoPathFactory = cryptoPathFactory ;
110
112
this .pathMatcherFactory = pathMatcherFactory ;
111
113
this .directoryStreamFactory = directoryStreamFactory ;
@@ -302,6 +304,7 @@ void createDirectory(CryptoPath cleartextDir, FileAttribute<?>... attrs) throws
302
304
// create dir if and only if the dirFile has been created right now (not if it has been created before):
303
305
try {
304
306
Files .createDirectories (ciphertextDir .path );
307
+ longFileNameProvider .persistCachedIfDeflated (ciphertextDirFile );
305
308
} catch (IOException e ) {
306
309
// make sure there is no orphan dir file:
307
310
Files .delete (ciphertextDirFile );
@@ -351,7 +354,9 @@ private FileChannel newFileChannel(CryptoPath cleartextFilePath, EffectiveOpenOp
351
354
throw new FileAlreadyExistsException (cleartextFilePath .toString ());
352
355
} else {
353
356
// might also throw FileAlreadyExists:
354
- return openCryptoFiles .getOrCreate (ciphertextPath ).newFileChannel (options );
357
+ FileChannel ch = openCryptoFiles .getOrCreate (ciphertextPath ).newFileChannel (options );
358
+ longFileNameProvider .persistCachedIfDeflated (ciphertextPath );
359
+ return ch ;
355
360
}
356
361
}
357
362
@@ -419,6 +424,7 @@ private void copySymlink(CryptoPath cleartextSource, CryptoPath cleartextTarget,
419
424
Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .SYMLINK );
420
425
CopyOption [] resolvedOptions = ArrayUtils .without (options , LinkOption .NOFOLLOW_LINKS ).toArray (CopyOption []::new );
421
426
Files .copy (ciphertextSourceFile , ciphertextTargetFile , resolvedOptions );
427
+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
422
428
} else {
423
429
CryptoPath resolvedSource = symlinks .resolveRecursively (cleartextSource );
424
430
CryptoPath resolvedTarget = symlinks .resolveRecursively (cleartextTarget );
@@ -431,6 +437,7 @@ private void copyFile(CryptoPath cleartextSource, CryptoPath cleartextTarget, Co
431
437
Path ciphertextSourceFile = cryptoPathMapper .getCiphertextFilePath (cleartextSource , CiphertextFileType .FILE );
432
438
Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .FILE );
433
439
Files .copy (ciphertextSourceFile , ciphertextTargetFile , options );
440
+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
434
441
}
435
442
436
443
private void copyDirectory (CryptoPath cleartextSource , CryptoPath cleartextTarget , CopyOption [] options ) throws IOException {
@@ -439,6 +446,7 @@ private void copyDirectory(CryptoPath cleartextSource, CryptoPath cleartextTarge
439
446
if (Files .notExists (ciphertextTargetDirFile )) {
440
447
// create new:
441
448
createDirectory (cleartextTarget );
449
+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetDirFile );
442
450
} else if (ArrayUtils .contains (options , StandardCopyOption .REPLACE_EXISTING )) {
443
451
// keep existing (if empty):
444
452
Path ciphertextTargetDir = cryptoPathMapper .getCiphertextDir (cleartextTarget ).path ;
@@ -517,6 +525,7 @@ private void moveSymlink(CryptoPath cleartextSource, CryptoPath cleartextTarget,
517
525
Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .SYMLINK );
518
526
try (OpenCryptoFiles .TwoPhaseMove twoPhaseMove = openCryptoFiles .prepareMove (ciphertextSourceFile , ciphertextTargetFile )) {
519
527
Files .move (ciphertextSourceFile , ciphertextTargetFile , options );
528
+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
520
529
twoPhaseMove .commit ();
521
530
}
522
531
}
@@ -528,6 +537,7 @@ private void moveFile(CryptoPath cleartextSource, CryptoPath cleartextTarget, Co
528
537
Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .FILE );
529
538
try (OpenCryptoFiles .TwoPhaseMove twoPhaseMove = openCryptoFiles .prepareMove (ciphertextSourceFile , ciphertextTargetFile )) {
530
539
Files .move (ciphertextSourceFile , ciphertextTargetFile , options );
540
+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
531
541
twoPhaseMove .commit ();
532
542
}
533
543
}
@@ -540,6 +550,7 @@ private void moveDirectory(CryptoPath cleartextSource, CryptoPath cleartextTarge
540
550
if (!ArrayUtils .contains (options , StandardCopyOption .REPLACE_EXISTING )) {
541
551
// try to move, don't replace:
542
552
Files .move (ciphertextSourceDirFile , ciphertextTargetDirFile , options );
553
+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetDirFile );
543
554
} else if (ArrayUtils .contains (options , StandardCopyOption .ATOMIC_MOVE )) {
544
555
// replace atomically (impossible):
545
556
assert ArrayUtils .contains (options , StandardCopyOption .REPLACE_EXISTING );
@@ -558,6 +569,7 @@ private void moveDirectory(CryptoPath cleartextSource, CryptoPath cleartextTarge
558
569
Files .delete (ciphertextTargetDir );
559
570
}
560
571
Files .move (ciphertextSourceDirFile , ciphertextTargetDirFile , options );
572
+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetDirFile );
561
573
}
562
574
dirIdProvider .move (ciphertextSourceDirFile , ciphertextTargetDirFile );
563
575
cryptoPathMapper .invalidatePathMapping (cleartextSource );
0 commit comments