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

Allow hard-links to be created #19

Open
paeppa opened this issue Nov 20, 2017 · 0 comments
Open

Allow hard-links to be created #19

paeppa opened this issue Nov 20, 2017 · 0 comments

Comments

@paeppa
Copy link

paeppa commented Nov 20, 2017

Would be great if cryptofs would also allow hard-links on disc.
I made a "proof-of-concept" implementation (see patch attached) which only adds about 10 lines of code.

diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemImpl.java b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemImpl.java
index 3c84460..0fa5077 100644
--- a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemImpl.java
+++ b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemImpl.java
@@ -403,6 +403,12 @@
 			throw new NoSuchFileException(cleartextSource.toString());
 		}
 	}
+	
+	void link(CryptoPath cleartextLink, CryptoPath cleartextExisting) throws IOException {
+		Path ciphertextLinkFile = cryptoPathMapper.getCiphertextFilePath(cleartextLink, CiphertextFileType.FILE);
+		Path ciphertextExistingFile = cryptoPathMapper.getCiphertextFilePath(cleartextExisting, CiphertextFileType.FILE);
+		Files.createLink(ciphertextLinkFile, ciphertextExistingFile);
+	}
 
 	private void copyAttributes(Path src, Path dst) throws IOException {
 		Set<Class<? extends FileAttributeView>> supportedAttributeViewTypes = fileStore.supportedFileAttributeViewTypes();
diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java
index ea9595a..3627e68 100644
--- a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java
+++ b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java
@@ -383,4 +383,9 @@
 		}
 	}
 
+	@Override
+	public void createLink(Path link, Path existing) throws IOException {
+		fileSystem(existing).link(CryptoPath.castAndAssertAbsolute(link), CryptoPath.castAndAssertAbsolute(existing));
+	}
+
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants