Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectoryNotEmptyException when moving symlink with REPLACE_EXISTING set #177

Open
JaniruTEC opened this issue Jul 29, 2023 · 0 comments
Open

Comments

@JaniruTEC
Copy link
Contributor

Moving a symlink (on top of another symlink) causes a DirectoryNotEmptyException:

var source = fs.getPath("/source");
var target = fs.getPath("/target");
Files.createSymbolicLink(source, fs.getPath("/linkedBySource.txt"));
Files.createSymbolicLink(target, fs.getPath("/linkedByTarget.txt"));

Assertions.assertDoesNotThrow(() -> Files.move(source, target, REPLACE_EXISTING));

Stacktrace:

java.nio.file.DirectoryNotEmptyException: /vault/d/FW/62AD46Y3CLSPBJCAZTO2EQD5TDALWH/y6Yo0PGakzpfU2ZozQWLcHrgiT8=.c9s
	at com.google.common.jimfs.FileSystemView.checkEmpty(FileSystemView.java:493)
	at com.google.common.jimfs.FileSystemView.checkDeletable(FileSystemView.java:477)
	at com.google.common.jimfs.FileSystemView.delete(FileSystemView.java:449)
	at com.google.common.jimfs.FileSystemView.copy(FileSystemView.java:539)
	at com.google.common.jimfs.JimfsFileSystemProvider.copy(JimfsFileSystemProvider.java:268)
	at com.google.common.jimfs.JimfsFileSystemProvider.move(JimfsFileSystemProvider.java:273)
	at java.base/java.nio.file.Files.move(Files.java:1432)
	at org.cryptomator.cryptofs/org.cryptomator.cryptofs.CryptoFileSystemImpl.moveSymlink(CryptoFileSystemImpl.java:585)
	at org.cryptomator.cryptofs/org.cryptomator.cryptofs.CryptoFileSystemImpl.move(CryptoFileSystemImpl.java:573)
	at org.cryptomator.cryptofs/org.cryptomator.cryptofs.MoveOperation.move(MoveOperation.java:37)
	at org.cryptomator.cryptofs/org.cryptomator.cryptofs.CryptoFileSystemProvider.move(CryptoFileSystemProvider.java:255)
	at java.base/java.nio.file.Files.move(Files.java:1432)

The same happens when using a regular filesystem instead of JIMFS.

org.cryptomator.cryptofs/org.cryptomator.cryptofs.CryptoFileSystemImpl.moveSymlink(CryptoFileSystemImpl.java:585):

CiphertextFilePath ciphertextSource = cryptoPathMapper.getCiphertextFilePath(cleartextSource);
CiphertextFilePath ciphertextTarget = cryptoPathMapper.getCiphertextFilePath(cleartextTarget);
try (OpenCryptoFiles.TwoPhaseMove twoPhaseMove = openCryptoFiles.prepareMove(ciphertextSource.getRawPath(), ciphertextTarget.getRawPath())) {
	Files.move(ciphertextSource.getRawPath(), ciphertextTarget.getRawPath(), options); //585
	if (ciphertextTarget.isShortened()) {
		ciphertextTarget.persistLongFileName();
	} else {
		Files.deleteIfExists(ciphertextTarget.getInflatedNamePath()); // no longer needed if not shortened
	}
	twoPhaseMove.commit();
}

Tests showed that both ciphertextSource.getRawPath() and ciphertextTarget.getRawPath() are directories, not regular files. I assume the problem is related to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant