perlundq/yajsync

Simply RsyncFileAttributes.stat(Path) / support of more file attribute views

Closed this issue · 1 comments

The following code snippet could be an example how to support more file attribute views beyond POSIX and Basic, for e.g. support of S_ISUID, S_ISGID and S_ISVTX and without the necessity to map via int toMode(...):

public static RsyncFileAttributes stat(Path path) throws IOException
{
    if (Files.getFileStore(path).supportsFileAttributeView("unix")) {
        Map<String,Object> attrMap = Files.readAttributes(path, "unix:*"); 
        int mode = (Integer) attrMap.get("mode");
        long size = (Long) attrMap.get("size");
        FileTime modTime = (FileTime) attrMap.get("lastModifiedTime");
        return new RsyncFileAttributes(mode, size, modTime.to(TimeUnit.SECONDS));
    }

...

Yes you are right. In an early version of yajsync, I actually used Files.readAttributes(path, "unix:...") exclusively. But I replaced it with BasicFileAttributes since it had a noticable performance benefit, was documented and was obviously going to work on non-unix platforms.

I have just made a simple benchmark of yajsync, comparing this, with PosixFileAttributes and BasicFileAttributes in a scenario where the overhead of stat:ing would be the largest (when copying files locally using --recursive and --times and having everything in the page cache). It seems that BasicFileAttributes is roughly 5% faster than PosixFileAttributes and this. PosixFileAttributes and this has roughly the same performance.

So I'll add support for this now since it doesn't hurt and as you say will give extra stat information.

In the long run I have plans for adding support for rsync option -a --archive and all the options it implies (-rlptgoD), the exact way this should work still isn't yet decided.