|
18 | 18 | import org.cryptomator.cryptofs.common.DeletingFileVisitor; |
19 | 19 | import org.cryptomator.cryptofs.common.FinallyUtil; |
20 | 20 | import org.cryptomator.cryptofs.dir.CiphertextDirectoryDeleter; |
| 21 | +import org.cryptomator.cryptofs.dir.DirectoryStreamFilters; |
21 | 22 | import org.cryptomator.cryptofs.dir.DirectoryStreamFactory; |
22 | 23 | import org.cryptomator.cryptofs.fh.OpenCryptoFiles; |
23 | 24 | import org.cryptomator.cryptolib.api.Cryptor; |
@@ -621,20 +622,21 @@ private void moveDirectory(CryptoPath cleartextSource, CryptoPath cleartextTarge |
621 | 622 | throw new AtomicMoveNotSupportedException(cleartextSource.toString(), cleartextTarget.toString(), "Replacing directories during move requires non-atomic status checks."); |
622 | 623 | } |
623 | 624 | // check if dir is empty: |
624 | | - Path oldCiphertextDir = cryptoPathMapper.getCiphertextDir(cleartextTarget).path; |
625 | | - boolean oldCiphertextDirExists = true; |
626 | | - try (DirectoryStream<Path> ds = Files.newDirectoryStream(oldCiphertextDir)) { |
| 625 | + Path targetCiphertextDirContentDir = cryptoPathMapper.getCiphertextDir(cleartextTarget).path; |
| 626 | + boolean targetCiphertextDirExists = true; |
| 627 | + try (DirectoryStream<Path> ds = Files.newDirectoryStream(targetCiphertextDirContentDir, DirectoryStreamFilters.EXCLUDE_DIR_ID_BACKUP)) { |
627 | 628 | if (ds.iterator().hasNext()) { |
628 | 629 | throw new DirectoryNotEmptyException(cleartextTarget.toString()); |
629 | 630 | } |
630 | 631 | } catch (NoSuchFileException e) { |
631 | | - oldCiphertextDirExists = false; |
632 | | - } |
633 | | - // cleanup dir to be replaced: |
634 | | - if (oldCiphertextDirExists) { |
635 | | - Files.walkFileTree(oldCiphertextDir, DeletingFileVisitor.INSTANCE); |
| 632 | + targetCiphertextDirExists = false; |
636 | 633 | } |
| 634 | + //delete dir link |
637 | 635 | Files.walkFileTree(ciphertextTarget.getRawPath(), DeletingFileVisitor.INSTANCE); |
| 636 | + // cleanup content dir |
| 637 | + if (targetCiphertextDirExists) { |
| 638 | + Files.walkFileTree(targetCiphertextDirContentDir, DeletingFileVisitor.INSTANCE); |
| 639 | + } |
638 | 640 | } |
639 | 641 |
|
640 | 642 | // no exceptions until this point, so MOVE: |
|
0 commit comments