cryptomator / cryptofs

Java Filesystem Provider with integrated encryption
GNU Affero General Public License v3.0
93 stars 35 forks source link

Feature/#111 fix #112

Closed infeo closed 3 years ago

infeo commented 3 years ago

Closes #111.

To prevent rewriting the name.9s for already existing, shortened files, one could add a small if:

    private FileChannel newFileChannelFromFile(CryptoPath cleartextFilePath, EffectiveOpenOptions options, FileAttribute<?>... attrs) throws IOException {
        /*
         * Some Code
         */
        if (options.createNew() && openCryptoFiles.get(ciphertextFilePath).isPresent()) {
            throw new FileAlreadyExistsException(cleartextFilePath.toString());
        } else {
            /* More Code */ 

            FileChannel ch = openCryptoFiles.getOrCreate(ciphertextFilePath).newFileChannel(options);
            if (options.writable()) {
                if( options.create() || options.createNew()) {
                    ciphertextPath.persistLongFileName(); 
                }
                stats.incrementAccessesWritten();
            }
            /* final statements */
            return ch;
        }
    }

But as @overheadhunter already said, shortend is a rare case and performance impact is minial, so i decided against it.

Regarding the unit test, i'm not sure if I put the into the right place.

infeo commented 3 years ago

As soon as this PR is approved and merged, i'll create a cherrypicked hotfix for the 1.9.x branch.

overheadhunter commented 3 years ago

Oh but instead of merging directly into develop, can you merge into new hotfix 2.0.x branch and only then into develop?