Allow hard-links to be created

Open
#19 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
java

Research direction

Start with createLink in src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java and link in CryptoFileSystemImpl.java, then review how the existing ciphertext paths are mapped. Verify the implementation against the Java NIO hard-link contract and confirm that creating a link through the provider succeeds for an existing file.

Written by the indexing model from the issue text.

Description

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));
+	}
+
 }
Dominant language
Java
Stars
110
Forks
39
Avg merge
1d 28m
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cryptomator/cryptofs

All issues in cryptomator/cryptofs

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.