perlundq/yajsync

Support Path instead of String for pathnames

Closed this issue · 2 comments

There are comments like the following that declare why some pathnames have to be saved as String not Path in the current implementation. To be able to support URIs of different FileSystems there should be a dual approach:

  • allow URIs locally
  • use according String representations for remote processing

Is there anything that could interfere with such a local/remote differentiation?

/**
 * a class for rsync file information, we must keep the path name as a string
 * as opposed to storing the Path directly since the latter may fail
 * (when being the receiver) and we must keep the file list identical to the
 * peer's file list when being receiver
 */
public class FileInfo implements Comparable<FileInfo>

FileInfo stores the path as an array of bytes, regardless of its encoding, since that is required to be able to sort file info's correctly. It also stores the normalized path which is used to detect duplicates (this does not have to be stored and could be computed at use also). And also stores the absolute local path (which also can be derived at use)

Sorry but I don't understand what you have in mind when you talk about keeping URLs in there. Can you eloberate on this please, an example could possibly be useful also.

thanks,

I published a spartan implementation of an encrypting FileSystem, see https://github.com/usrflo/encfs4j

The following test class shows how I added encfs4j to yajsync using the proposed CustomFileSystem class and modifications in #19 :

package com.github.perlundq.yajsync.ui;

import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.spi.FileSystemProvider;
import java.util.HashMap;
import java.util.Map;

import com.github.perlundq.yajsync.io.CustomFileSystem;

import de.agitos.encfs4j.EncryptedFileSystemProvider;

public class CryptedSyncClient {

    public static void main(String[] args) throws IOException
    {
        System.err.println("Warning: this software is still unstable and " +
                           "there might be data corruption bugs hiding. So " +
                           "use it only carefully at your own risk.");

        FileSystemProvider provider = new EncryptedFileSystemProvider();
        Map<String,String> env = new HashMap<String,String>();
        env.put(EncryptedFileSystemProvider.CIPHER_ALGORITHM, "AES");
        env.put(EncryptedFileSystemProvider.CIPHER_ALGORITHM_MODE, "CTR");
        env.put(EncryptedFileSystemProvider.CIPHER_ALGORITHM_PADDING, "NoPadding");
        env.put(EncryptedFileSystemProvider.SECRET_KEY, "1234567890abcdef"); // 128 bit key
        env.put(EncryptedFileSystemProvider.REVERSE_MODE, "true");

        env.put(EncryptedFileSystemProvider.FILESYSTEM_ROOT_URI, "file:/yajsync-test/data/");

        URI uri = URI.create("enc:///");
        FileSystem fs = provider.newFileSystem(uri, env);

        CustomFileSystem.setFileSystem(fs);

        new YajSyncClient().start(args);
    }
}