@@ -75,6 +75,7 @@ class CryptoFileSystemImpl extends CryptoFileSystem {
7575 private final CryptoFileStore fileStore ;
7676 private final CryptoFileSystemStats stats ;
7777 private final CryptoPathMapper cryptoPathMapper ;
78+ private final LongFileNameProvider longFileNameProvider ;
7879 private final CryptoPathFactory cryptoPathFactory ;
7980 private final PathMatcherFactory pathMatcherFactory ;
8081 private final DirectoryStreamFactory directoryStreamFactory ;
@@ -95,7 +96,7 @@ class CryptoFileSystemImpl extends CryptoFileSystem {
9596
9697 @ Inject
9798 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 ,
99100 PathMatcherFactory pathMatcherFactory , DirectoryStreamFactory directoryStreamFactory , DirectoryIdProvider dirIdProvider ,
100101 AttributeProvider fileAttributeProvider , AttributeByNameProvider fileAttributeByNameProvider , AttributeViewProvider fileAttributeViewProvider ,
101102 OpenCryptoFiles openCryptoFiles , Symlinks symlinks , FinallyUtil finallyUtil , CiphertextDirectoryDeleter ciphertextDirDeleter , ReadonlyFlag readonlyFlag , RootDirectoryInitializer rootDirectoryInitializer ) {
@@ -106,6 +107,7 @@ public CryptoFileSystemImpl(CryptoFileSystemProvider provider, CryptoFileSystems
106107 this .fileStore = fileStore ;
107108 this .stats = stats ;
108109 this .cryptoPathMapper = cryptoPathMapper ;
110+ this .longFileNameProvider = longFileNameProvider ;
109111 this .cryptoPathFactory = cryptoPathFactory ;
110112 this .pathMatcherFactory = pathMatcherFactory ;
111113 this .directoryStreamFactory = directoryStreamFactory ;
@@ -302,6 +304,7 @@ void createDirectory(CryptoPath cleartextDir, FileAttribute<?>... attrs) throws
302304 // create dir if and only if the dirFile has been created right now (not if it has been created before):
303305 try {
304306 Files .createDirectories (ciphertextDir .path );
307+ longFileNameProvider .persistCachedIfDeflated (ciphertextDirFile );
305308 } catch (IOException e ) {
306309 // make sure there is no orphan dir file:
307310 Files .delete (ciphertextDirFile );
@@ -351,7 +354,9 @@ private FileChannel newFileChannel(CryptoPath cleartextFilePath, EffectiveOpenOp
351354 throw new FileAlreadyExistsException (cleartextFilePath .toString ());
352355 } else {
353356 // 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 ;
355360 }
356361 }
357362
@@ -419,6 +424,7 @@ private void copySymlink(CryptoPath cleartextSource, CryptoPath cleartextTarget,
419424 Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .SYMLINK );
420425 CopyOption [] resolvedOptions = ArrayUtils .without (options , LinkOption .NOFOLLOW_LINKS ).toArray (CopyOption []::new );
421426 Files .copy (ciphertextSourceFile , ciphertextTargetFile , resolvedOptions );
427+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
422428 } else {
423429 CryptoPath resolvedSource = symlinks .resolveRecursively (cleartextSource );
424430 CryptoPath resolvedTarget = symlinks .resolveRecursively (cleartextTarget );
@@ -431,6 +437,7 @@ private void copyFile(CryptoPath cleartextSource, CryptoPath cleartextTarget, Co
431437 Path ciphertextSourceFile = cryptoPathMapper .getCiphertextFilePath (cleartextSource , CiphertextFileType .FILE );
432438 Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .FILE );
433439 Files .copy (ciphertextSourceFile , ciphertextTargetFile , options );
440+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
434441 }
435442
436443 private void copyDirectory (CryptoPath cleartextSource , CryptoPath cleartextTarget , CopyOption [] options ) throws IOException {
@@ -439,6 +446,7 @@ private void copyDirectory(CryptoPath cleartextSource, CryptoPath cleartextTarge
439446 if (Files .notExists (ciphertextTargetDirFile )) {
440447 // create new:
441448 createDirectory (cleartextTarget );
449+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetDirFile );
442450 } else if (ArrayUtils .contains (options , StandardCopyOption .REPLACE_EXISTING )) {
443451 // keep existing (if empty):
444452 Path ciphertextTargetDir = cryptoPathMapper .getCiphertextDir (cleartextTarget ).path ;
@@ -517,6 +525,7 @@ private void moveSymlink(CryptoPath cleartextSource, CryptoPath cleartextTarget,
517525 Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .SYMLINK );
518526 try (OpenCryptoFiles .TwoPhaseMove twoPhaseMove = openCryptoFiles .prepareMove (ciphertextSourceFile , ciphertextTargetFile )) {
519527 Files .move (ciphertextSourceFile , ciphertextTargetFile , options );
528+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
520529 twoPhaseMove .commit ();
521530 }
522531 }
@@ -528,6 +537,7 @@ private void moveFile(CryptoPath cleartextSource, CryptoPath cleartextTarget, Co
528537 Path ciphertextTargetFile = cryptoPathMapper .getCiphertextFilePath (cleartextTarget , CiphertextFileType .FILE );
529538 try (OpenCryptoFiles .TwoPhaseMove twoPhaseMove = openCryptoFiles .prepareMove (ciphertextSourceFile , ciphertextTargetFile )) {
530539 Files .move (ciphertextSourceFile , ciphertextTargetFile , options );
540+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetFile );
531541 twoPhaseMove .commit ();
532542 }
533543 }
@@ -540,6 +550,7 @@ private void moveDirectory(CryptoPath cleartextSource, CryptoPath cleartextTarge
540550 if (!ArrayUtils .contains (options , StandardCopyOption .REPLACE_EXISTING )) {
541551 // try to move, don't replace:
542552 Files .move (ciphertextSourceDirFile , ciphertextTargetDirFile , options );
553+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetDirFile );
543554 } else if (ArrayUtils .contains (options , StandardCopyOption .ATOMIC_MOVE )) {
544555 // replace atomically (impossible):
545556 assert ArrayUtils .contains (options , StandardCopyOption .REPLACE_EXISTING );
@@ -558,6 +569,7 @@ private void moveDirectory(CryptoPath cleartextSource, CryptoPath cleartextTarge
558569 Files .delete (ciphertextTargetDir );
559570 }
560571 Files .move (ciphertextSourceDirFile , ciphertextTargetDirFile , options );
572+ longFileNameProvider .persistCachedIfDeflated (ciphertextTargetDirFile );
561573 }
562574 dirIdProvider .move (ciphertextSourceDirFile , ciphertextTargetDirFile );
563575 cryptoPathMapper .invalidatePathMapping (cleartextSource );
0 commit comments